@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
1 lines • 1.36 kB
Source Map (JSON)
{"version":3,"file":"composeSerializers.cjs","names":[],"sources":["../../src/richtext/composeSerializers.ts"],"sourcesContent":["import type { RichTextFunctionSerializer } from \"./types\"\n\n/**\n * Takes an array of serializers and returns a serializer applying provided\n * serializers sequentially until a result is returned\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level\n * packages Most users aren't expected to this function directly\n *\n * @typeParam SerializerReturnType - Return type of serializers\n *\n * @param serializers - Serializers to compose\n *\n * @returns Composed serializer\n */\nexport const composeSerializers = <SerializerReturnType>(\n\t...serializers: (\n\t\t| RichTextFunctionSerializer<SerializerReturnType>\n\t\t| undefined\n\t)[]\n): RichTextFunctionSerializer<SerializerReturnType> => {\n\treturn (...args) => {\n\t\tfor (let i = 0; i < serializers.length; i++) {\n\t\t\tconst serializer = serializers[i]\n\n\t\t\tif (serializer) {\n\t\t\t\tconst res = serializer(...args)\n\n\t\t\t\tif (res != null) {\n\t\t\t\t\treturn res\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,sBACZ,GAAG,gBAImD;AACtD,SAAQ,GAAG,SAAS;AACnB,OAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;GAC5C,MAAM,aAAa,YAAY;AAE/B,OAAI,YAAY;IACf,MAAM,MAAM,WAAW,GAAG,KAAK;AAE/B,QAAI,OAAO,KACV,QAAO"}