@oviirup/utils 1.0.6 → 1.0.8
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/{array/index.d.ts → array.d.ts} +10 -3
- package/dist/{array/index.js → array.js} +19 -4
- package/dist/{assertions/index.d.ts → assertions.d.ts} +2 -2
- package/dist/{assertions/index.js → assertions.js} +1 -1
- package/dist/{chunk-BN_g-Awi.js → chunk-BYypO7fO.js} +3 -3
- package/dist/{clsx/index.d.ts → clsx.d.ts} +2 -2
- package/dist/{clsx/index.js → clsx.js} +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/{nanoid/index.d.ts → nanoid.d.ts} +1 -1
- package/dist/{nanoid/index.js → nanoid.js} +1 -1
- package/dist/{number/index.d.ts → number.d.ts} +4 -4
- package/dist/{number/index.js → number.js} +3 -3
- package/dist/object.d.ts +1 -1
- package/dist/object.js +3 -3
- package/dist/picocolors.d.ts +26 -0
- package/dist/picocolors.js +62 -0
- package/dist/promise.d.ts +19 -2
- package/dist/promise.js +25 -4
- package/dist/{string/casing.d.ts → string.d.ts} +16 -2
- package/dist/{string/casing.js → string.js} +36 -3
- package/dist/types.d.ts +17 -2
- package/dist/types.ts +2 -0
- package/license +21 -21
- package/package.json +14 -12
- package/dist/string/index.d.ts +0 -17
- package/dist/string/index.js +0 -30
- package/dist/types-C7M9sZlw.d.ts +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare namespace
|
|
2
|
-
export { at, first, last, move, range, toArray, toFiltered, unique };
|
|
1
|
+
declare namespace array_d_exports {
|
|
2
|
+
export { at, chunk, first, last, move, range, toArray, toFiltered, unique };
|
|
3
3
|
}
|
|
4
4
|
/**
|
|
5
5
|
* Converts a given value to represent itself in an array
|
|
@@ -58,5 +58,12 @@ declare function toFiltered<T>(array: T[], predicate: Predicate<T>): T[];
|
|
|
58
58
|
* @category Array
|
|
59
59
|
*/
|
|
60
60
|
declare function move<T>(array: T[], from: number, to: number): T[];
|
|
61
|
+
/**
|
|
62
|
+
* Chunk an array into smaller arrays of a given size
|
|
63
|
+
* @param array The array to chunk
|
|
64
|
+
* @param size The size of the chunks
|
|
65
|
+
* @category Array
|
|
66
|
+
*/
|
|
67
|
+
declare function chunk<T>(array: T[], size: number): T[][];
|
|
61
68
|
//#endregion
|
|
62
|
-
export { at, first, last, move, range,
|
|
69
|
+
export { at, chunk, first, last, move, range, array_d_exports as t, toArray, toFiltered, unique };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { t as __exportAll } from "
|
|
2
|
-
import { isEmptyArray } from "
|
|
1
|
+
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
|
+
import { isEmptyArray } from "./assertions.js";
|
|
3
3
|
|
|
4
|
-
//#region src/array
|
|
4
|
+
//#region src/array.ts
|
|
5
5
|
var array_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
at: () => at,
|
|
7
|
+
chunk: () => chunk,
|
|
7
8
|
first: () => first,
|
|
8
9
|
last: () => last,
|
|
9
10
|
move: () => move,
|
|
@@ -79,6 +80,20 @@ function move(array, from, to) {
|
|
|
79
80
|
array.splice(to, 0, item);
|
|
80
81
|
return array;
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Chunk an array into smaller arrays of a given size
|
|
85
|
+
* @param array The array to chunk
|
|
86
|
+
* @param size The size of the chunks
|
|
87
|
+
* @category Array
|
|
88
|
+
*/
|
|
89
|
+
function chunk(array, size) {
|
|
90
|
+
return array.reduce((acc, item, index) => {
|
|
91
|
+
const chunkIndex = Math.floor(index / size);
|
|
92
|
+
if (!acc[chunkIndex]) acc[chunkIndex] = [];
|
|
93
|
+
acc[chunkIndex].push(item);
|
|
94
|
+
return acc;
|
|
95
|
+
}, []);
|
|
96
|
+
}
|
|
82
97
|
|
|
83
98
|
//#endregion
|
|
84
|
-
export { at, first, last, move, range, array_exports as t, toArray, toFiltered, unique };
|
|
99
|
+
export { at, chunk, first, last, move, range, array_exports as t, toArray, toFiltered, unique };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyFunction, Dictionary, NegatePredicate, Predicate } from "./types.js";
|
|
2
2
|
|
|
3
|
-
//#region src/assertions
|
|
3
|
+
//#region src/assertions.d.ts
|
|
4
4
|
/** Check if given value is a string */
|
|
5
5
|
declare function isString(val: unknown): val is string;
|
|
6
6
|
/** Check if the given value is a number */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all,
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
5
|
for (var name in all) {
|
|
6
6
|
__defProp(target, name, {
|
|
@@ -8,7 +8,7 @@ var __exportAll = (all, symbols) => {
|
|
|
8
8
|
enumerable: true
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
if (
|
|
11
|
+
if (!no_symbols) {
|
|
12
12
|
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
13
|
}
|
|
14
14
|
return target;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isArray, isNumber, isObject, isString } from "
|
|
1
|
+
import { isArray, isNumber, isObject, isString } from "./assertions.js";
|
|
2
2
|
|
|
3
|
-
//#region src/clsx
|
|
3
|
+
//#region src/clsx.ts
|
|
4
4
|
function toClassValue(value) {
|
|
5
5
|
let names = "";
|
|
6
6
|
let temp;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not } from "./assertions
|
|
4
|
-
import { clsx } from "./clsx
|
|
5
|
-
import { charset, nanoid } from "./nanoid
|
|
6
|
-
import { t as
|
|
1
|
+
import { t as array_d_exports } from "./array.js";
|
|
2
|
+
import { ClassNameValue } from "./types.js";
|
|
3
|
+
import { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not } from "./assertions.js";
|
|
4
|
+
import { clsx } from "./clsx.js";
|
|
5
|
+
import { charset, nanoid } from "./nanoid.js";
|
|
6
|
+
import { t as number_d_exports } from "./number.js";
|
|
7
7
|
import { t as object_d_exports } from "./object.js";
|
|
8
8
|
import { t as promise_d_exports } from "./promise.js";
|
|
9
|
-
import { t as
|
|
10
|
-
export { ClassNameValue,
|
|
9
|
+
import { t as string_d_exports } from "./string.js";
|
|
10
|
+
export { ClassNameValue, array_d_exports as array, charset, clsx, isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, nanoid, not, number_d_exports as number, object_d_exports as object, promise_d_exports as promise, string_d_exports as string };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not } from "./assertions
|
|
2
|
-
import { t as array_exports } from "./array
|
|
3
|
-
import { clsx } from "./clsx
|
|
4
|
-
import { charset, nanoid } from "./nanoid
|
|
5
|
-
import { t as number_exports } from "./number
|
|
1
|
+
import { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not } from "./assertions.js";
|
|
2
|
+
import { t as array_exports } from "./array.js";
|
|
3
|
+
import { clsx } from "./clsx.js";
|
|
4
|
+
import { charset, nanoid } from "./nanoid.js";
|
|
5
|
+
import { t as number_exports } from "./number.js";
|
|
6
6
|
import { t as object_exports } from "./object.js";
|
|
7
7
|
import { t as promise_exports } from "./promise.js";
|
|
8
|
-
import { t as string_exports } from "./string
|
|
8
|
+
import { t as string_exports } from "./string.js";
|
|
9
9
|
|
|
10
10
|
export { array_exports as array, charset, clsx, isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, nanoid, not, number_exports as number, object_exports as object, promise_exports as promise, string_exports as string };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbbreviateOptions, AbbreviationSymbols } from "./types.js";
|
|
2
2
|
|
|
3
|
-
//#region src/number
|
|
4
|
-
declare namespace
|
|
3
|
+
//#region src/number.d.ts
|
|
4
|
+
declare namespace number_d_exports {
|
|
5
5
|
export { AbbreviateOptions, AbbreviationSymbols, abbreviate, clamp, inRange };
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
@@ -29,4 +29,4 @@ declare function clamp(val: number, min: number, max: number): number;
|
|
|
29
29
|
declare function abbreviate(value: number, precision?: number): string;
|
|
30
30
|
declare function abbreviate(value: number, options?: AbbreviateOptions): string;
|
|
31
31
|
//#endregion
|
|
32
|
-
export { type AbbreviateOptions, type AbbreviationSymbols, abbreviate, clamp, inRange,
|
|
32
|
+
export { type AbbreviateOptions, type AbbreviationSymbols, abbreviate, clamp, inRange, number_d_exports as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as __exportAll } from "
|
|
2
|
-
import { isNumber, isObject } from "
|
|
1
|
+
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
|
+
import { isNumber, isObject } from "./assertions.js";
|
|
3
3
|
|
|
4
|
-
//#region src/number
|
|
4
|
+
//#region src/number.ts
|
|
5
5
|
var number_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
abbreviate: () => abbreviate,
|
|
7
7
|
clamp: () => clamp,
|
package/dist/object.d.ts
CHANGED
package/dist/object.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-
|
|
2
|
-
import { isObject } from "./assertions
|
|
3
|
-
import { toArray } from "./array
|
|
1
|
+
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
|
+
import { isObject } from "./assertions.js";
|
|
3
|
+
import { toArray } from "./array.js";
|
|
4
4
|
|
|
5
5
|
//#region src/object.ts
|
|
6
6
|
var object_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/picocolors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A recreation of the picocolors library
|
|
4
|
+
*
|
|
5
|
+
* @package picocolors
|
|
6
|
+
* @version 1.1.1
|
|
7
|
+
* @repository https://github.com/alexeyraspopov/picocolors
|
|
8
|
+
*/
|
|
9
|
+
declare const pc: {
|
|
10
|
+
isEnabled: boolean;
|
|
11
|
+
reset: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
12
|
+
bold: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
13
|
+
dim: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
14
|
+
italic: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
15
|
+
underline: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
16
|
+
red: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
17
|
+
green: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
18
|
+
yellow: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
19
|
+
blue: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
20
|
+
magenta: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
21
|
+
cyan: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
22
|
+
white: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
23
|
+
gray: (input: TemplateStringsArray | string, ...args: unknown[]) => string;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { pc };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/picocolors.ts
|
|
2
|
+
/**
|
|
3
|
+
* A recreation of the picocolors library
|
|
4
|
+
*
|
|
5
|
+
* @package picocolors
|
|
6
|
+
* @version 1.1.1
|
|
7
|
+
* @repository https://github.com/alexeyraspopov/picocolors
|
|
8
|
+
*/
|
|
9
|
+
const p = process || {};
|
|
10
|
+
const argv = p.argv || [];
|
|
11
|
+
const env = p.env || {};
|
|
12
|
+
const isEnabled = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
13
|
+
/** Function wrapper to allow for both normal and tagged template usage */
|
|
14
|
+
function wrapTemplateString(cb) {
|
|
15
|
+
return function(input, ...args) {
|
|
16
|
+
if (Array.isArray(input) && "raw" in input) {
|
|
17
|
+
let str = input[0];
|
|
18
|
+
let i = 0;
|
|
19
|
+
for (const arg of args) str += String(arg) + input[++i];
|
|
20
|
+
return cb(str);
|
|
21
|
+
}
|
|
22
|
+
return cb(String(input));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function formatter(open, close, replace = open) {
|
|
26
|
+
const format = (input) => {
|
|
27
|
+
if (!isEnabled) return String(input);
|
|
28
|
+
let string = String(input);
|
|
29
|
+
let index = string.indexOf(close, open.length);
|
|
30
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
31
|
+
};
|
|
32
|
+
return wrapTemplateString(format);
|
|
33
|
+
}
|
|
34
|
+
function replaceClose(string, close, replace, index) {
|
|
35
|
+
let result = "";
|
|
36
|
+
let cursor = 0;
|
|
37
|
+
do {
|
|
38
|
+
result += string.substring(cursor, index) + replace;
|
|
39
|
+
cursor = index + close.length;
|
|
40
|
+
index = string.indexOf(close, cursor);
|
|
41
|
+
} while (~index);
|
|
42
|
+
return result + string.substring(cursor);
|
|
43
|
+
}
|
|
44
|
+
const pc = {
|
|
45
|
+
isEnabled,
|
|
46
|
+
reset: formatter("\x1B[0m", "\x1B[0m"),
|
|
47
|
+
bold: formatter("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
48
|
+
dim: formatter("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
49
|
+
italic: formatter("\x1B[3m", "\x1B[23m"),
|
|
50
|
+
underline: formatter("\x1B[4m", "\x1B[24m"),
|
|
51
|
+
red: formatter("\x1B[31m", "\x1B[39m"),
|
|
52
|
+
green: formatter("\x1B[32m", "\x1B[39m"),
|
|
53
|
+
yellow: formatter("\x1B[33m", "\x1B[39m"),
|
|
54
|
+
blue: formatter("\x1B[34m", "\x1B[39m"),
|
|
55
|
+
magenta: formatter("\x1B[35m", "\x1B[39m"),
|
|
56
|
+
cyan: formatter("\x1B[36m", "\x1B[39m"),
|
|
57
|
+
white: formatter("\x1B[37m", "\x1B[39m"),
|
|
58
|
+
gray: formatter("\x1B[90m", "\x1B[39m")
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { pc };
|
package/dist/promise.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { MaybePromise } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/promise.d.ts
|
|
1
4
|
declare namespace promise_d_exports {
|
|
2
|
-
export { retry, sleep };
|
|
5
|
+
export { retry, sleep, tryCatch };
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Delays execution for a specified number of milliseconds
|
|
9
|
+
* @param delay The delay in milliseconds (must be a positive finite number)
|
|
10
|
+
* @returns A promise that resolves after the specified delay
|
|
11
|
+
* @category promise
|
|
12
|
+
*/
|
|
4
13
|
declare function sleep(delay: number): Promise<void>;
|
|
5
14
|
/**
|
|
6
15
|
* Retries a function until it succeeds or the maximum number of retries is reached
|
|
@@ -8,7 +17,15 @@ declare function sleep(delay: number): Promise<void>;
|
|
|
8
17
|
* @param retries The number of retries
|
|
9
18
|
* @param delay The delay between retries (optional)
|
|
10
19
|
* @returns The result of the function
|
|
20
|
+
* @category promise
|
|
11
21
|
*/
|
|
12
22
|
declare function retry<T>(func: () => Promise<T>, retries: number, delay?: number): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Wraps a promise or function and returns a result object with discriminated union
|
|
25
|
+
* @param input A promise or function that returns a promise/value
|
|
26
|
+
* @returns A tuple [value, error] where value is the result or null, and error is undefined or the error
|
|
27
|
+
* @category promise
|
|
28
|
+
*/
|
|
29
|
+
declare function tryCatch<T, E = Error>(input: Promise<T> | (() => MaybePromise<T>)): Promise<readonly [Awaited<T>, undefined] | readonly [null, E]>;
|
|
13
30
|
//#endregion
|
|
14
|
-
export { retry, sleep, promise_d_exports as t };
|
|
31
|
+
export { retry, sleep, promise_d_exports as t, tryCatch };
|
package/dist/promise.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-
|
|
2
|
-
import { isNumber } from "./assertions
|
|
1
|
+
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
|
+
import { isNumber } from "./assertions.js";
|
|
3
3
|
|
|
4
4
|
//#region src/promise.ts
|
|
5
5
|
var promise_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
retry: () => retry,
|
|
7
|
-
sleep: () => sleep
|
|
7
|
+
sleep: () => sleep,
|
|
8
|
+
tryCatch: () => tryCatch
|
|
8
9
|
});
|
|
10
|
+
/**
|
|
11
|
+
* Delays execution for a specified number of milliseconds
|
|
12
|
+
* @param delay The delay in milliseconds (must be a positive finite number)
|
|
13
|
+
* @returns A promise that resolves after the specified delay
|
|
14
|
+
* @category promise
|
|
15
|
+
*/
|
|
9
16
|
function sleep(delay) {
|
|
10
17
|
if (!isNumber(delay)) throw new TypeError("sleep: delay must be a number");
|
|
11
18
|
else if (!Number.isFinite(delay) || delay < 0) throw new RangeError("sleep: delay must be a positive finite number");
|
|
@@ -18,6 +25,7 @@ function sleep(delay) {
|
|
|
18
25
|
* @param retries The number of retries
|
|
19
26
|
* @param delay The delay between retries (optional)
|
|
20
27
|
* @returns The result of the function
|
|
28
|
+
* @category promise
|
|
21
29
|
*/
|
|
22
30
|
async function retry(func, retries, delay = 0) {
|
|
23
31
|
try {
|
|
@@ -30,6 +38,19 @@ async function retry(func, retries, delay = 0) {
|
|
|
30
38
|
throw error;
|
|
31
39
|
}
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Wraps a promise or function and returns a result object with discriminated union
|
|
43
|
+
* @param input A promise or function that returns a promise/value
|
|
44
|
+
* @returns A tuple [value, error] where value is the result or null, and error is undefined or the error
|
|
45
|
+
* @category promise
|
|
46
|
+
*/
|
|
47
|
+
async function tryCatch(input) {
|
|
48
|
+
try {
|
|
49
|
+
return [typeof input === "function" ? await input() : await input, void 0];
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return [null, error];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
33
54
|
|
|
34
55
|
//#endregion
|
|
35
|
-
export { retry, sleep, promise_exports as t };
|
|
56
|
+
export { retry, sleep, promise_exports as t, tryCatch };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
declare namespace string_d_exports {
|
|
2
|
+
export { slash, toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase, truncate };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Replace backslash to slash
|
|
6
|
+
* @category String
|
|
7
|
+
*/
|
|
8
|
+
declare function slash(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Truncates a string to the specified length, adding "..." if it was longer.
|
|
11
|
+
* @param text The string to truncate
|
|
12
|
+
* @param length Maximum allowed length before truncation (default: 80)
|
|
13
|
+
* @category String
|
|
14
|
+
*/
|
|
15
|
+
declare function truncate(input: string, length?: number): string;
|
|
2
16
|
/**
|
|
3
17
|
* Converts a string to `camelCase`
|
|
4
18
|
* @param str The string to convert
|
|
@@ -42,4 +56,4 @@ declare function toSentenceCase(str: string): string;
|
|
|
42
56
|
*/
|
|
43
57
|
declare function toTitleCase(str: string): string;
|
|
44
58
|
//#endregion
|
|
45
|
-
export { toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase };
|
|
59
|
+
export { slash, string_d_exports as t, toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase, truncate };
|
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
|
+
import { isEmpty } from "./assertions.js";
|
|
2
3
|
|
|
3
|
-
//#region src/string
|
|
4
|
+
//#region src/string.ts
|
|
5
|
+
var string_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
slash: () => slash,
|
|
7
|
+
toCamelCase: () => toCamelCase,
|
|
8
|
+
toKebabCase: () => toKebabCase,
|
|
9
|
+
toPascalCase: () => toPascalCase,
|
|
10
|
+
toSentenceCase: () => toSentenceCase,
|
|
11
|
+
toSnakeCase: () => toSnakeCase,
|
|
12
|
+
toTitleCase: () => toTitleCase,
|
|
13
|
+
truncate: () => truncate
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Replace backslash to slash
|
|
17
|
+
* @category String
|
|
18
|
+
*/
|
|
19
|
+
function slash(str) {
|
|
20
|
+
return str.replace(/\\/g, "/");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Truncates a string to the specified length, adding "..." if it was longer.
|
|
24
|
+
* @param text The string to truncate
|
|
25
|
+
* @param length Maximum allowed length before truncation (default: 80)
|
|
26
|
+
* @category String
|
|
27
|
+
*/
|
|
28
|
+
function truncate(input, length = 80) {
|
|
29
|
+
if (!input) return input;
|
|
30
|
+
const text = input.trim();
|
|
31
|
+
const maxLength = Math.max(3, length);
|
|
32
|
+
if (text.length <= maxLength) return text;
|
|
33
|
+
return `${text.slice(0, maxLength - 3)}...`;
|
|
34
|
+
}
|
|
4
35
|
const reWords = /\p{Lu}?\p{Ll}+(?:[''](?:d|ll|m|re|s|t|ve))?(?=[\p{Z}\p{P}\p{S}_-]|\p{Lu}|$)|(?:\p{Lu}|[^\p{Z}\p{N}\p{Emoji_Presentation}\p{L}_-])+(?:[''](?:D|LL|M|RE|S|T|VE))?(?=[\p{Z}\p{P}\p{S}_-]|\p{Lu}(?:\p{Ll}|[^\p{Z}\p{N}\p{Emoji_Presentation}\p{L}_-])|$)|(?:\p{Lu}?[\p{Ll}\p{L}]+(?:[''](?:d|ll|m|re|s|t|ve))?|\p{Lu}+(?:[''](?:D|LL|M|RE|S|T|VE))?|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|\p{Lu})|\d+|\p{Emoji}+)/gu;
|
|
5
36
|
/**
|
|
6
37
|
* Splits a string into an array of words using Unicode-aware matching.
|
|
38
|
+
* @internal
|
|
7
39
|
* @param str The input string to split into words.
|
|
8
40
|
* @returns An array of words found in the input string.
|
|
9
41
|
*/
|
|
@@ -12,6 +44,7 @@ function words(str) {
|
|
|
12
44
|
}
|
|
13
45
|
/**
|
|
14
46
|
* Joins the words in a string with the specified delimiter and converts the result to lowercase.
|
|
47
|
+
* @internal
|
|
15
48
|
* @param str The input string to split into words and join.
|
|
16
49
|
* @param d The delimiter to use when joining the words.
|
|
17
50
|
* @returns The joined string in lowercase.
|
|
@@ -89,4 +122,4 @@ function toTitleCase(str) {
|
|
|
89
122
|
}
|
|
90
123
|
|
|
91
124
|
//#endregion
|
|
92
|
-
export { toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase };
|
|
125
|
+
export { slash, string_exports as t, toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase, truncate };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type Dictionary<T = any> = Record<string, T>;
|
|
3
|
+
type AnyFunction<T = any> = (...args: any[]) => T;
|
|
4
|
+
type ClassValue = string | number | bigint | null | boolean | undefined;
|
|
5
|
+
type ClassArray = ClassValue[];
|
|
6
|
+
type ClassRecord = Record<string, any>;
|
|
7
|
+
type ClassNameValue = ClassValue | ClassArray | ClassRecord;
|
|
8
|
+
type AbbreviationSymbols = Dictionary<number> | string[];
|
|
9
|
+
type AbbreviateOptions = {
|
|
10
|
+
symbols?: AbbreviationSymbols;
|
|
11
|
+
precision?: number;
|
|
12
|
+
};
|
|
13
|
+
type Predicate = ((val: unknown) => boolean) | ((val: unknown) => val is unknown);
|
|
14
|
+
type NegatePredicate<T> = T extends ((val: unknown) => val is infer U) ? <V>(val: V) => val is Exclude<V, U> : T extends ((val: unknown) => boolean) ? (val: unknown) => boolean : never;
|
|
15
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AbbreviateOptions, AbbreviationSymbols, AnyFunction, ClassNameValue, Dictionary, MaybePromise, NegatePredicate, Predicate };
|
package/dist/types.ts
CHANGED
package/license
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Avirup Ghosh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Avirup Ghosh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oviirup/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Collection of common JavaScript / TypeScript utilities bt @oviirup",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/oviirup/utils",
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.js",
|
|
11
|
-
"./array": "./dist/array
|
|
12
|
-
"./assertions": "./dist/assertions
|
|
13
|
-
"./clsx": "./dist/clsx
|
|
14
|
-
"./nanoid": "./dist/nanoid
|
|
15
|
-
"./number": "./dist/number
|
|
11
|
+
"./array": "./dist/array.js",
|
|
12
|
+
"./assertions": "./dist/assertions.js",
|
|
13
|
+
"./clsx": "./dist/clsx.js",
|
|
14
|
+
"./nanoid": "./dist/nanoid.js",
|
|
15
|
+
"./number": "./dist/number.js",
|
|
16
16
|
"./object": "./dist/object.js",
|
|
17
|
+
"./picocolors": "./dist/picocolors.js",
|
|
17
18
|
"./promise": "./dist/promise.js",
|
|
18
|
-
"./string": "./dist/string
|
|
19
|
-
"./string/casing": "./dist/string/casing.js",
|
|
19
|
+
"./string": "./dist/string.js",
|
|
20
20
|
"./types": "./dist/types.js",
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
@@ -29,10 +29,12 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@biomejs/biome": "^2.
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"
|
|
32
|
+
"@biomejs/biome": "^2.4.8",
|
|
33
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
34
|
+
"@changesets/cli": "^2.30.0",
|
|
35
|
+
"@types/bun": "^1.3.11",
|
|
36
|
+
"lefthook": "^2.1.4",
|
|
37
|
+
"tsdown": "^0.20.3",
|
|
36
38
|
"typescript": "^5.9.3"
|
|
37
39
|
},
|
|
38
40
|
"publishConfig": {
|
package/dist/string/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare namespace index_d_exports {
|
|
2
|
-
export { slash, truncate };
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Replace backslash to slash
|
|
6
|
-
* @category String
|
|
7
|
-
*/
|
|
8
|
-
declare function slash(str: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* Truncates a string to the specified length, adding "..." if it was longer.
|
|
11
|
-
* @param text The string to truncate
|
|
12
|
-
* @param length Maximum allowed length before truncation (default: 80)
|
|
13
|
-
* @category String
|
|
14
|
-
*/
|
|
15
|
-
declare function truncate(input: string, length?: number): string;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { slash, index_d_exports as t, truncate };
|
package/dist/string/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "../chunk-BN_g-Awi.js";
|
|
2
|
-
|
|
3
|
-
//#region src/string/index.ts
|
|
4
|
-
var string_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
-
slash: () => slash,
|
|
6
|
-
truncate: () => truncate
|
|
7
|
-
});
|
|
8
|
-
/**
|
|
9
|
-
* Replace backslash to slash
|
|
10
|
-
* @category String
|
|
11
|
-
*/
|
|
12
|
-
function slash(str) {
|
|
13
|
-
return str.replace(/\\/g, "/");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Truncates a string to the specified length, adding "..." if it was longer.
|
|
17
|
-
* @param text The string to truncate
|
|
18
|
-
* @param length Maximum allowed length before truncation (default: 80)
|
|
19
|
-
* @category String
|
|
20
|
-
*/
|
|
21
|
-
function truncate(input, length = 80) {
|
|
22
|
-
if (!input) return input;
|
|
23
|
-
const text = input.trim();
|
|
24
|
-
const maxLength = Math.max(3, length);
|
|
25
|
-
if (text.length <= maxLength) return text;
|
|
26
|
-
return `${text.slice(0, maxLength - 3)}...`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { slash, string_exports as t, truncate };
|
package/dist/types-C7M9sZlw.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
|
-
type Dictionary<T = any> = Record<string, T>;
|
|
3
|
-
type AnyFunction<T = any> = (...args: any[]) => T;
|
|
4
|
-
type ClassValue = string | number | bigint | null | boolean | undefined;
|
|
5
|
-
type ClassArray = ClassValue[];
|
|
6
|
-
type ClassRecord = Record<string, any>;
|
|
7
|
-
type ClassNameValue = ClassValue | ClassArray | ClassRecord;
|
|
8
|
-
type AbbreviationSymbols = Dictionary<number> | string[];
|
|
9
|
-
type AbbreviateOptions = {
|
|
10
|
-
symbols?: AbbreviationSymbols;
|
|
11
|
-
precision?: number;
|
|
12
|
-
};
|
|
13
|
-
type Predicate = ((val: unknown) => boolean) | ((val: unknown) => val is unknown);
|
|
14
|
-
type NegatePredicate<T> = T extends ((val: unknown) => val is infer U) ? <V>(val: V) => val is Exclude<V, U> : T extends ((val: unknown) => boolean) ? (val: unknown) => boolean : never;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { Dictionary as a, ClassNameValue as i, AbbreviationSymbols as n, NegatePredicate as o, AnyFunction as r, Predicate as s, AbbreviateOptions as t };
|