@h3ravel/support 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -46,7 +46,7 @@ type KeysToSnakeCase<T> = {
46
46
  * @param size - Size of each chunk (default: 2)
47
47
  * @returns An array of chunks (arrays)
48
48
  */
49
- declare const chunk: <T>(arr: T[], size?: number) => T[][];
49
+ declare const chunk: <T>(arr: T[], size?: number) => T[][]
50
50
  /**
51
51
  * Generates an array of sequential numbers.
52
52
  *
@@ -54,7 +54,7 @@ declare const chunk: <T>(arr: T[], size?: number) => T[][];
54
54
  * @param startAt - Starting number (default: 0)
55
55
  * @returns An array of numbers from startAt to startAt + size - 1
56
56
  */
57
- declare const range: (size: number, startAt?: number) => number[];
57
+ declare const range: (size: number, startAt?: number) => number[]
58
58
 
59
59
  /**
60
60
  * Abbreviates large numbers using SI symbols (K, M, B...)
@@ -64,7 +64,7 @@ declare const range: (size: number, startAt?: number) => number[];
64
64
  * @param locale - Optional locale string (default: "en-US")
65
65
  * @returns A localized, abbreviated number string
66
66
  */
67
- declare const abbreviate: (value?: number, locale?: string) => string;
67
+ declare const abbreviate: (value?: number, locale?: string) => string
68
68
  /**
69
69
  * Concverts a number into human readable string
70
70
  *
@@ -72,7 +72,7 @@ declare const abbreviate: (value?: number, locale?: string) => string;
72
72
  * @param slugify convert the ouput into a slug using this as a separator
73
73
  * @returns
74
74
  */
75
- declare const humanize: (num: number, slugify?: "-" | "_") => string;
75
+ declare const humanize: (num: number, slugify?: '-' | '_') => string
76
76
  /**
77
77
  * Converts a number of bytes into a human-readable string.
78
78
  *
@@ -82,7 +82,7 @@ declare const humanize: (num: number, slugify?: "-" | "_") => string;
82
82
  * otherwise uses 1024-based binary units (Bytes, KiB...)
83
83
  * @returns A formatted string with the appropriate unit
84
84
  */
85
- declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string;
85
+ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string
86
86
  /**
87
87
  * Formats a duration (in seconds) into a human-readable string.
88
88
  *
@@ -91,7 +91,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
91
91
  * otherwise HH:MM:SS (e.g., "01:02:03")
92
92
  * @returns A formatted time string
93
93
  */
94
- declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
94
+ declare const toHumanTime: (seconds?: number, worded?: boolean) => string
95
95
 
96
96
  /**
97
97
  * Flattens a nested object into a single-level object
@@ -114,7 +114,7 @@ declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
114
114
  * @param obj - The nested object to flatten
115
115
  * @returns A flattened object with dotted keys and inferred types
116
116
  */
117
- declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
117
+ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>
118
118
  /**
119
119
  * Extracts a subset of properties from an object.
120
120
  *
@@ -124,7 +124,7 @@ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
124
124
  * @param keys - Array of keys to extract
125
125
  * @returns A new object with only the specified keys
126
126
  */
127
- declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>;
127
+ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>
128
128
  /**
129
129
  * Safely retrieves a value from an object by key or nested keys.
130
130
  *
@@ -133,7 +133,7 @@ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, k
133
133
  * @param item - The source object
134
134
  * @returns The found value as a string or the key itself if not found
135
135
  */
136
- declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string;
136
+ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string
137
137
  /**
138
138
  * Maps over an object's entries and returns a new object
139
139
  * with transformed keys and/or values.
@@ -144,7 +144,7 @@ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T,
144
144
  * @param callback - Function that receives [key, value] and returns [newKey, newValue]
145
145
  * @returns A new object with transformed entries
146
146
  */
147
- declare const modObj: <T extends object, R>(obj: T, callback: (entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>;
147
+ declare const modObj: <T extends object, R>(obj: T, callback: (entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>
148
148
  declare function safeDot<T extends Record<string, any>>(data: T): T;
149
149
  declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(data: T, key?: K): DotNestedValue<T, K>;
150
150
  /**
@@ -160,7 +160,7 @@ declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<
160
160
  * @param key - The dot-separated key (e.g., 'app.user.name').
161
161
  * @param value - The value to set at the specified path.
162
162
  */
163
- declare const setNested: (obj: Record<string, any>, key: string, value: any) => void;
163
+ declare const setNested: (obj: Record<string, any>, key: string, value: any) => void
164
164
  /**
165
165
  * Converts object keys to a slugified format (e.g., snake_case).
166
166
  *
@@ -170,7 +170,7 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
170
170
  * @param separator - Separator for slugified keys (default: "_")
171
171
  * @returns A new object with slugified keys
172
172
  */
173
- declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
173
+ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>
174
174
 
175
175
  /**
176
176
  * Get the portion of the string after the first occurrence of the given value.
@@ -179,7 +179,7 @@ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator
179
179
  * @param search
180
180
  * @returns
181
181
  */
182
- declare const after: (value: string, search: string) => string;
182
+ declare const after: (value: string, search: string) => string
183
183
  /**
184
184
  * Get the portion of the string after the last occurrence of the given value.
185
185
  *
@@ -187,7 +187,7 @@ declare const after: (value: string, search: string) => string;
187
187
  * @param search
188
188
  * @returns
189
189
  */
190
- declare const afterLast: (value: string, search: string) => string;
190
+ declare const afterLast: (value: string, search: string) => string
191
191
  /**
192
192
  * Get the portion of the string before the first occurrence of the given value.
193
193
  *
@@ -195,7 +195,7 @@ declare const afterLast: (value: string, search: string) => string;
195
195
  * @param search
196
196
  * @returns
197
197
  */
198
- declare const before: (value: string, search: string) => string;
198
+ declare const before: (value: string, search: string) => string
199
199
  /**
200
200
  * Get the portion of the string before the last occurrence of the given value.
201
201
  *
@@ -203,7 +203,7 @@ declare const before: (value: string, search: string) => string;
203
203
  * @param search
204
204
  * @returns
205
205
  */
206
- declare const beforeLast: (value: string, search: string) => string;
206
+ declare const beforeLast: (value: string, search: string) => string
207
207
  /**
208
208
  * Capitalizes the first character of a string.
209
209
  *
@@ -218,14 +218,14 @@ declare function capitalize(str: string): string;
218
218
  * @param count - The number determining pluralization
219
219
  * @returns Singular if count === 1, otherwise plural form
220
220
  */
221
- declare const pluralize: (word: string, count: number) => string;
221
+ declare const pluralize: (word: string, count: number) => string
222
222
  /**
223
223
  * Converts a plural English word into its singular form.
224
224
  *
225
225
  * @param word - The word to singularize
226
226
  * @returns The singular form of the word
227
227
  */
228
- declare const singularize: (word: string) => string;
228
+ declare const singularize: (word: string) => string
229
229
  /**
230
230
  * Converts a string into a slug format.
231
231
  * Handles camelCase, spaces, and non-alphanumeric characters.
@@ -234,7 +234,7 @@ declare const singularize: (word: string) => string;
234
234
  * @param joiner - The character used to join words (default: "_")
235
235
  * @returns A slugified string
236
236
  */
237
- declare const slugify: (str: string, joiner?: string) => string;
237
+ declare const slugify: (str: string, joiner?: string) => string
238
238
  /**
239
239
  * Truncates a string to a specified length and appends an ellipsis if needed.
240
240
  *
@@ -243,7 +243,7 @@ declare const slugify: (str: string, joiner?: string) => string;
243
243
  * @param ellipsis - String to append if truncated (default: "...")
244
244
  * @returns The truncated string
245
245
  */
246
- declare const subString: (str: string, len: number, ellipsis?: string) => string;
246
+ declare const subString: (str: string, len: number, ellipsis?: string) => string
247
247
  /**
248
248
  * Replaces placeholders in a string with corresponding values from a data object.
249
249
  *
@@ -256,7 +256,7 @@ declare const subString: (str: string, len: number, ellipsis?: string) => string
256
256
  * @param def - Default value to use if a key is missing. (Optional)
257
257
  * @returns The substituted string or undefined if the input string or data is invalid.
258
258
  */
259
- declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined;
259
+ declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined
260
260
  /**
261
261
  * Truncates a string to a specified length, removing HTML tags and
262
262
  * appending a suffix if the string exceeds the length.
@@ -266,6 +266,6 @@ declare const substitute: (str: string, data?: Record<string, unknown>, def?: st
266
266
  * @param suffix - Suffix to append if truncated (default: "...")
267
267
  * @returns The truncated string
268
268
  */
269
- declare const truncate: (str: string, len?: number, suffix?: string) => string;
269
+ declare const truncate: (str: string, len?: number, suffix?: string) => string
270
270
 
271
- export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate };
271
+ export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate }
package/dist/index.d.ts CHANGED
@@ -46,7 +46,7 @@ type KeysToSnakeCase<T> = {
46
46
  * @param size - Size of each chunk (default: 2)
47
47
  * @returns An array of chunks (arrays)
48
48
  */
49
- declare const chunk: <T>(arr: T[], size?: number) => T[][];
49
+ declare const chunk: <T>(arr: T[], size?: number) => T[][]
50
50
  /**
51
51
  * Generates an array of sequential numbers.
52
52
  *
@@ -54,7 +54,7 @@ declare const chunk: <T>(arr: T[], size?: number) => T[][];
54
54
  * @param startAt - Starting number (default: 0)
55
55
  * @returns An array of numbers from startAt to startAt + size - 1
56
56
  */
57
- declare const range: (size: number, startAt?: number) => number[];
57
+ declare const range: (size: number, startAt?: number) => number[]
58
58
 
59
59
  /**
60
60
  * Abbreviates large numbers using SI symbols (K, M, B...)
@@ -64,7 +64,7 @@ declare const range: (size: number, startAt?: number) => number[];
64
64
  * @param locale - Optional locale string (default: "en-US")
65
65
  * @returns A localized, abbreviated number string
66
66
  */
67
- declare const abbreviate: (value?: number, locale?: string) => string;
67
+ declare const abbreviate: (value?: number, locale?: string) => string
68
68
  /**
69
69
  * Concverts a number into human readable string
70
70
  *
@@ -72,7 +72,7 @@ declare const abbreviate: (value?: number, locale?: string) => string;
72
72
  * @param slugify convert the ouput into a slug using this as a separator
73
73
  * @returns
74
74
  */
75
- declare const humanize: (num: number, slugify?: "-" | "_") => string;
75
+ declare const humanize: (num: number, slugify?: '-' | '_') => string
76
76
  /**
77
77
  * Converts a number of bytes into a human-readable string.
78
78
  *
@@ -82,7 +82,7 @@ declare const humanize: (num: number, slugify?: "-" | "_") => string;
82
82
  * otherwise uses 1024-based binary units (Bytes, KiB...)
83
83
  * @returns A formatted string with the appropriate unit
84
84
  */
85
- declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string;
85
+ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string
86
86
  /**
87
87
  * Formats a duration (in seconds) into a human-readable string.
88
88
  *
@@ -91,7 +91,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
91
91
  * otherwise HH:MM:SS (e.g., "01:02:03")
92
92
  * @returns A formatted time string
93
93
  */
94
- declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
94
+ declare const toHumanTime: (seconds?: number, worded?: boolean) => string
95
95
 
96
96
  /**
97
97
  * Flattens a nested object into a single-level object
@@ -114,7 +114,7 @@ declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
114
114
  * @param obj - The nested object to flatten
115
115
  * @returns A flattened object with dotted keys and inferred types
116
116
  */
117
- declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
117
+ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>
118
118
  /**
119
119
  * Extracts a subset of properties from an object.
120
120
  *
@@ -124,7 +124,7 @@ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
124
124
  * @param keys - Array of keys to extract
125
125
  * @returns A new object with only the specified keys
126
126
  */
127
- declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>;
127
+ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>
128
128
  /**
129
129
  * Safely retrieves a value from an object by key or nested keys.
130
130
  *
@@ -133,7 +133,7 @@ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, k
133
133
  * @param item - The source object
134
134
  * @returns The found value as a string or the key itself if not found
135
135
  */
136
- declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string;
136
+ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string
137
137
  /**
138
138
  * Maps over an object's entries and returns a new object
139
139
  * with transformed keys and/or values.
@@ -144,7 +144,7 @@ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T,
144
144
  * @param callback - Function that receives [key, value] and returns [newKey, newValue]
145
145
  * @returns A new object with transformed entries
146
146
  */
147
- declare const modObj: <T extends object, R>(obj: T, callback: (entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>;
147
+ declare const modObj: <T extends object, R>(obj: T, callback: (entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>
148
148
  declare function safeDot<T extends Record<string, any>>(data: T): T;
149
149
  declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(data: T, key?: K): DotNestedValue<T, K>;
150
150
  /**
@@ -160,7 +160,7 @@ declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<
160
160
  * @param key - The dot-separated key (e.g., 'app.user.name').
161
161
  * @param value - The value to set at the specified path.
162
162
  */
163
- declare const setNested: (obj: Record<string, any>, key: string, value: any) => void;
163
+ declare const setNested: (obj: Record<string, any>, key: string, value: any) => void
164
164
  /**
165
165
  * Converts object keys to a slugified format (e.g., snake_case).
166
166
  *
@@ -170,7 +170,7 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
170
170
  * @param separator - Separator for slugified keys (default: "_")
171
171
  * @returns A new object with slugified keys
172
172
  */
173
- declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
173
+ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>
174
174
 
175
175
  /**
176
176
  * Get the portion of the string after the first occurrence of the given value.
@@ -179,7 +179,7 @@ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator
179
179
  * @param search
180
180
  * @returns
181
181
  */
182
- declare const after: (value: string, search: string) => string;
182
+ declare const after: (value: string, search: string) => string
183
183
  /**
184
184
  * Get the portion of the string after the last occurrence of the given value.
185
185
  *
@@ -187,7 +187,7 @@ declare const after: (value: string, search: string) => string;
187
187
  * @param search
188
188
  * @returns
189
189
  */
190
- declare const afterLast: (value: string, search: string) => string;
190
+ declare const afterLast: (value: string, search: string) => string
191
191
  /**
192
192
  * Get the portion of the string before the first occurrence of the given value.
193
193
  *
@@ -195,7 +195,7 @@ declare const afterLast: (value: string, search: string) => string;
195
195
  * @param search
196
196
  * @returns
197
197
  */
198
- declare const before: (value: string, search: string) => string;
198
+ declare const before: (value: string, search: string) => string
199
199
  /**
200
200
  * Get the portion of the string before the last occurrence of the given value.
201
201
  *
@@ -203,7 +203,7 @@ declare const before: (value: string, search: string) => string;
203
203
  * @param search
204
204
  * @returns
205
205
  */
206
- declare const beforeLast: (value: string, search: string) => string;
206
+ declare const beforeLast: (value: string, search: string) => string
207
207
  /**
208
208
  * Capitalizes the first character of a string.
209
209
  *
@@ -218,14 +218,14 @@ declare function capitalize(str: string): string;
218
218
  * @param count - The number determining pluralization
219
219
  * @returns Singular if count === 1, otherwise plural form
220
220
  */
221
- declare const pluralize: (word: string, count: number) => string;
221
+ declare const pluralize: (word: string, count: number) => string
222
222
  /**
223
223
  * Converts a plural English word into its singular form.
224
224
  *
225
225
  * @param word - The word to singularize
226
226
  * @returns The singular form of the word
227
227
  */
228
- declare const singularize: (word: string) => string;
228
+ declare const singularize: (word: string) => string
229
229
  /**
230
230
  * Converts a string into a slug format.
231
231
  * Handles camelCase, spaces, and non-alphanumeric characters.
@@ -234,7 +234,7 @@ declare const singularize: (word: string) => string;
234
234
  * @param joiner - The character used to join words (default: "_")
235
235
  * @returns A slugified string
236
236
  */
237
- declare const slugify: (str: string, joiner?: string) => string;
237
+ declare const slugify: (str: string, joiner?: string) => string
238
238
  /**
239
239
  * Truncates a string to a specified length and appends an ellipsis if needed.
240
240
  *
@@ -243,7 +243,7 @@ declare const slugify: (str: string, joiner?: string) => string;
243
243
  * @param ellipsis - String to append if truncated (default: "...")
244
244
  * @returns The truncated string
245
245
  */
246
- declare const subString: (str: string, len: number, ellipsis?: string) => string;
246
+ declare const subString: (str: string, len: number, ellipsis?: string) => string
247
247
  /**
248
248
  * Replaces placeholders in a string with corresponding values from a data object.
249
249
  *
@@ -256,7 +256,7 @@ declare const subString: (str: string, len: number, ellipsis?: string) => string
256
256
  * @param def - Default value to use if a key is missing. (Optional)
257
257
  * @returns The substituted string or undefined if the input string or data is invalid.
258
258
  */
259
- declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined;
259
+ declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined
260
260
  /**
261
261
  * Truncates a string to a specified length, removing HTML tags and
262
262
  * appending a suffix if the string exceeds the length.
@@ -266,6 +266,6 @@ declare const substitute: (str: string, data?: Record<string, unknown>, def?: st
266
266
  * @param suffix - Suffix to append if truncated (default: "...")
267
267
  * @returns The truncated string
268
268
  */
269
- declare const truncate: (str: string, len?: number, suffix?: string) => string;
269
+ declare const truncate: (str: string, len?: number, suffix?: string) => string
270
270
 
271
- export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate };
271
+ export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate }