File size: 8,565 Bytes
391a73c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
 * Applies a function to the value at the given index of an array
 *
 * @param index
 * @param fn
 * @param collection
 * @returns Copy of the array with the element at the given index replaced with the result of the function application.
 */
declare const adjust: <T>(index: number, fn: (value: T) => T, collection: T[]) => T[];

type Fn$1 = (arg: any, ...args: any[]) => Promise<any> | any;
type ComposedInput$1<T extends Fn$1[]> = T extends [
    ...any,
    (arg: infer A, ...args: any[]) => Promise<any> | any
] ? A : never;
type ComposedOutput$1<T extends Fn$1[]> = T extends [
    (arg: any, ...args: any[]) => Promise<infer R> | infer R,
    ...any
] ? R : never;
/**
 * Performs right-to-left function composition with async functions support.
 * asyncCompose(f, g, h)(x) is equivalent to f(g(h(x))), awaiting each result.
 *
 * @param fns - Functions to compose (can be sync or async)
 * @returns Composed async function that applies functions from right to left
 */
declare const asyncCompose: <T extends Fn$1[]>(...fns: T) => (value: ComposedInput$1<T>, ...args: Parameters<T[0]> extends [any, ...infer Rest] ? Rest : []) => Promise<ComposedOutput$1<T>>;

/**
 * Capitalize first letter of each word
 *
 * @param value - Any string
 * @returns Capitalized string
 */
declare const capitalize: (value?: string | null) => string | null | undefined;

/**
 * Casts value to array
 *
 * @template T - The type of the value.
 * @param value - The value to cast into an array.
 * @returns The value as-is if already an array, otherwise wrapped in an array.
 */
declare const castArray: <T>(value: T | T[]) => T[];

type Fn = (arg: any, ...args: any[]) => any;
type ComposedInput<T extends Fn[]> = T extends [
    ...any,
    (arg: infer A, ...args: any[]) => any
] ? A : never;
type ComposedOutput<T extends Fn[]> = T extends [
    (arg: any, ...args: any[]) => infer R,
    ...any
] ? R : never;
/**
 * Performs right-to-left function composition.
 * compose(f, g, h)(x) is equivalent to f(g(h(x)))
 *
 * @param fns - Functions to compose
 * @returns Composed function that applies functions from right to left
 */
declare const compose: <T extends Fn[]>(...fns: T) => (value: ComposedInput<T>, ...args: any[]) => ComposedOutput<T>;

/**
 * Drops the last element from an array or string.
 *
 * @param value - The array or string to drop the last element from
 * @returns A new array or string with the last element removed
 */
declare function dropLast(value: string): string;
declare function dropLast<T>(value: T[]): T[];

/**
 * Applies a set of transformations to an object and returns a new object with the transformed values.
 *
 * @example
 * evolve({ count: (n) => n + 1 }, { name: 'item', count: 5 })
 * // => { name: 'item', count: 6 }
 *
 * @param transformations - The transformations to apply
 * @param object - The object to transform
 * @returns The transformed object
 */
declare function evolve<T extends Record<string, any>>(transformations: Partial<{
    [K in keyof T]: (value: T[K]) => T[K];
}>, object: T): T;

/**
 * Retrieves the value at a given path from an object.
 *
 * @example
 * get({ a: { b: 1 } }, ['a', 'b'], 0) // => 1
 * get({ a: { b: 1 } }, ['a', 'c'], 0) // => 0
 *
 * @param target - The object to retrieve the value from
 * @param path - The path of the value to retrieve
 * @param defaultValue - The default value to return if the path does not exist
 * @returns The value at the given path, or the default value if the path does not exist
 */
declare const get: (target: any, path: (string | number)[] | string | number, defaultValue: any) => any;

/**
 * Checks if a value is null or undefined.
 *
 * @example
 * isNil(null)      // => true
 * isNil(undefined) // => true
 * isNil(0)         // => false
 *
 * @param value - The value to check
 * @returns True if the value is null or undefined, false otherwise
 */
declare const isNil: (value: unknown) => value is null | undefined;

/**
 * Returns the last element of an array or last character of a string.
 *
 * @example
 * last([1, 2, 3]) // => 3
 * last('abc')     // => 'c'
 * last([])        // => undefined
 * last('')        // => ''
 *
 * @param value - The array or string
 * @returns The last element/character, or undefined for empty arrays
 */
declare function last(value: string): string;
declare function last<T>(value: T[]): T | undefined;

