{"_id":"@sanity/id-utils","_rev":"78-5331247abdccbe683162822482a72961","name":"@sanity/id-utils","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@sanity/id-utils","version":"1.0.0","keywords":["sanity","id","drafts","documents"],"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","_id":"@sanity/id-utils@1.0.0","maintainers":[{"name":"ausha","email":"ausha@sanity.io"},{"name":"kaspar.lippmaa.sanity","email":"kaspar.lippmaa@sanity.io"},{"name":"tdfka_rick","email":"joshua.ellis18@gmail.com"},{"name":"jjburbridge","email":"jonathan.burbridge@sanity.io"},{"name":"ryanblock","email":"rblock+npm@gmail.com"},{"name":"danielsgroves","email":"hello@danielgroves.net"},{"name":"colepeters","email":"cole@colepeters.com"},{"name":"dam","email":"kristoferjoseph@gmail.com"},{"name":"tbeseda","email":"tbeseda@gmail.com"},{"name":"ryanbonial-sanity","email":"ryan.bonial@sanity.io"},{"name":"madken","email":"kenneth.madsen@sanity.io"},{"name":"tiit.kass.saity","email":"tiit.kass@sanity.io"},{"name":"christianhg","email":"services@groengaard.dk"},{"name":"joan_miralles_paez","email":"joan.miralles@sanity.io"},{"name":"jwoods-sanity","email":"james.woods@sanity.io"},{"name":"armandocerna","email":"armando@cerna.ca"},{"name":"daniel.malmer","email":"daniel.malmer@sanity.io"},{"name":"jordanl17","email":"jordanl17@me.com"},{"name":"tambet","email":"tambet.masik@gmail.com"},{"name":"drewsanity","email":"drew.lyton@sanity.io"},{"name":"refiito","email":"margus@sanity.io"},{"name":"sergeisarviro","email":"sergei@sanity.io"},{"name":"ash","email":"ashley@juice49.com"},{"name":"indrek.karner","email":"indrek.karner@sanity.io"},{"name":"cngonzalez-sanity","email":"carolina@sanity.io"},{"name":"rdunk","email":"rupert@rupertdunk.com"},{"name":"rneatherway-sanity","email":"robin.neatherway@sanity.io"},{"name":"ricokahler","email":"ricokahler@me.com"},{"name":"pedro-sanity","email":"pedro@sanity.io"},{"name":"kenjonespizza","email":"ken@sanity.io"},{"name":"pauloborgesf","email":"paulo@sanity.io"},{"name":"binoy14","email":"me@binoy.io"},{"name":"simen.svale","email":"simen@sanity.io"},{"name":"svirs","email":"shur@sanity.io"},{"name":"josh_sanity_io","email":"josh@sanity.io"},{"name":"joneidejohnsen","email":"jon@sanity.io"},{"name":"rankers","email":"richardankers@gmail.com"},{"name":"snorreeb","email":"snorre.e.brekke@gmail.com"},{"name":"mattcraig","email":"matt@sanity.io"},{"name":"vincentquigley","email":"vincent@sanity.io"},{"name":"stipsan","email":"stipsan@gmail.com"},{"name":"michael-sanity","email":"michael@sanity.io"},{"name":"rubioz","email":"jarubc@gmail.com"},{"name":"tonina","email":"zhelyazkova.tonina@gmail.com"},{"name":"ritasdias","email":"anarita151@gmail.com"},{"name":"simeonsanity","email":"simeon@sanity.io"},{"name":"kmelve","email":"knut.melvaer@gmail.com"},{"name":"bjoerge","email":"bjoerge@gmail.com"},{"name":"rexxars","email":"espen@hovlandsdal.com"},{"name":"skogsmaskin","email":"per.kristian.nordnes@gmail.com"},{"name":"robinpyon","email":"robin@robinpyon.com"},{"name":"mariuslundgard","email":"studio@mariuslundgard.com"},{"name":"sanity-io","email":"developers@sanity.io"},{"name":"evenw","email":"even@sanity.io"},{"name":"radhe_sanity","email":"radhe@sanity.io"},{"name":"rbotten","email":"rbotten@gmail.com"},{"name":"judofyr","email":"judofyr@gmail.com"},{"name":"obliadp","email":"orjan@sanity.io"},{"name":"dcilke","email":"dain.cilke@gmail.com"},{"name":"fredcarlsen","email":"fred@superbig.co"},{"name":"hermanw","email":"herman@sanity.io"},{"name":"sgulseth","email":"sgulseth@gmail.com"},{"name":"atombender","email":"npm@purefiction.net"}],"contributors":[{"name":"Bjørge Næss","email":"bjoerge@gmail.com"}],"homepage":"https://github.com/sanity-io/id-utils#readme","bugs":{"url":"https://github.com/sanity-io/id-utils/issues"},"dist":{"shasum":"3bc48bf8c9f5911cd90dee79a455e55ba540b7b7","tarball":"https://registry.npmjs.org/@sanity/id-utils/-/id-utils-1.0.0.tgz","fileCount":9,"integrity":"sha512-2sb7tbdMDuUuVyocJPKG0gZBiOML/ovCe+mJiLrv1j69ODOfa2LfUjDVR+dRw/A/+XuxoJSSP8ebG7NiwTOgIA==","signatures":[{"sig":"MEUCIFp0TXKKOUZJIxDuz9G0QC5plJMHFpPhml8BtAu0gvW9AiEAhJGicL4N8STTrjxOPZWuhEAZzy2Mf8T0yhCY26dylnk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sanity%2fid-utils@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":63467},"main":"./dist/index.cjs","type":"module","_from":"file:sanity-id-utils-1.0.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"import":"./dist/index.js","source":"./src/index.ts","default":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"scripts":{"dev":"run-p pkg:watch","docs":"run-s build && api-extractor run --local && api-documenter markdown -i temp -o docs","lint":"eslint .","test":"vitest run --typecheck","build":"run-p pkg:build","check":"run-s typecheck pkg:build test","format":"prettier --write --cache --ignore-unknown .","test:ui":"vitest --ui","coverage":"vitest run --coverage","lint:fix":"eslint . --fix","pkg:build":"pkg build --strict --check --clean","pkg:watch":"pkg watch --strict","typecheck":"tsc --noEmit --emitDeclarationOnly false -p tsconfig.dist.json","test:watch":"vitest --typecheck","typecheck:examples":"run-p typecheck:examples:*","typecheck:examples:ts":"tsc --project examples/tsconfig.json"},"_npmUser":{"name":"sanity-io","email":"developers@sanity.io"},"_resolved":"/tmp/67b3b40c79f15ab2ad82c80562a95398/sanity-id-utils-1.0.0.tgz","_integrity":"sha512-2sb7tbdMDuUuVyocJPKG0gZBiOML/ovCe+mJiLrv1j69ODOfa2LfUjDVR+dRw/A/+XuxoJSSP8ebG7NiwTOgIA==","repository":{"url":"git+https://github.com/sanity-io/id-utils.git","type":"git"},"_npmVersion":"10.9.0","description":"Utilities for working with Sanity document IDs","directories":{},"sideEffects":false,"_nodeVersion":"22.10.0","browserslist":"extends @sanity/browserslist-config","dependencies":{"lodash":"^4.17.21","ts-brand":"^0.2.0","@sanity/uuid":"^3.0.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.14.0","rimraf":"^6.0.1","vitest":"^2.1.4","prettier":"^3.3.3","@eslint/js":"^9.14.0","@vitest/ui":"^2.1.4","typescript":"^5.6.3","npm-run-all2":"^7.0.1","@sanity/types":"^3.63.0","@types/lodash":"^4.17.13","@sanity/pkg-utils":"^6.11.9","@types/eslint__js":"^8.42.3","typescript-eslint":"^8.13.0","@vitest/coverage-v8":"^2.1.4","eslint-plugin-import":"^2.31.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@sanity/prettier-config":"^1.0.3","@types/diff-match-patch":"^1.0.36","@microsoft/api-extractor":"^7.47.11","@microsoft/api-documenter":"^7.25.21","@typescript-eslint/parser":"^8.13.0","@vitest/coverage-istanbul":"2.1.4","eslint-import-resolver-node":"^0.3.9","eslint-plugin-unused-imports":"^4.1.4","@typescript-eslint/eslint-plugin":"^8.13.0","eslint-plugin-simple-import-sort":"^12.1.1"},"_npmOperationalInternal":{"tmp":"tmp/id-utils_1.0.0_1731329296289_0.8333012746468773","host":"s3://npm-registry-packages"}},"1.1.0":{"_id":"@sanity/id-utils@1.1.0","bugs":{"url":"https://github.com/sanity-io/id-utils/issues"},"dist":{"shasum":"58c342c06e1422b67d818482fc105ba7a3d7307b","tarball":"https://registry.npmjs.org/@sanity/id-utils/-/id-utils-1.1.0.tgz","fileCount":9,"integrity":"sha512-A+DujVHCO3/+0DuzinmfCRQacIWVIherK0AHqFDoDOSgxx+Bur1kLhzX8fn7PdB2uZilxu2zWOr+UaGcj5zGbA==","signatures":[{"sig":"MEUCIQDjsCEs3aoQZy1p5ALjTSvTJ9VKwcgOATYA+93NIzpwDwIgboEaFSvbFUtjVcBCTdt6jYVXgDIvghj1KCyOKZRj6w4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD9pYXnzrBYRx6vmQ4XI/EW459VDjKxG1VsjTqttz2igAIgVel9KZkoGNyAOpof9ZI6Yg0bFAsHecNbqiqCzyO9cS8="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@sanity%2fid-utils@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":76555},"main":"./dist/index.cjs","name":"@sanity/id-utils","type":"module","_from":"file:sanity-id-utils-1.1.0.tgz","types":"./dist/index.d.ts","author":{"name":"Sanity.io","email":"hello@sanity.io"},"module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"import":"./dist/index.js","source":"./src/index.ts","default":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"license":"MIT","scripts":{"dev":"run-p pkg:watch","docs":"run-s build && api-extractor run --local && api-documenter markdown -i temp -o docs","lint":"eslint .","test":"vitest run --typecheck","build":"run-p pkg:build","check":"run-s typecheck pkg:build test","format":"prettier --write --cache --ignore-unknown .","test:ui":"vitest --ui","coverage":"vitest run --coverage","lint:fix":"eslint . --fix","pkg:build":"pkg build --strict --check --clean","pkg:watch":"pkg watch --strict","typecheck":"tsc --noEmit --emitDeclarationOnly false -p tsconfig.dist.json","test:watch":"vitest --typecheck","typecheck:examples":"run-p typecheck:examples:*","typecheck:examples:ts":"tsc --project examples/tsconfig.json"},"version":"1.1.0","_npmUser":{"name":"sanity-svc.npm","email":"svc.npm@sanity.io"},"homepage":"https://github.com/sanity-io/id-utils#readme","keywords":["sanity","id","drafts","documents"],"_resolved":"/tmp/554f009c13d6034e6e813565d8a7263d/sanity-id-utils-1.1.0.tgz","_integrity":"sha512-A+DujVHCO3/+0DuzinmfCRQacIWVIherK0AHqFDoDOSgxx+Bur1kLhzX8fn7PdB2uZilxu2zWOr+UaGcj5zGbA==","repository":{"url":"git+https://github.com/sanity-io/id-utils.git","type":"git"},"_npmVersion":"11.19.0","description":"Utilities for working with Sanity document IDs","directories":{},"maintainers":[{"name":"sanity-svc.npm","email":"svc.npm@sanity.io"},{"name":"sanity-io","email":"developers@sanity.io"}],"sideEffects":false,"_nodeVersion":"24.20.0","browserslist":"extends @sanity/browserslist-config","contributors":[{"name":"Bjørge Næss","email":"bjoerge@gmail.com"}],"dependencies":{"ts-brand":"^0.2.0","@sanity/uuid":"^3.0.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.14.0","rimraf":"^6.0.1","vitest":"^2.1.4","prettier":"^3.3.3","@eslint/js":"^9.14.0","@vitest/ui":"^2.1.4","typescript":"^5.6.3","npm-run-all2":"^7.0.1","@sanity/types":"^3.63.0","@sanity/pkg-utils":"^6.11.9","@types/eslint__js":"^8.42.3","typescript-eslint":"^8.13.0","@vitest/coverage-v8":"^2.1.4","eslint-plugin-import":"^2.31.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@sanity/prettier-config":"^1.0.3","@types/diff-match-patch":"^1.0.36","@microsoft/api-extractor":"^7.47.11","@microsoft/api-documenter":"^7.25.21","@typescript-eslint/parser":"^8.13.0","@vitest/coverage-istanbul":"2.1.4","eslint-import-resolver-node":"^0.3.9","eslint-plugin-unused-imports":"^4.1.4","@typescript-eslint/eslint-plugin":"^8.13.0","eslint-plugin-simple-import-sort":"^12.1.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/id-utils_1.1.0_1788886821420_0.7611991024868567"}}},"time":{"created":"2024-11-11T12:48:16.152Z","modified":"2026-09-08T17:00:21.826Z","1.0.0":"2024-11-11T12:48:16.456Z","1.1.0":"2026-09-08T17:00:21.523Z"},"bugs":{"url":"https://github.com/sanity-io/id-utils/issues"},"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","homepage":"https://github.com/sanity-io/id-utils#readme","keywords":["sanity","id","drafts","documents"],"repository":{"url":"git+https://github.com/sanity-io/id-utils.git","type":"git"},"description":"Utilities for working with Sanity document IDs","contributors":[{"name":"Bjørge Næss","email":"bjoerge@gmail.com"}],"maintainers":[{"name":"sanity-svc.npm","email":"svc.npm@sanity.io"},{"name":"sanity-io","email":"developers@sanity.io"}],"readme":"# @sanity/id-utils\n\nUtilities for working with Sanity document IDs\n\n# Why?\nQuite often you'll see an APIs that takes a Sanity document ID as a `string`, but in many cases there’s an implicit expectation in the API about this document ID being either a published ID or a draft ID. Passing the wrong type of ID can lead to subtle errors, and at the same time guarding against this often leads to lots of redundant checks in places we a certain document ID variant is required.\n\nWith the help from this library, and it’s use of [branded types](https://www.learningtypescript.com/articles/branded-types) functions and components can now declare which ID variant they need as part of their signature, which provides developers with immediate feedback if attempting to pass the wrong variant.\n\n\nFor example, imagine that this component has an implicit assumption that `props.id` will always be the id of the published document:\n```typescript\nfunction SomeComponent(props: {id: string}) {\n//... Things will break in spectacular ways if `props.id` is a draft id\n}\n```\nThis can now be written this way:\n```typescript\nfunction SomeComponent(props: {id: PublishedId}) {\n//...\n}\n````\nIf you try to pass this component a draft id now, you’ll immediately see an error in your IDE\n```tsx\n<SomeComponent id={someDraftId} />\n// TS2322: Type string is not assignable to type PublishedId\n// Or, if it's of the DraftId type:\n// TS2322: Type DraftId is not assignable to type PublishedId\n```\n\nYou will have to make sure to turn it into a published id before passing it:\n```tsx\n<SomeComponent id={getPublishedId(someDraftId)} />\n```\n\n# Features\n\n- Added type safety through [branded types](https://www.learningtypescript.com/articles/branded-types) via [ts-brand](https://github.com/kourge/ts-brand).\n- Runtime validation of IDs. Tells you if you accidentally use an [invalid](https://www.sanity.io/docs/ids#10abf7adf05a) ID.\n- Easily convert between the IDs the published documents, draft document and any version of a document.\n- Generate safe document ids from strings, useful for importing from external systems that may have incompatible ids\n\n## Usage example\n\n```typescript\nimport {\n  DocumentId,\n  getDraftId,\n  getPublishedId,\n  getVersionId,\n  getVersionNameFromId,\n} from '@sanity/id-utils'\n\n// Make the document id \"foo\". This would have thrown the provided id was not valid\nconst id = DocumentId('foo')\n\n// get the draft id of foo\nconst draftId = getDraftId(id)\n\nconsole.log(draftId)\n// => drafts.foo\n\n// get the id of the document in version \"someversion\"\nconst someVersionId = getVersionId(draftId, 'some-version')\nconsole.log(someVersionId)\n// => versions.some-version.foo\n\n// get the id of the document in version \"other-version\"\nconst otherVersionId = getVersionId(draftId, 'other-version')\nconsole.log(otherVersionId)\n// => versions.other-version.foo\n\n// get the published id of the version\nconsole.log(getPublishedId(otherVersionId))\n// => foo\n\n// get the published id of the other version\nconsole.log(getVersionNameFromId(otherVersionId))\n// => other-version\n\n// get the version name from the draft id\n// @ts-expect-error - this is a type error because draft ids does not contain version names\nconsole.log(getVersionNameFromId(draftId))\n```\n\n# API Docs\n\nFind the latest autogenerated API docs [here](https://github.com/sanity-io/id-utils/blob/main/docs/id-utils.md)\n","readmeFilename":"README.md"}