( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ HEX
HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux mail.thebrand.ai 6.8.0-107-generic #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 x86_64
User: www-data (33)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/tmpr/../tmpr/..//tmpr/../tmpr/../node_modules/dot-object/test/pick.js
'use strict'

/* jshint -W030 */

require('should')
var Dot = require('../index')

describe('Pick:', function () {
  it('Should be able to pick a value', function () {
    var obj = {
      some: 'value',
      already: 'set'
    }

    var val = Dot.pick('some', obj)

    val.should.eql('value')
  })

  it('Should be able to pick dotted value', function () {
    var obj = {
      some: {
        other: 'value'
      }
    }

    var val = Dot.pick('some.other', obj)

    val.should.eql('value')
  })

  it('Should be able to pick null properties', function () {
    var obj = {
      some: null
    }

    var val = Dot.pick('some', obj)

    ;(val === null).should.equal(true)
  })

  it('Should return undefined when picking an non-existing value', function () {
    var obj = {
      some: null
    }

    var val = Dot.pick('other', obj)

    ;(val === undefined).should.equal(true)
  })

  it('Should return undefined when picking an non-existing dotted value',
    function () {
      var obj = {
        some: null
      }

      var val = Dot.pick('some.other', obj)

      ;(val === undefined).should.equal(true)
    }
  )

  it("Should check down the object's prototype chain", function () {
    var obj = {
      some: {
        other: 'value'
      }
    }

    var objIns = Object.create(obj)

    objIns.should.have.property('some')

    var val = Dot.pick('some.other', objIns)
    val.should.be.instanceOf(String)
  })

  it('Should be able to delete picked value', function () {
    var obj = {
      some: {
        other: 'value',
        foo: 'bar'
      }
    }

    var val = Dot.pick('some.foo', obj, true)

    val.should.eql('bar')
    obj.should.eql({
      some: {
        other: 'value'
      }
    })
  })

  it('Should be able to delete picked array value', function () {
    var obj = {
      some: {
        other: 'value',
        arrayItems: ['foo', 'bar', 'baz']
      }
    }

    var val = Dot.pick('some.arrayItems[1]', obj, true)

    val.should.eql('bar')
    obj.should.eql({
      some: {
        other: 'value',
        arrayItems: ['foo', , 'baz'] /* eslint-disable-line no-sparse-arrays */
      }
    })
  })

  it('Should be able to delete picked array value and reindex', function () {
    var obj = {
      some: {
        other: 'value',
        arrayItems: ['foo', 'bar', 'baz']
      }
    }

    var val = Dot.pick('some.arrayItems[1]', obj, true, true)

    val.should.eql('bar')
    obj.should.eql({
      some: {
        other: 'value',
        arrayItems: ['foo', 'baz']
      }
    })
  })
})