type IteratorFn = (value: any, key: string, index: number) => any;
/**
 * Maps over the values of an object and applies a function to each value.
 *
 * @example
 * mapValues({ a: 1, b: 2 }, (v) => v * 2) // => { a: 2, b: 4 }
 *
 * @param object - The object to map over
 * @param fn - The function to apply to each value
 * @returns A new object with the mapped values
 */
declare const mapValues: (object: Record<string, any>, fn: IteratorFn) => Record<string, any>;

interface PercentMatch {
    percent: number;
    value: number;
}
/**
 * Parses a percentage string and returns both the numeric value and decimal percent.
 *
 * @example
 * matchPercent('50%')  // => { value: 50, percent: 0.5 }
 * matchPercent('-25%') // => { value: -25, percent: -0.25 }
 * matchPercent('abc')  // => null
 *
 * @param value - The value to parse
 * @returns Object with value and percent, or null if not a valid percentage
 */
declare const matchPercent: (value: string | number | null) => PercentMatch | null;

/**
 * Creates a new object by omitting specified keys from the original object.
 *
 * @example
 * omit('b', { a: 1, b: 2, c: 3 })      // => { a: 1, c: 3 }
 * omit(['a', 'c'], { a: 1, b: 2, c: 3 }) // => { b: 2 }
 *
 * @param keys - The key or keys to omit
 * @param object - The original object
 * @returns The new object without the omitted keys
 */
declare const omit: (keys: string | string[], object: Record<string, any>) => Record<string, any>;

/**
 * Picks the specified keys from an object and returns a new object with only those keys.
 *
 * @example
 * pick(['a', 'c'], { a: 1, b: 2, c: 3 }) // => { a: 1, c: 3 }
 * pick(['x'], { a: 1, b: 2 })            // => {}
 *
 * @param keys - The keys to pick from the object
 * @param object - The object to pick the keys from
 * @returns A new object with only the picked keys
 */
declare const pick: (keys: (string | number)[], object: Record<string, any>) => Record<string, any>;

/**
 * Repeats an element a specified number of times.
 *
 * @example
 * repeat('a', 3) // => ['a', 'a', 'a']
 * repeat(0, 4)   // => [0, 0, 0, 0]
 * repeat('x')    // => []
 *
 * @param element - Element to be repeated
 * @param length - Number of times to repeat element (default: 0)
 * @returns Array with the element repeated
 */
declare const repeat: <T>(element: T, length?: number) => T[];

/**
 * Returns a new array with elements in reverse order. Does not mutate the original.
 *
 * @example
 * reverse([1, 2, 3]) // => [3, 2, 1]
 * reverse(['a', 'b']) // => ['b', 'a']
 *
 * @param array - Array to be reversed
 * @returns New array with elements reversed
 */
declare const reverse: <T>(array: T[]) => T[];

/**
 * Converts the first character of a string to uppercase. Does not affect other characters.
 *
 * @example
 * upperFirst('hello')  // => 'Hello'
 * upperFirst('hELLO')  // => 'HELLO'
 * upperFirst('')       // => ''
 * upperFirst(null)     // => null
 *
 * @param value - The string to transform
 * @returns String with first character uppercased, or the original value if null/undefined/empty
 */
declare const upperFirst: <T extends string | null | undefined>(value: T) => T extends string ? string : T;

/**
 * Returns a new array excluding the specified values.
 *
 * @example
 * without([2, 4], [1, 2, 3, 4, 5]) // => [1, 3, 5]
 * without(['b'], ['a', 'b', 'c'])  // => ['a', 'c']
 *
 * @param exclude - Values to exclude from the array
 * @param array - Array to filter
 * @returns A new array without the excluded values
 */
declare const without: <T>(exclude: T[], array: T[]) => T[];

/**
 * Parse a string or number to a float. Non-string values pass through unchanged.
 *
 * @example
 * parseFloat('3.14')  // => 3.14
 * parseFloat(42)      // => 42
 * parseFloat('10px')  // => 10
 * parseFloat(null)    // => null
 *
 * @param value - The value to parse
 * @returns Parsed float for strings, original value otherwise
 */
declare const parseFloat: <T extends string | number | null | undefined>(value: T) => T extends string ? number : T;

export { adjust, asyncCompose, capitalize, castArray, compose, dropLast, evolve, get, isNil, last, mapValues, matchPercent, omit, parseFloat, pick, repeat, reverse, upperFirst, without };