PHP 8.2.30
Preview: remove-path.spec.ts Size: 2.47 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/utils/flat/remove-path.spec.ts

import { expect } from 'chai'

import { removePath } from './remove-path.js'

describe('removePath', () => {
  let params

  beforeEach(() => {
    params = {
      name: 'value',
      'notPopulated.0': 'val1',
      'notPopulated.1': 'val2',
      'property.0': 'val1',
      'property.1': 'val2',
      'property.2': 'val3',
      'property.3.nested.0': 'val1',
      'property.3.nested.1': 'val2',
      'property.3.nested.2': 'val3',
      'property.3.nested.3.some': 'val3',
      'property.3.nested.4.some-other': 'val41',
      'property.4': 'val4',
      'property.5.nested.0': 'val5',
    }
  })

  it('removes regular property', () => {
    expect(removePath(params, 'name')).not.to.have.keys('name')
  })

  it('removes element from the array and updates other indexes', () => {
    const newParams = removePath(params, 'property.1')

    expect(newParams).to.deep.equal({
      name: 'value',
      'notPopulated.0': 'val1',
      'notPopulated.1': 'val2',
      'property.0': 'val1',
      'property.1': 'val3',
      'property.2.nested.0': 'val1',
      'property.2.nested.1': 'val2',
      'property.2.nested.2': 'val3',
      'property.2.nested.3.some': 'val3',
      'property.2.nested.4.some-other': 'val41',
      'property.3': 'val4',
      'property.4.nested.0': 'val5',
    })
  })

  it('removes parent element from the array and updates other indexes', () => {
    const newParams = removePath(params, 'property.3.nested.3.some')

    expect(newParams).to.deep.equal({
      name: 'value',
      'notPopulated.0': 'val1',
      'notPopulated.1': 'val2',
      'property.0': 'val1',
      'property.1': 'val2',
      'property.2': 'val3',
      'property.3.nested.0': 'val1',
      'property.3.nested.1': 'val2',
      'property.3.nested.2': 'val3',
      'property.3.nested.3.some-other': 'val41',
      'property.4': 'val4',
      'property.5.nested.0': 'val5',
    })
  })

  it('leaves empty array when removing last element', () => {
    let newParams = removePath(params, 'notPopulated.0')
    newParams = removePath(newParams, 'notPopulated.0')

    expect(newParams).to.deep.equal({
      name: 'value',
      notPopulated: [],
      'property.0': 'val1',
      'property.1': 'val2',
      'property.2': 'val3',
      'property.3.nested.0': 'val1',
      'property.3.nested.1': 'val2',
      'property.3.nested.2': 'val3',
      'property.3.nested.3.some': 'val3',
      'property.3.nested.4.some-other': 'val41',
      'property.4': 'val4',
      'property.5.nested.0': 'val5',
    })
  })
})

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
44 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
448 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.42 KB lrw-r--r-- 2026-02-28 00:32:10
Edit Download
906 B lrw-r--r-- 2026-02-28 00:32:10
Edit Download
1.24 KB lrw-r--r-- 2026-02-28 00:32:14
Edit Download
2.74 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
965 B lrw-r--r-- 2026-02-28 00:32:14
Edit Download
587 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.84 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
2.51 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
65 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
2.01 KB lrw-r--r-- 2026-02-28 00:32:34
Edit Download
686 B lrw-r--r-- 2026-02-28 00:32:36
Edit Download
38 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
730 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
976 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
890 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.21 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.47 KB lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.41 KB lrw-r--r-- 2026-02-28 00:32:40
Edit Download
504 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.49 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
1.11 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
639 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
4.70 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
2.03 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).