{"version":3,"sources":["../../source/random/random.ts","../../source/schema/bigint/bigint.ts","../../source/schema/native/native.ts","../../source/schema/empty/empty.ts","../../source/schema/float/float.ts","../../source/schema/integer/integer.ts","../../source/shuffle/shuffle.ts"],"names":["validatePositiveInteger","getRandomIntNumber","BUILT_IN_OBJECTS_SCHEMAS","BIGINT64_ARRAY_SCHEMA","BIGUINT64_ARRAY_SCHEMA","z","ARRAY_SCHEMA","validateArray","value","EMPTY_ARRAY_SCHEMA","isEmptyArray","array","FLOAT32_ARRAY_SCHEMA","FLOAT64_ARRAY_SCHEMA","INT8_ARRAY_SCHEMA","INT16_ARRAY_SCHEMA","INT32_ARRAY_SCHEMA","UINT8_ARRAY_SCHEMA","UINT8_CLAMPED_ARRAY_SCHEMA","UINT16_ARRAY_SCHEMA","UINT32_ARRAY_SCHEMA","getRandomIndex","length","shuffleArray","shuffled","currentIndex","newIndex"],"mappings":"AAAA,OAAS,2BAAAA,MAA+B,kCACxC,OAAS,sBAAAC,MAA0B,yCCDnC,OAAS,4BAAAC,MAAgC,yCAKlC,IAAMC,EAAwBD,EAAyB,cACjDE,EAAyBF,EAAyB,eCN/D,OAAS,KAAAG,MAAS,MAEX,IAAMC,EAAeD,EAAE,MAAMA,EAAE,IAAI,CAAC,EAIpC,SAASE,EAAcC,EAA2C,CACxEF,EAAa,MAAME,CAAK,CACzB,CCNO,IAAMC,EAAqBH,EAAa,OAAO,CAAC,EAQhD,SAASI,EAAaC,EAAiE,CAC7F,OAAAJ,EAAcI,CAAK,EAEZF,EAAmB,UAAUE,CAAK,EAAE,OAC5C,CCdA,OAAS,4BAAAT,MAAgC,yCAKlC,IAAMU,EAAuBV,EAAyB,aAChDW,EAAuBX,EAAyB,aCN7D,OAAS,4BAAAA,MAAgC,yCAWlC,IAAMY,EAAoBZ,EAAyB,UAC7Ca,EAAqBb,EAAyB,WAC9Cc,EAAqBd,EAAyB,WAQpD,IAAMe,EAAqBf,EAAyB,WAC9CgB,EAA6BhB,EAAyB,kBACtDiB,EAAsBjB,EAAyB,YAC/CkB,EAAsBlB,EAAyB,YLnB5D,eAAsBmB,EAAeC,EAAiC,CACrE,OAAO,MAAMrB,EAAmB,CAAE,IAAK,EAAG,IAAKqB,EAAS,CAAE,CAAC,CAC5D,CMHA,eAAsBC,GAAwBZ,EAA4D,CAGzG,GAFAJ,EAAcI,CAAK,EAEfD,EAAaC,CAAK,EAAG,MAAO,CAAC,EAC5B,CACJ,IAAMa,EAAW,CAAC,GAAGb,CAAK,EAE1B,QAASc,EAAed,EAAM,OAAS,EAAGc,EAAe,EAAGA,IAAgB,CAC3E,IAAMC,EAAW,MAAML,EAAeV,EAAM,MAAM,EAGlD,CACaa,EAASC,CAAY,EACrBD,EAASE,CAAQ,CACrB,EAAI,CACZF,EAASE,CAAQ,EACjBF,EAASC,CAAY,CACtB,EAGD,OAAOD,EAET","sourcesContent":["import { validatePositiveInteger } from \"@terminal-nerds/snippets-number\";\nimport { getRandomIntNumber } from \"@terminal-nerds/snippets-number/random\";\n\nimport { validateArray } from \"../schema/schema.ts\";\n\nexport async function getRandomIndex(length: number): Promise<number> {\n\treturn await getRandomIntNumber({ min: 0, max: length - 1 });\n}\n\nexport async function getRandomItem<Type = unknown>(array: Array<Type> | readonly Type[]): Promise<Type> {\n\tvalidateArray(array);\n\n\treturn array.at(await getRandomIndex(array.length)) as Type;\n}\n\ninterface RandomArrayItemsOptions {\n\t/**\n\t * A positive integer, with a count of how many random items you want to be picked.\n\t */\n\tcount: number;\n}\n\n/** NOTE: It could create duplicates. */\nexport async function getRandomItems<Type = unknown>(\n\tarray: Array<Type> | readonly Type[],\n\toptions: RandomArrayItemsOptions,\n): Promise<Array<Type>> {\n\tconst { count } = options;\n\n\tvalidatePositiveInteger(count);\n\n\tconst results: Array<Type> = [];\n\n\twhile (results.length < count) {\n\t\tresults.push(await getRandomItem(array));\n\t}\n\n\treturn results;\n}\n","import { BUILT_IN_OBJECTS_SCHEMAS } from \"@terminal-nerds/snippets-type/built-in\";\n\nexport const BIGINT_ARRAY_TYPES = [\"signed\", \"unsigned\"] as const;\nexport type BigIntArrayType = (typeof BIGINT_ARRAY_TYPES)[number];\n\nexport const BIGINT64_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.BigInt64Array;\nexport const BIGUINT64_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.BigUint64Array;\n\nexport const BIGINT_ARRAY_SCHEMAS = {\n\tsigned: BIGINT64_ARRAY_SCHEMA,\n\tunsigned: BIGUINT64_ARRAY_SCHEMA,\n} as const;\n\nexport interface BigIntArrays {\n\tsigned: BigInt64Array;\n\tunsigned: BigUint64Array;\n}\n\nexport type BigIntArray<Type extends BigIntArrayType> = BigIntArrays[Type];\n\ntype BigIntArrayOptions<Type extends BigIntArrayType> = {\n\ttype: Type;\n};\n\nexport function validateBigIntArray<Type extends BigIntArrayType>(\n\tvalue: unknown,\n\toptions: BigIntArrayOptions<Type>,\n): asserts value is BigIntArray<Type> {\n\tconst { type } = options;\n\n\tBIGINT_ARRAY_SCHEMAS[type].parse(value);\n}\n\nexport function isBigIntArray<Type extends BigIntArrayType>(\n\tvalue: unknown,\n\toptions: BigIntArrayOptions<Type>,\n): value is BigIntArray<Type> {\n\tconst { type } = options;\n\n\treturn BIGINT_ARRAY_SCHEMAS[type].safeParse(value).success;\n}\n","import { z } from \"zod\";\n\nexport const ARRAY_SCHEMA = z.array(z.any());\n\nexport type AnyArray = ReadonlyArray<unknown>;\n\nexport function validateArray(value: unknown): asserts value is AnyArray {\n\tARRAY_SCHEMA.parse(value);\n}\n\nexport function validateArrays(...arrays: AnyArray[]): void {\n\tfor (const currentArray of arrays) {\n\t\tvalidateArray(currentArray);\n\t}\n}\n","import { ARRAY_SCHEMA, validateArray } from \"../native/native.ts\";\n\nexport const EMPTY_ARRAY_SCHEMA = ARRAY_SCHEMA.length(0);\n\nexport type EmptyArray = [];\n\nexport function validateEmptyArray(array: Array<unknown> | readonly unknown[]): asserts array is EmptyArray {\n\tEMPTY_ARRAY_SCHEMA.parse(array);\n}\n\nexport function isEmptyArray(array: Array<unknown> | readonly unknown[]): array is EmptyArray {\n\tvalidateArray(array);\n\n\treturn EMPTY_ARRAY_SCHEMA.safeParse(array).success;\n}\n","import { BUILT_IN_OBJECTS_SCHEMAS } from \"@terminal-nerds/snippets-type/built-in\";\n\nexport const FLOAT_ARRAY_BITS = [32, 64] as const;\nexport type FloatArrayBit = (typeof FLOAT_ARRAY_BITS)[number];\n\nexport const FLOAT32_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Float32Array;\nexport const FLOAT64_ARRAY_SCHEMA = BUILT_IN_OBJECTS_SCHEMAS.Float64Array;\n\nexport const FLOAT_ARRAY_SCHEMAS = {\n\t32: FLOAT32_ARRAY_SCHEMA,\n\t64: FLOAT64_ARRAY_SCHEMA,\n} as const;\n\nexport type FloatArrays = {\n\t32: Float32Array;\n\t64: Float64Array;\n};\n\nexport type FloatArray<Bit extends FloatArrayBit> = FloatArrays[Bit];\n\nexport interface FloatArrayOptions<Bit extends FloatArrayBit> {\n\tbit: Bit;\n}\n\nexport function validateFloatArray<Bit extends FloatArrayBit>(\n\tvalue: unknown,\n\toptions: FloatArrayOptions<Bit>,\n): asserts value is FloatArray<Bit> {\n\tconst { bit } = options;\n\n\tFLOAT_ARRAY_SCHEMAS[bit].parse(value);\n}\n\nexport function isFloatArray<Bit extends FloatArrayBit>(\n\tvalue: unknown,\n\toptions: FloatArrayOptions<Bit>,\n): value is FloatArray<Bit> {\n\tconst { bit } = options;\n\n\treturn FLOAT_ARRAY_SCHEMAS[bit].safeParse(value).success;\n}\n","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","import { getRandomIndex } from \"../random/random.ts\";\nimport { isEmptyArray } from \"../schema/empty/empty.ts\";\nimport { validateArray } from \"../schema/schema.ts\";\n\nexport async function shuffleArray<ValueType>(array: ReadonlyArray<ValueType>): Promise<Array<ValueType>> {\n\tvalidateArray(array);\n\n\tif (isEmptyArray(array)) return [];\n\telse {\n\t\tconst shuffled = [...array];\n\n\t\tfor (let currentIndex = array.length - 1; currentIndex > 0; currentIndex--) {\n\t\t\tconst newIndex = await getRandomIndex(array.length);\n\n\t\t\t/* prettier-ignore */\n\t\t\t[\n                shuffled[currentIndex],\n                shuffled[newIndex],\n            ] = [\n\t\t\t\tshuffled[newIndex] as ValueType,\n\t\t\t\tshuffled[currentIndex] as ValueType,\n\t\t\t];\n\t\t}\n\n\t\treturn shuffled;\n\t}\n}\n"]}