{"version":3,"sources":["../../../source/schema/integer/integer.ts"],"names":["BUILT_IN_OBJECTS_SCHEMAS","INTEGER_ARRAY_TYPES","INTEGER_ARRAY_BITS","INTEGER_ARRAY_CATEGORIES","INT8_ARRAY_SCHEMA","INT16_ARRAY_SCHEMA","INT32_ARRAY_SCHEMA","INT_ARRAY_SCHEMAS","UINT8_ARRAY_SCHEMA","UINT8_CLAMPED_ARRAY_SCHEMA","UINT16_ARRAY_SCHEMA","UINT32_ARRAY_SCHEMA","UINT_ARRAY_SCHEMAS","INTEGER_ARRAY_SCHEMAS","isUnsigned","type","is8Bit","bit","validateIntegerArray","value","options","clamped","isIntegerArray"],"mappings":"AAAA,OAAS,4BAAAA,MAAgC,yCAElC,IAAMC,EAAsB,CAAC,SAAU,UAAU,EAG3CC,EAAqB,CAAC,EAAG,GAAI,EAAE,EAG/BC,EAA2B,CAAC,UAAW,UAAU,EAGjDC,EAAoBJ,EAAyB,UAC7CK,EAAqBL,EAAyB,WAC9CM,EAAqBN,EAAyB,WAE9CO,EAAoB,CAChC,EAAG,CAAE,SAAUH,CAAkB,EACjC,GAAI,CAAE,SAAUC,CAAmB,EACnC,GAAI,CAAE,SAAUC,CAAmB,CACpC,EAEaE,EAAqBR,EAAyB,WAC9CS,EAA6BT,EAAyB,kBACtDU,EAAsBV,EAAyB,YAC/CW,EAAsBX,EAAyB,YAE/CY,EAAqB,CACjC,EAAG,CAAE,SAAUJ,EAAoB,QAASC,CAA2B,EACvE,GAAI,CAAE,SAAUC,CAAoB,EACpC,GAAI,CAAE,SAAUC,CAAoB,CACrC,EAEaE,EAAwB,CACpC,OAAQN,EACR,SAAUK,CACX,EAkDO,SAASE,EAAWC,EAA4C,CACtE,OAAOA,IAAS,UACjB,CAEO,SAASC,EAAOC,EAAgC,CACtD,OAAOA,IAAQ,CAChB,CAQO,SAASC,EAKfC,EACAC,EACiE,CACjE,GAAM,CAAE,KAAAL,EAAM,IAAAE,CAAI,EAAIG,EAEtB,GAAIN,EAAWC,CAAI,GAAKC,EAAOC,CAAG,EAAG,CACpC,GAAM,CAAE,QAAAI,EAAU,EAAM,EAAID,EAE5BP,EAAsBE,CAAI,EAAEE,CAAG,EAAEI,EAAU,UAAY,UAAU,EAAE,MAAMF,CAAK,OAE9EN,EAAsBE,CAAI,EAAEE,CAAG,EAAE,SAAY,MAAME,CAAK,CAE1D,CAQO,SAASG,EAKfH,EACAC,EACyD,CACzD,GAAM,CAAE,KAAAL,EAAM,IAAAE,CAAI,EAAIG,EAEtB,GAAIN,EAAWC,CAAI,GAAKC,EAAOC,CAAG,EAAG,CACpC,GAAM,CAAE,QAAAI,EAAU,EAAM,EAAID,EAE5B,OAAOP,EAAsBE,CAAI,EAAEE,CAAG,EAAEI,EAAU,UAAY,UAAU,EAAE,UAAUF,CAAK,EAAE,YAE3F,QAAON,EAAsBE,CAAI,EAAEE,CAAG,EAAE,SAAY,UAAUE,CAAK,EAAE,OAEvE","sourcesContent":["import { BUILT_IN_OBJECTS_SCHEMAS } from \"@terminal-nerds/snippets-type/built-in\";\n\nexport const INTEGER_ARRAY_TYPES = [\"signed\", \"unsigned\"] as const;\nexport type IntegerArrayType = (typeof INTEGER_ARRAY_TYPES)[number];\n\nexport const INTEGER_ARRAY_BITS = [8, 16, 32] as const;\nexport type IntegerArrayBit = (typeof INTEGER_ARRAY_BITS)[number];\n\nexport const INTEGER_ARRAY_CATEGORIES = [\"clamped\", \"standard\"] as const;\nexport type IntegerArrayCategory = (typeof INTEGER_ARRAY_CATEGORIES)[number];\n\nexport const INT8_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Int8Array;\nexport const INT16_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Int16Array;\nexport const INT32_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Int32Array;\n\nexport const INT_ARRAY_SCHEMAS = {\n\t8: { standard: INT8_ARRAY_SCHEMA },\n\t16: { standard: INT16_ARRAY_SCHEMA },\n\t32: { standard: INT32_ARRAY_SCHEMA },\n} as const;\n\nexport const UINT8_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Uint8Array;\nexport const UINT8_CLAMPED_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Uint8ClampedArray;\nexport const UINT16_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Uint16Array;\nexport const UINT32_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Uint32Array;\n\nexport const UINT_ARRAY_SCHEMAS = {\n\t8: { standard: UINT8_ARRAY_SCHEMA, clamped: UINT8_CLAMPED_ARRAY_SCHEMA },\n\t16: { standard: UINT16_ARRAY_SCHEMA },\n\t32: { standard: UINT32_ARRAY_SCHEMA },\n} as const;\n\nexport const INTEGER_ARRAY_SCHEMAS = {\n\tsigned: INT_ARRAY_SCHEMAS,\n\tunsigned: UINT_ARRAY_SCHEMAS,\n} as const;\n\nexport interface IntegerArrays {\n\tsigned: {\n\t\t8: { standard: Int8Array };\n\t\t16: { standard: Int16Array };\n\t\t32: { standard: Int32Array };\n\t};\n\tunsigned: {\n\t\t8: { standard: Uint8Array; clamped: Uint8ClampedArray };\n\t\t16: { standard: Uint16Array };\n\t\t32: { standard: Uint32Array };\n\t};\n}\n\nexport type IntArray<Bit extends IntegerArrayBit> = IntegerArrays[\"signed\"][Bit][\"standard\"];\nexport type UintArray<Bit extends IntegerArrayBit, Category extends IntegerArrayCategory> = Bit extends 8\n\t? IntegerArrays[\"unsigned\"][8][Category]\n\t: IntegerArrays[\"unsigned\"][Bit][\"standard\"];\nexport type IntegerArray<\n\tType extends IntegerArrayType,\n\tBit extends IntegerArrayBit,\n\tCategory extends IntegerArrayCategory = Type extends \"unsigned\"\n\t\t? Bit extends 8\n\t\t\t? IntegerArrayCategory\n\t\t\t: \"standard\"\n\t\t: \"standard\",\n> = Type extends \"signed\" ? IntArray<Bit> : Type extends \"unsigned\" ? UintArray<Bit, Category> : never;\n\ntype IntArrayOptions<Type extends IntegerArrayType, Bit extends IntegerArrayBit> = {\n\ttype: Type;\n\tbit: Bit;\n};\n\ntype Uint8ArrayOptions<Clamped extends boolean | undefined = undefined> = {\n\ttype: \"unsigned\";\n\tclamped?: Clamped;\n\tbit: 8;\n};\n\nexport type IntegerArrayOptions<\n\tType extends IntegerArrayType,\n\tBit extends IntegerArrayBit,\n\tClamped extends boolean | undefined = undefined,\n> = Type extends \"unsigned\"\n\t? Bit extends 8\n\t\t? Uint8ArrayOptions<Type extends \"unsigned\" ? (Bit extends 8 ? Clamped : undefined) : undefined>\n\t\t: IntArrayOptions<Type, Bit>\n\t: IntArrayOptions<Type, Bit>;\n\nexport function isUnsigned(type: IntegerArrayType): type is \"unsigned\" {\n\treturn type === \"unsigned\";\n}\n\nexport function is8Bit(bit: IntegerArrayBit): bit is 8 {\n\treturn bit === 8;\n}\n\n/**\n * FIXME:\n * There's an unwanted case, where the passed options -`{ type: \"standard\", bit: 8 }`\n * the return value will be: `Uint8Array` | `Uint8ClampedArray`.\n * What is expected: it should pick one, and base it on the `clamped` optional key in options.\n */\nexport function validateIntegerArray<\n\tType extends IntegerArrayType,\n\tBit extends IntegerArrayBit,\n\tClamped extends boolean | undefined = undefined,\n>(\n\tvalue: unknown,\n\toptions: IntegerArrayOptions<Type, Bit, Clamped>,\n): asserts value is IntegerArray<Type, Bit, IntegerArrayCategory> {\n\tconst { type, bit } = options;\n\n\tif (isUnsigned(type) && is8Bit(bit)) {\n\t\tconst { clamped = false } = options as IntegerArrayOptions<\"unsigned\", 8, Clamped>;\n\n\t\tINTEGER_ARRAY_SCHEMAS[type][bit][clamped ? \"clamped\" : \"standard\"].parse(value);\n\t} else {\n\t\tINTEGER_ARRAY_SCHEMAS[type][bit][\"standard\"].parse(value);\n\t}\n}\n\n/**\n * FIXME:\n * There's an unwanted case, where the passed options -`{ type: \"standard\", bit: 8 }`\n * the return value will be: `Uint8Array` | `Uint8ClampedArray`.\n * What is expected: it should pick one, and base it on the `clamped` optional key in options.\n */\nexport function isIntegerArray<\n\tType extends IntegerArrayType,\n\tBit extends IntegerArrayBit,\n\tClamped extends boolean | undefined = undefined,\n>(\n\tvalue: unknown,\n\toptions: IntegerArrayOptions<Type, Bit, Clamped>,\n): value is IntegerArray<Type, Bit, IntegerArrayCategory> {\n\tconst { type, bit } = options;\n\n\tif (isUnsigned(type) && is8Bit(bit)) {\n\t\tconst { clamped = false } = options as IntegerArrayOptions<\"unsigned\", 8, Clamped>;\n\n\t\treturn INTEGER_ARRAY_SCHEMAS[type][bit][clamped ? \"clamped\" : \"standard\"].safeParse(value).success;\n\t} else {\n\t\treturn INTEGER_ARRAY_SCHEMAS[type][bit][\"standard\"].safeParse(value).success;\n\t}\n}\n"]}