UNPKG

ts-regex-builder

Version:

Maintainable regular expressions for TypeScript and JavaScript.

1 lines 1.72 kB
{"version":3,"file":"hex-color.mjs","names":["buildRegExp","endOfString","startOfString","wordBoundary","choiceOf","repeat","hexDigit","hexColorFinder","ignoreCase","global","hexColorValidator"],"sources":["../../../src/patterns/hex-color.ts"],"sourcesContent":["import { buildRegExp } from '../builders';\nimport { endOfString, startOfString, wordBoundary } from '../constructs/anchors';\nimport { choiceOf } from '../constructs/choice-of';\nimport { repeat } from '../constructs/repeat';\n\nconst hexDigit = /[0-9a-f]/;\n\n/** Find hex color strings in a text. */\nexport const hexColorFinder = buildRegExp(\n [\n '#',\n choiceOf(\n repeat(hexDigit, 6), // #rrggbb\n repeat(hexDigit, 3), // #rgb\n ),\n wordBoundary,\n ],\n { ignoreCase: true, global: true },\n);\n\n/**\n * Check that given text is a valid hex color.\n *\n * Allows both 3 and 6 digit hex colors.\n * */\nexport const hexColorValidator = buildRegExp(\n [\n startOfString, // Match whole string\n '#',\n choiceOf(\n repeat(hexDigit, 6), // #rrggbb\n repeat(hexDigit, 3), // #rgb\n ),\n endOfString,\n ],\n { ignoreCase: true },\n);\n"],"mappings":"SAASA,WAAW;AAAA,SACXC,WAAW,EAAEC,aAAa,EAAEC,YAAY;AAAA,SACxCC,QAAQ;AAAA,SACRC,MAAM;AAEf,MAAMC,QAAQ,GAAG,UAAU;AAG3B,OAAO,MAAMC,cAAc,GAAGP,WAAW,CACvC,CACE,GAAG,EACHI,QAAQ,CACNC,MAAM,CAACC,QAAQ,EAAE,CAAC,CAAC,EACnBD,MAAM,CAACC,QAAQ,EAAE,CAAC,CACpB,CAAC,EACDH,YAAY,CACb,EACD;EAAEK,UAAU,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CACnC,CAAC;AAOD,OAAO,MAAMC,iBAAiB,GAAGV,WAAW,CAC1C,CACEE,aAAa,EACb,GAAG,EACHE,QAAQ,CACNC,MAAM,CAACC,QAAQ,EAAE,CAAC,CAAC,EACnBD,MAAM,CAACC,QAAQ,EAAE,CAAC,CACpB,CAAC,EACDL,WAAW,CACZ,EACD;EAAEO,UAAU,EAAE;AAAK,CACrB,CAAC","ignoreList":[]}