@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
1 lines • 1.02 kB
Source Map (JSON)
{"version":3,"file":"findRef.cjs","sources":["../../../src/lib/findRef.ts"],"sourcesContent":["import type { Ref } from \"../types/api/ref\"\n\nimport { PrismicError } from \"../errors/PrismicError\"\n\n/**\n * Returns the first ref from a list that passes a filter (a function that\n * returns true).\n *\n * @param refs - A list of refs to search.\n * @param filter - A function that determines if a ref from the list matches the\n * criteria.\n *\n * @returns The first matching ref.\n *\n * @throws If a matching ref cannot be found.\n */\nexport const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {\n\tconst ref = refs.find((ref) => filter(ref))\n\n\tif (!ref) {\n\t\tthrow new PrismicError(\"Ref could not be found.\", undefined, undefined)\n\t}\n\n\treturn ref\n}\n"],"names":["ref","PrismicError"],"mappings":";;;AAgBa,MAAA,UAAU,CAAC,MAAa,WAAsC;AAC1E,QAAM,MAAM,KAAK,KAAK,CAACA,SAAQ,OAAOA,IAAG,CAAC;AAE1C,MAAI,CAAC,KAAK;AACT,UAAM,IAAIC,aAAA,aAAa,2BAA2B,QAAW,MAAS;AAAA,EAAA;AAGhE,SAAA;AACR;;"}