Skip to content

hasPath ​

Category
Export size
min 0.97 kB · gzip 0.60 kB
See also

Whether path resolves to an own property — inherited properties do not count, so a key named toString is only reported when the object really carries it. A property that exists but holds undefined counts.

ts
  import { 
hasPath
} from 'feathers-utils/helpers';

Example ​

ts
import { hasPath } from 'feathers-utils/helpers'

hasPath({ user: { id: 1 } }, 'user.id') // => true
hasPath({ user: { id: undefined } }, 'user.id') // => true
hasPath({ list: [1] }, 'list[1]') // => false
hasPath({}, 'toString') // => false

Type declaration ​

Show Type Declarations
ts
/**
 * Whether `path` resolves to an **own** property — inherited properties do not
 * count, so a key named `toString` is only reported when the object really
 * carries it. A property that exists but holds `undefined` counts.
 *
 * @example
 * ```ts
 *
 *
 * hasPath({ user: { id: 1 } }, 'user.id') // => true
 * hasPath({ user: { id: undefined } }, 'user.id') // => true
 * hasPath({ list: [1] }, 'list[1]') // => false
 * hasPath({}, 'toString') // => false
 * ```
 *
 * @see https://utils.feathersjs.com/helpers/has-path.html
 */
export declare const hasPath: (object: unknown, path: PropertyPath) => boolean
ArgumentTypeDescription
objectunknown
pathPropertyPath

Coming from lodash ​

A drop-in for _.has: only own properties count along the path. There is no counterpart to _.hasIn, which also follows the prototype chain — getPath(obj, path) !== undefined covers most of its uses.

Released under the MIT License.