{"_id":"@asbp/get-by-path","_rev":"5-95b86882790027c8d9814e07d5c2a974","name":"@asbp/get-by-path","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@asbp/get-by-path","version":"1.0.0","keywords":[],"author":"","license":"GPL-3.0-only","_id":"@asbp/get-by-path@1.0.0","maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"dist":{"shasum":"922d2f2227879f8d85423271c11a1548b6c132c8","tarball":"https://registry.npmjs.org/@asbp/get-by-path/-/get-by-path-1.0.0.tgz","fileCount":5,"integrity":"sha512-ydxVIbYxKKVFQGCtt2ajeuC0S4nwivCWn8JymB3aCZC6lMtBzTSoknzUVQrggEmg1ZrchVIPJD/6jteB03OpnQ==","signatures":[{"sig":"MEUCIHN5tG/K8XpP26yemDJyBV1OvzkbtlIYwERDjiTCaP4SAiEAq3V6O62fcgepoGB7/ZhUXPmYkGeaLcEco1Y0MQP1ZlM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45172},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"5e211e2cc18b9ae44802e53de3d5dc122c672451","scripts":{"test":"jest","build":"tsc","test:watch":"jest --watch","test:coverage":"jest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"asbp","email":"guungofficial@gmail.com"},"_npmVersion":"10.9.4","description":"Get a value of an object by querying it by dot notation.","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.5","ts-node":"^10.9.2","typescript":"^5.9.3","@types/node":"^24.10.1"},"_npmOperationalInternal":{"tmp":"tmp/get-by-path_1.0.0_1765186550601_0.39451095206483244","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@asbp/get-by-path","version":"1.0.1","keywords":[],"author":"","license":"GPL-3.0-only","_id":"@asbp/get-by-path@1.0.1","maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"dist":{"shasum":"501876fedd9dfc60ca1290f2810a2860595b4960","tarball":"https://registry.npmjs.org/@asbp/get-by-path/-/get-by-path-1.0.1.tgz","fileCount":5,"integrity":"sha512-TC9iyA84D2JM+aaHhgJ/za9BzQdl+9fzB8ATXRcaXatFQpjuxNiTsGNYrkzV7qgV54ZyO9Xvumd+z62Dy5+VMg==","signatures":[{"sig":"MEQCIDYGZHN3srTxgFpp2PHOmufQMfJ6khsWI+rRe7Y2cPqqAiAIfgM2WP/IalMrYCFSSncrDwwjBeRFmjWocqpBIoL/Hg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45214},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"2cc9495ca0dee58510eaf8c31a94343ef6c3cbb9","scripts":{"test":"jest","build":"tsc","test:watch":"jest --watch","test:coverage":"jest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"asbp","email":"guungofficial@gmail.com"},"_npmVersion":"10.9.4","description":"Get a value of an object by querying it by dot notation.","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.5","ts-node":"^10.9.2","typescript":"^5.9.3","@types/node":"^24.10.1"},"_npmOperationalInternal":{"tmp":"tmp/get-by-path_1.0.1_1765191332626_0.6848033083908913","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@asbp/get-by-path","version":"1.0.2","keywords":[],"author":"","license":"GPL-3.0-only","_id":"@asbp/get-by-path@1.0.2","maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"homepage":"https://github.com/asbp/get-by-path#readme","bugs":{"url":"https://github.com/asbp/get-by-path/issues"},"dist":{"shasum":"a5429103bd49a1f39f735dc651a7e3544fe263eb","tarball":"https://registry.npmjs.org/@asbp/get-by-path/-/get-by-path-1.0.2.tgz","fileCount":5,"integrity":"sha512-e+8UUKoXRsQ6LCt68Qd2e0FvF98yjNQOAHe7TKedP0QjmivCn6xV9O1n9zxdY3FmarR1eKO2novs9ivfwOQINQ==","signatures":[{"sig":"MEYCIQCio9/rWls9AhwQCAfLtGbcde01gN2LMRioIx4RLh7bCwIhAMww0UrxJtEenAyC9r7pHzn459bilCef/YIFWV67yR66","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45256},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"08b94ab7db552a7f252523f196ec21f11a8520ac","scripts":{"test":"jest","build":"tsc","test:watch":"jest --watch","test:coverage":"jest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"asbp","email":"guungofficial@gmail.com"},"repository":{"url":"git+https://github.com/asbp/get-by-path.git","type":"git"},"_npmVersion":"10.9.4","description":"Get a value of an object by querying it by dot notation.","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.5","ts-node":"^10.9.2","typescript":"^5.9.3","@types/node":"^24.10.1"},"_npmOperationalInternal":{"tmp":"tmp/get-by-path_1.0.2_1767853704588_0.9119913755613107","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@asbp/get-by-path","version":"1.0.3","keywords":[],"author":"","license":"GPL-3.0-only","_id":"@asbp/get-by-path@1.0.3","maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"homepage":"https://github.com/asbp/get-by-path#readme","bugs":{"url":"https://github.com/asbp/get-by-path/issues"},"dist":{"shasum":"ff9ac4f3dceb665bf551592042855a22593e9c5f","tarball":"https://registry.npmjs.org/@asbp/get-by-path/-/get-by-path-1.0.3.tgz","fileCount":5,"integrity":"sha512-22WRmDZcx6Je/3F9tmrRfZFmGwFWlZekckzZjvTlTa9EgiDfehP3ZRw8MnCtSJz//o1vgo7zznhMHyPS8pRvOw==","signatures":[{"sig":"MEYCIQCTUMJuNhDMivl9/CA30Vyq4nt7pqRsXt3F9SPH+MXPoQIhAPmwnBy4+KpqjcaynS90Q4KIVgSAEVKFcIhJ90Z8vnHy","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50352},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"8d0ed6c8b92f465845fb0315af641fbf463b3afe","scripts":{"test":"jest","build":"tsc","test:watch":"jest --watch","test:coverage":"jest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"asbp","email":"guungofficial@gmail.com"},"repository":{"url":"git+https://github.com/asbp/get-by-path.git","type":"git"},"_npmVersion":"10.9.4","description":"Get a value of an object by querying it by dot notation.","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.5","ts-node":"^10.9.2","typescript":"^5.9.3","@types/node":"^24.10.1"},"_npmOperationalInternal":{"tmp":"tmp/get-by-path_1.0.3_1769443575833_0.9809985883294594","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@asbp/get-by-path","version":"1.1.0","description":"Get a value of an object by querying it by dot notation.","main":"dist/index.js","module":"dist/esm/index.js","types":"dist/index.d.ts","exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"scripts":{"build":"tsc && tsc -p tsconfig.esm.json && node scripts/fixup-esm.js","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage","prepublishOnly":"npm run build"},"keywords":[],"author":"","license":"GPL-3.0-only","repository":{"type":"git","url":"git+https://github.com/asbp/get-by-path.git"},"devDependencies":{"@types/node":"^26.1.0","jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3"},"gitHead":"995b5592a24d6485db4b8ed482c1d1474fc629e1","_id":"@asbp/get-by-path@1.1.0","bugs":{"url":"https://github.com/asbp/get-by-path/issues"},"homepage":"https://github.com/asbp/get-by-path#readme","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-FmCKAgmSy4mWyVpAdrWo1Ox2WCJfPtYacBTIx7vnSQEkxT3Cw7pUuLjGWJAg+1kpH8Xs4Ya8/DCOk9z/kuE1rw==","shasum":"7716127f0a02730de3b5eace038b9569f2d28ce1","tarball":"https://registry.npmjs.org/@asbp/get-by-path/-/get-by-path-1.1.0.tgz","fileCount":8,"unpackedSize":68905,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCCYFNO8SKxzYmTrGU2909j8WjN47IitqsT9/AdYaoihgIgVicusMJNis2wiLIW+mxbnjRTX74vpAWBWDN/HdUJdRQ="}]},"_npmUser":{"name":"asbp","email":"guungofficial@gmail.com"},"directories":{},"maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/get-by-path_1.1.0_1783228384482_0.7744024167327028"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-08T09:35:50.481Z","modified":"2026-07-05T05:13:04.735Z","1.0.0":"2025-12-08T09:35:50.743Z","1.0.1":"2025-12-08T10:55:32.769Z","1.0.2":"2026-01-08T06:28:24.719Z","1.0.3":"2026-01-26T16:06:15.977Z","1.1.0":"2026-07-05T05:13:04.621Z"},"bugs":{"url":"https://github.com/asbp/get-by-path/issues"},"license":"GPL-3.0-only","homepage":"https://github.com/asbp/get-by-path#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/asbp/get-by-path.git"},"description":"Get a value of an object by querying it by dot notation.","maintainers":[{"name":"asbp","email":"guungofficial@gmail.com"}],"readme":"\n# get-by-path\nGet a value of an object by querying it by dot notation. This library has no runtime dependencies, meaning it can be run on a browser as well as a Node.js environment.\n## Installation\nWith yarn\n\n```bash\n  yarn add @asbp/get-by-path\n```\nWith npm\n\n```bash\n  npm i @asbp/get-by-path\n```\n\n## Usage/Examples\nIn simple usage, just import `getByPath` function like the example below.\n```javascript\nimport getByPath from '@asbp/get-by-path'\n\ngetByPath({foo: 'bar'}, 'foo') // -> 'bar'\ngetByPath({foo: 'bar'}, 'baz') // -> undefined\n```\n\nYou can also use array as a path. Array segments may be strings or numbers (handy for array indices):\n```javascript\nimport getByPath from '@asbp/get-by-path'\n\ngetByPath({ foo: 'bar', baz: 'qux', abc: { def: 'ghi' } }, ['abc', 'def']) // -> 'ghi'\ngetByPath({ items: [{ name: 'first' }, { name: 'second' }] }, ['items', 0, 'name']) // -> 'first'\n```\n\nYou can also use a function as a path, provided it returns a string, a number, or an array of strings/numbers, like the example below:\n```javascript\nimport getByPath from '@asbp/get-by-path';\n\nconst cond1 = true;\n\ngetByPath({ foo: 'bar', baz: 'qux', abc: { def: 'ghi' } }, () => {\n    return cond1 ? 'foo' : ['abc', 'def'];\n}) // -> 'bar' (cond1 is true, so the path is 'foo')\n```\n\n**Warning!** If the fallback is an object, it cannot passed directly after `path` argument since it might be misinterpreted as miscellaneous option object (`MiscOptions`, see API references), therefore if you want to set an object as a fallback, do it like this:\n\n```javascript\nimport getByPath from '@asbp/get-by-path'\n\ngetByPath({foo: 'bar'}, 'qux', {\n    fallback: { baz: 'ooo' }\n}) // -> { baz: 'ooo' }\n```\n\nFunctions are not ambiguous, so a function *can* be passed directly as the fallback:\n\n```javascript\nconst myFallback = () => 'computed later';\n\ngetByPath({foo: 'bar'}, 'qux', myFallback) // -> myFallback\n```\n\nThe options object you pass in is never modified by the library.\n\nYou can also import the non-null version (`getByPathNoNull`). Basically it 'treats' `null` in the resulting value as an `undefined`, thus returning the fallback.\n\n```javascript\nimport { getByPathNoNull } from '@asbp/get-by-path'\n\ngetByPathNoNull({ a: { b: { c: 42 }, b0: null } }, 'a.b0', 'Nope!') // -> 'Nope!'\n```\n\nYou can also import the found-first version (`getByPathFoundFirst`). Basically it traverse trough array of possible paths until the first key that has corresponding value in the `target` or else the fallback.\n\n```javascript\nimport { getByPathFoundFirst } from '@asbp/get-by-path'\n\ngetByPathFoundFirst({ a: { b: { c: 42 }, b0: null } }, ['qux', 'a.b.c', 'a.b0'], 'Nope!') // -> 42\n```\n\n## Type inference (TypeScript)\n\nWhen the path is statically known (a string literal, a number literal, or an array literal), the return type is inferred from `target`, `path`, and `options`. No type annotations are needed:\n\n```typescript\ngetByPath({ a: { b: { c: 42 } } }, 'a.b.c')      // number\ngetByPath({ arr: [10, 20, 30] }, 'arr.1')        // number | undefined\ngetByPath({ x: 1 }, 'z')                         // undefined\ngetByPath({ x: 1 }, 'z', 'not found')            // 'not found'\ngetByPathNoNull({ a: null as string | null }, 'a', 'N/A') // string | 'N/A'\ngetByPathFoundFirst({ a: 1, b: 'x' }, ['b', 'a']) // string | number\n```\n\nWhen the fallback is provided, it replaces `undefined` in the inferred type, matching the runtime behavior where a miss returns the fallback.\n\nInference falls back to `any` when the path cannot be resolved statically: a `string`-typed variable, a widened `string[]` path, a function path, or an untyped (`any`) target.\n\nThe previous explicit style keeps working, so this is not a breaking change at the call site:\n\n```typescript\ngetByPath<string>(target, 'some.path') // string, as before\n```\n\nNote that consumers who relied on the old implicit `any` return type (for example, assigning a result to an incompatible annotated variable) may see new compile errors after upgrading, so treat the upgrade as a types-level breaking change.\n\n## API Reference\n\n#### `Path` type\n```typescript\ntype PathSegment = string | number;\ntype Path = PathSegment | PathSegment[] | (() => PathSegment | PathSegment[]);\n```\nAccepts a string, a number, an array of strings/numbers, or a function that returns any of those.\n\n#### `Fallback` type\n```typescript\ntype Fallback = number | bigint | string | boolean | null | undefined | object | Function;\n```\n\n#### `MiscOptions` interface\n```typescript\ninterface MiscOptions {\n\tfallback?: Fallback;\n\tallowNull?: boolean;\n\treturnFallbackOnPrimitive?: boolean;\n};\n```\n| Parameter | Type     | Default Value   | Description                |\n| :-------- | :------- | :------- | :------------------------- |\n| `fallback` | `Fallback` | `undefined` | A fallback value to be used |\n| `allowNull` | `boolean` | `true` | Whether to allow `null` as the final result. If set to `false`, it will treat `null` as `undefined`, thus returning the fallback.|\n| `returnFallbackOnPrimitive` | `boolean` | `false` | Whether to return the fallback when `target` is of primitive type. If set to false, it just return the value of `target` instead. |\n\n#### `Options` type\n```typescript\ntype Options = Fallback | MiscOptions;\n```\nThis type can accept a primitive value (as a fallback) or a `MiscOptions`.\n\n#### `NoNullOptions` type\n```typescript\ntype NoNullOptions = Fallback | Omit<MiscOptions, 'allowNull'>;\n```\nThis type is basically `Options` minus the `allowNull` property. The `NoNull` functions always force `allowNull` to `false`, so passing it has no effect.\n\n#### `PathValue<T, P>` type\nThe value found at path `P` inside `T`, or `undefined` when the path cannot be resolved. Falls back to `any` when the path is not statically known. The related `GetByPathResult`, `GetByPathNoNullResult`, `GetByPathFoundFirstResult`, and `GetByPathFoundFirstNoNullResult` types additionally account for the fallback and the other options, and are what the functions return.\n\n```typescript\nimport type { PathValue } from '@asbp/get-by-path'\n\ntype C = PathValue<{ a: { b: { c: number } } }, 'a.b.c'> // number\n```\n\n#### Default function (`getByPath`)\n```typescript\ngetByPath<T, const P extends Path, const O extends Options>(target: T, path: P, options?: O): GetByPathResult<T, P, O>\ngetByPath<R = any>(target: unknown, path: Path, options?: Options): R // legacy explicit form\n```\n\n| Parameter | Type     | Description                |\n| :-------- | :------- | :------------------------- |\n| `target` | `unknown` | A target object  |\n| `path` | `Path` | A path. For usage, see above.  |\n| `options` | `Options` | Additional options (see above)  |\n\n#### Non-null version function (`getByPathNoNull`)\n```typescript\ngetByPathNoNull<T, const P extends Path, const O extends NoNullOptions>(target: T, path: P, options?: O): GetByPathNoNullResult<T, P, O>\ngetByPathNoNull<R = any>(target: unknown, path: Path, options?: NoNullOptions): R // legacy explicit form\n```\n\n| Parameter | Type     | Description                |\n| :-------- | :------- | :------------------------- |\n| `target` | `unknown` | A target object  |\n| `path` | `Path` | A path. For usage, see above.  |\n| `options` | `NoNullOptions` | Additional options (see above) |\n\n#### Found-first version (`getByPathFoundFirst`)\n```typescript\ngetByPathFoundFirst<T, const Ps extends readonly Path[], const O extends Options>(target: T, paths: Ps, options?: O): GetByPathFoundFirstResult<T, Ps, O>\ngetByPathFoundFirst<R = any>(target: unknown, paths: Path[], options?: Options): R // legacy explicit form\n```\nThis function traverse trough  array of possible paths and return the first key that has corresponding value in the `target`.\n| Parameter | Type     | Description                |\n| :-------- | :------- | :------------------------- |\n| `target` | `unknown` | A target object  |\n| `path` | `Path[]` | An array of paths. For usage, see above.  |\n| `options` | `Options` | Additional options (see above)  |\n\n#### Found-first no-null version (`getByPathFoundFirstNoNull`)\n```typescript\ngetByPathFoundFirstNoNull<T, const Ps extends readonly Path[], const O extends NoNullOptions>(target: T, paths: Ps, options?: O): GetByPathFoundFirstNoNullResult<T, Ps, O>\ngetByPathFoundFirstNoNull<R = any>(target: unknown, paths: Path[], options?: NoNullOptions): R // legacy explicit form\n```\nSame as `getByPathFoundFirst` but not allowing `null` value.\n| Parameter | Type     | Description                |\n| :-------- | :------- | :------------------------- |\n| `target` | `unknown` | A target object  |\n| `path` | `Path[]` | An array of paths. For usage, see above.  |\n| `options` | `NoNullOptions` | Additional options (see above)  |","readmeFilename":"README.md"}