/** * Copyright 2026 - present Nazmul Hassan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { C as NormalPrimitiveKey, li as NestedPrimitiveKey, ni as GenericObject } from "./index-Dx3yeNwR.mjs"; //#region src/types/array.d.ts /** * Flatten Array or Wrap in Array */ type Flattened = T extends (infer U)[] ? Flattened : T; /** * Union of type `T` and array of `T` */ type TypeOrArray = T | Array; /** * * Configuration for `createOptionsArray`. * - Defines the mapping between keys in the input objects and the keys in the output options. * * @typeParam T - The type of the objects in the input array. * @typeParam K1 - The name of the key for the first field in the output (default: `'value'`). * @typeParam K2 - The name of the key for the second field in the output (default: `'label'`). * @typeParam V - Whether to keep the `value` field as number if it is a number. Defaults to `false`. */ interface OptionsConfig { /** * - The key in the input objects to use for the first field of the option. Only primitive values (`string | number | boolean | null | undefined`) are accepted. * @example * // If the input objects have an `id` field and you want to use it as the `value` field in the output: * createOptionsArray(data, {firstFieldKey: 'id'}). */ firstFieldKey: NormalPrimitiveKey; /** * - The key in the input objects to use for the second field of the option. Only primitive values (`string | number | boolean | null | undefined`) are accepted. * @example * // If the input objects have a `name` field and you want to use it as the `label` field in the output: * createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name'}). */ secondFieldKey: NormalPrimitiveKey; /** * - The name of the first field in the output object. * - Defaults to `'value'`. * @example * // If you want the output field to be named `'key'` instead of `'value'`: * createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name', firstFieldName: 'key'}). */ firstFieldName?: K1; /** * - The name of the second field in the output object. * - Defaults to `'label'`. * @example * // If you want the output field to be named `'title'` instead of `'label'`: * createOptionsArray(data, {firstFieldKey: 'id', secondFieldKey: 'name', firstFieldName: 'key', secondFieldName: 'title'}). */ secondFieldName?: K2; /** * - If `true`, numeric values from `firstFieldKey` will remain as numbers. * - All other values (including booleans, null, undefined) will be converted to strings. * - When `false` (default), all values are converted to strings. * - Defaults to `false`. * @example * // Numeric IDs remain as numbers * createOptionsArray(data, { * firstFieldKey: 'id', * secondFieldKey: 'name', * retainNumberValue: true * }); * * // All values become strings (default behavior) * createOptionsArray(data, { * firstFieldKey: 'id', * secondFieldKey: 'name' * }); */ retainNumberValue?: V; } /** Type for first field key */ type FirstFieldKey = T[OptionsConfig['firstFieldKey']]; /** Type for firs field value */ type FirstFieldValue = V extends true ? FirstFieldKey extends Exclude, number> ? string : number : string; /** Type of values for the option fields */ type FieldValue

= P extends K1 ? FirstFieldValue : string; /** Type of an option in `OptionsArray` */ type Option = { [P in K1 | K2]: FieldValue; }; /** * Option for sorting order. */ interface OrderOption { /** * * The order in which to sort the array. Defaults to `'asc'`. * - `'asc'`: Sort in ascending order. * - `'desc'`: Sort in descending order. */ sortOrder?: 'asc' | 'desc'; } /** * Options for setting sortByField for sorting an array of objects. */ interface SortByOption extends OrderOption { /** The field by which to sort the objects in the array. */ sortByField: NestedPrimitiveKey; } /** * Options for sorting array. */ type SortOptions = T extends GenericObject ? SortByOption : OrderOption; /** Optional settings to configure comparison behavior. */ interface SortNature { /** If true, compares string chunks without case sensitivity. Defaults to `true`. */ caseInsensitive?: boolean; /** If true, uses localeCompare for string chunk comparisons. Defaults to `false`. */ localeAware?: boolean; } /** * Options for customizing the search behavior. */ interface FindOptions { /** * Enables fuzzy matching when exact match fails. Defaults to `false`. */ fuzzy?: boolean; /** * Optional key for caching the result. Defaults to `finder-cache` */ cacheKey?: string; /** * Forces binary search even for small datasets. Defaults to `false`. */ forceBinary?: boolean; /** * If true, matcher and keys will be normalized to lowercase. Defaults to `true`. */ caseInsensitive?: boolean; /** * If true, uses built in `Array.sort()`. Defaults to `true`. Pass `false` if data is already sorted. */ needSorting?: boolean; /** * Optional data source to use instead of constructor items. */ data?: T[] | (() => T[]); } //#endregion export { Flattened as a, OrderOption as c, SortOptions as d, TypeOrArray as f, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };