@oviirup/utils 1.0.5 → 1.0.7

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.
Files changed (43) hide show
  1. package/dist/{array.d.ts → array/index.d.ts} +12 -2
  2. package/dist/array/index.js +99 -0
  3. package/dist/{assertions.d.ts → assertions/index.d.ts} +5 -3
  4. package/dist/assertions/index.js +64 -0
  5. package/dist/chunk-BYypO7fO.js +18 -0
  6. package/dist/{clsx.d.ts → clsx/index.d.ts} +4 -4
  7. package/dist/clsx/index.js +40 -0
  8. package/dist/index.d.ts +10 -13
  9. package/dist/index.js +10 -1
  10. package/dist/{nanoid.d.ts → nanoid/index.d.ts} +3 -2
  11. package/dist/nanoid/index.js +29 -0
  12. package/dist/{number.d.ts → number/index.d.ts} +7 -4
  13. package/dist/number/index.js +60 -0
  14. package/dist/object.d.ts +7 -3
  15. package/dist/object.js +38 -1
  16. package/dist/promise/index.d.ts +31 -0
  17. package/dist/promise/index.js +56 -0
  18. package/dist/string/casing.d.ts +45 -0
  19. package/dist/string/casing.js +92 -0
  20. package/dist/{string.d.ts → string/index.d.ts} +6 -9
  21. package/dist/string/index.js +30 -0
  22. package/dist/types.d.ts +7 -5
  23. package/dist/types.js +1 -0
  24. package/dist/types.ts +27 -0
  25. package/license +21 -21
  26. package/package.json +26 -56
  27. package/dist/array.js +0 -1
  28. package/dist/array.mjs +0 -1
  29. package/dist/assertions.js +0 -1
  30. package/dist/assertions.mjs +0 -1
  31. package/dist/clsx.js +0 -1
  32. package/dist/clsx.mjs +0 -1
  33. package/dist/index.mjs +0 -1
  34. package/dist/nanoid.js +0 -1
  35. package/dist/nanoid.mjs +0 -1
  36. package/dist/number.js +0 -1
  37. package/dist/number.mjs +0 -1
  38. package/dist/object.mjs +0 -1
  39. package/dist/promise.d.ts +0 -11
  40. package/dist/promise.js +0 -1
  41. package/dist/promise.mjs +0 -1
  42. package/dist/string.js +0 -1
  43. package/dist/string.mjs +0 -1
@@ -1,3 +1,6 @@
1
+ declare namespace index_d_exports {
2
+ export { at, chunk, first, last, move, range, toArray, toFiltered, unique };
3
+ }
1
4
  /**
2
5
  * Converts a given value to represent itself in an array
3
6
  * @param value The value to convert to an array
@@ -55,5 +58,12 @@ declare function toFiltered<T>(array: T[], predicate: Predicate<T>): T[];
55
58
  * @category Array
56
59
  */
57
60
  declare function move<T>(array: T[], from: number, to: number): T[];
58
-
59
- export { at, first, last, move, range, toArray, toFiltered, unique };
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[][];
68
+ //#endregion
69
+ export { at, chunk, first, last, move, range, index_d_exports as t, toArray, toFiltered, unique };
@@ -0,0 +1,99 @@
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
+ import { isEmptyArray } from "../assertions/index.js";
3
+
4
+ //#region src/array/index.ts
5
+ var array_exports = /* @__PURE__ */ __exportAll({
6
+ at: () => at,
7
+ chunk: () => chunk,
8
+ first: () => first,
9
+ last: () => last,
10
+ move: () => move,
11
+ range: () => range,
12
+ toArray: () => toArray,
13
+ toFiltered: () => toFiltered,
14
+ unique: () => unique
15
+ });
16
+ /**
17
+ * Converts a given value to represent itself in an array
18
+ * @param value The value to convert to an array
19
+ * @category Array
20
+ */
21
+ function toArray(array) {
22
+ array = array ?? [];
23
+ return Array.isArray(array) ? array : [array];
24
+ }
25
+ function unique(value, equals) {
26
+ if (typeof equals !== "function") return Array.from(new Set(value));
27
+ return value.reduce((acc, item) => {
28
+ if (acc.findIndex((e) => equals(e, item)) === -1) acc.push(item);
29
+ return acc;
30
+ }, []);
31
+ }
32
+ function at(array, index) {
33
+ const len = array.length;
34
+ if (!len) return void 0;
35
+ if (index < 0) index += len;
36
+ return array[index];
37
+ }
38
+ function last(array) {
39
+ return at(array, -1);
40
+ }
41
+ function first(array) {
42
+ return at(array, 0);
43
+ }
44
+ function range(...args) {
45
+ let start = 0;
46
+ let stop;
47
+ let step = 1;
48
+ if (args.length === 1) [stop] = args;
49
+ else [start, stop, step = 1] = args;
50
+ const array = [];
51
+ let current = start;
52
+ while (current < stop) {
53
+ array.push(current);
54
+ current += step;
55
+ }
56
+ return array;
57
+ }
58
+ /**
59
+ * Filter an array in place (faster than Array.filter)
60
+ * @param array The array to filter
61
+ * @param predicate The predicate function to use to filter the array
62
+ * @category Array
63
+ */
64
+ function toFiltered(array, predicate) {
65
+ for (let i = array.length - 1; i >= 0; i--) if (!predicate(array[i], i, array)) array.splice(i, 1);
66
+ return array;
67
+ }
68
+ /**
69
+ * Move an item in an array to a new position
70
+ * @param array The array to move the item in
71
+ * @param from The index of the item to move
72
+ * @param to The index to move the item to
73
+ * @category Array
74
+ */
75
+ function move(array, from, to) {
76
+ if (isEmptyArray(array)) return array;
77
+ if (from === to) return array;
78
+ const item = array[from];
79
+ array.splice(from, 1);
80
+ array.splice(to, 0, item);
81
+ return array;
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
+ }
97
+
98
+ //#endregion
99
+ export { at, chunk, first, last, move, range, array_exports as t, toArray, toFiltered, unique };
@@ -1,5 +1,6 @@
1
- import { Dictionary, AnyFunction, Predicate, NegatePredicate } from './types.js';
1
+ import { AnyFunction, Dictionary, NegatePredicate, Predicate } from "../types.js";
2
2
 
3
+ //#region src/assertions/index.d.ts
3
4
  /** Check if given value is a string */
4
5
  declare function isString(val: unknown): val is string;
5
6
  /** Check if the given value is a number */
@@ -24,8 +25,9 @@ declare function isFunction(val: any): val is AnyFunction<any>;
24
25
  declare function isRegex(val: unknown): val is RegExp;
25
26
  /** Check if the given value is truthy */
26
27
  declare function isTruthy(val: unknown): boolean;
28
+ /** Check if the code is running in a browser environment */
27
29
  declare function isBrowser(): boolean;
28
30
  /** Negate an assertion function, returning a new function with the opposite boolean result */
29
31
  declare function not<T extends Predicate>(fn: T): NegatePredicate<T>;
30
-
31
- export { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not };
32
+ //#endregion
33
+ export { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not };
@@ -0,0 +1,64 @@
1
+ //#region src/assertions/index.ts
2
+ /** Check if given value is a string */
3
+ function isString(val) {
4
+ return typeof val === "string";
5
+ }
6
+ /** Check if the given value is a number */
7
+ function isNumber(val) {
8
+ return typeof val === "number" && !Number.isNaN(val);
9
+ }
10
+ /** Check if the given value is an integer */
11
+ function isInteger(val) {
12
+ return isNumber(val) && Number.isInteger(val);
13
+ }
14
+ /** Check if the given value is a float */
15
+ function isFloat(val) {
16
+ return isNumber(val) && !Number.isInteger(val);
17
+ }
18
+ /** Check if given value is an array */
19
+ function isArray(val) {
20
+ return Array.isArray(val);
21
+ }
22
+ /** Check if given array is empty */
23
+ function isEmptyArray(val) {
24
+ return isArray(val) && val.length === 0;
25
+ }
26
+ /** Check if given value is an object */
27
+ function isObject(val) {
28
+ return val !== null && typeof val === "object" && !Array.isArray(val);
29
+ }
30
+ /** Check if given object is empty */
31
+ function isEmptyObject(val) {
32
+ return Object.keys(val).length === 0;
33
+ }
34
+ /** Check if the given value is empty, null, undefined, or a string with no content */
35
+ function isEmpty(val) {
36
+ if (val === null || val === void 0) return true;
37
+ if (typeof val === "string" && val.trim() === "") return true;
38
+ if (isArray(val)) return isEmptyArray(val);
39
+ if (isObject(val)) return isEmptyObject(val);
40
+ return false;
41
+ }
42
+ /** Check if the given object is a function */
43
+ function isFunction(val) {
44
+ return typeof val === "function";
45
+ }
46
+ /** Check if the given value is a regex */
47
+ function isRegex(val) {
48
+ return val instanceof RegExp;
49
+ }
50
+ /** Check if the given value is truthy */
51
+ function isTruthy(val) {
52
+ return !!val;
53
+ }
54
+ /** Check if the code is running in a browser environment */
55
+ function isBrowser() {
56
+ return typeof window !== "undefined";
57
+ }
58
+ /** Negate an assertion function, returning a new function with the opposite boolean result */
59
+ function not(fn) {
60
+ return ((val) => !fn(val));
61
+ }
62
+
63
+ //#endregion
64
+ export { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not };
@@ -0,0 +1,18 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!no_symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll as t };
@@ -1,10 +1,10 @@
1
- import { ClassNameValue } from './types.js';
2
- export { ClassNameValue } from './types.js';
1
+ import { ClassNameValue } from "../types.js";
3
2
 
3
+ //#region src/clsx/index.d.ts
4
4
  /**
5
5
  * Utility function to construct class names conditionally
6
6
  * @category ClassNames
7
7
  */
8
8
  declare function clsx(...inputs: ClassNameValue[]): string;
9
-
10
- export { clsx };
9
+ //#endregion
10
+ export { type ClassNameValue, clsx };
@@ -0,0 +1,40 @@
1
+ import { isArray, isNumber, isObject, isString } from "../assertions/index.js";
2
+
3
+ //#region src/clsx/index.ts
4
+ function toClassValue(value) {
5
+ let names = "";
6
+ let temp;
7
+ if (isString(value) || isNumber(value)) {
8
+ if (value) names += value.toString().trim();
9
+ } else if (isArray(value)) for (const item of value) {
10
+ temp = toClassValue(item);
11
+ if (!temp) continue;
12
+ if (names) names += " ";
13
+ names += temp;
14
+ }
15
+ else if (isObject(value)) for (const key in value) {
16
+ if (!value[key]) continue;
17
+ if (names) names += " ";
18
+ names += key;
19
+ }
20
+ return names;
21
+ }
22
+ /**
23
+ * Utility function to construct class names conditionally
24
+ * @category ClassNames
25
+ */
26
+ function clsx(...inputs) {
27
+ let result = "";
28
+ let temp;
29
+ for (const arg of inputs) {
30
+ if (!arg) continue;
31
+ temp = toClassValue(arg);
32
+ if (!temp) continue;
33
+ if (result) result += " ";
34
+ result += temp;
35
+ }
36
+ return result;
37
+ }
38
+
39
+ //#endregion
40
+ export { clsx };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,10 @@
1
- import * as array_d_ts from './array.js';
2
- export { array_d_ts as array };
3
- export * from './assertions.js';
4
- export * from './clsx.js';
5
- export * from './nanoid.js';
6
- import * as number_d_ts from './number.js';
7
- export { number_d_ts as number };
8
- import * as object_d_ts from './object.js';
9
- export { object_d_ts as object };
10
- import * as promise_d_ts from './promise.js';
11
- export { promise_d_ts as promise };
12
- import * as string_d_ts from './string.js';
13
- export { string_d_ts as string };
1
+ import { t as index_d_exports } from "./array/index.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/index.js";
4
+ import { clsx } from "./clsx/index.js";
5
+ import { charset, nanoid } from "./nanoid/index.js";
6
+ import { t as index_d_exports$1 } from "./number/index.js";
7
+ import { t as object_d_exports } from "./object.js";
8
+ import { t as index_d_exports$2 } from "./promise/index.js";
9
+ import { t as index_d_exports$3 } from "./string/index.js";
10
+ export { ClassNameValue, index_d_exports as array, charset, clsx, isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, nanoid, not, index_d_exports$1 as number, object_d_exports as object, index_d_exports$2 as promise, index_d_exports$3 as string };
package/dist/index.js CHANGED
@@ -1 +1,10 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./array.js"),r=require("./assertions.js"),t=require("./clsx.js"),o=require("./nanoid.js"),n=require("./number.js"),s=require("./object.js"),u=require("./promise.js"),c=require("./string.js");function a(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var i=a(e),p=a(n),f=a(s),j=a(u),b=a(c);exports.array=i,exports.number=p,exports.object=f,exports.promise=j,exports.string=b,Object.keys(r).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})}),Object.keys(t).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}),Object.keys(o).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return o[e]}})});
1
+ import { isArray, isBrowser, isEmpty, isEmptyArray, isEmptyObject, isFloat, isFunction, isInteger, isNumber, isObject, isRegex, isString, isTruthy, not } from "./assertions/index.js";
2
+ import { t as array_exports } from "./array/index.js";
3
+ import { clsx } from "./clsx/index.js";
4
+ import { charset, nanoid } from "./nanoid/index.js";
5
+ import { t as number_exports } from "./number/index.js";
6
+ import { t as object_exports } from "./object.js";
7
+ import { t as promise_exports } from "./promise/index.js";
8
+ import { t as string_exports } from "./string/index.js";
9
+
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,3 +1,4 @@
1
+ //#region src/nanoid/index.d.ts
1
2
  declare const charset = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789";
2
3
  /**
3
4
  * Generate a secure nanoid string using Node.js crypto module.
@@ -7,5 +8,5 @@ declare const charset = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0
7
8
  * @source https://github.com/ai/nanoid
8
9
  */
9
10
  declare function nanoid(length?: number, alphabets?: string): string;
10
-
11
- export { charset, nanoid };
11
+ //#endregion
12
+ export { charset, nanoid };
@@ -0,0 +1,29 @@
1
+ import { randomBytes } from "crypto";
2
+
3
+ //#region src/nanoid/index.ts
4
+ const charset = `abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789`;
5
+ /**
6
+ * Generate a secure nanoid string using Node.js crypto module.
7
+ * @param length - Length of the ID (default: 21)
8
+ * @param alphabets - Alphabet to use for the ID
9
+ * @returns A cryptographically secure unique ID string
10
+ * @source https://github.com/ai/nanoid
11
+ */
12
+ function nanoid(length = 21, alphabets = charset) {
13
+ const size = alphabets.length;
14
+ if (size === 0 || size > 255) throw new Error("Alphabet must contain less than 255 characters");
15
+ const mask = (2 << Math.floor(Math.log2(size - 1))) - 1;
16
+ const step = Math.ceil(1.6 * mask * length / size);
17
+ let id = "";
18
+ while (id.length < length) {
19
+ const bytes = randomBytes(step);
20
+ for (let i = 0; i < step && id.length < length; i++) {
21
+ const index = bytes[i] & mask;
22
+ if (index < size) id += alphabets[index];
23
+ }
24
+ }
25
+ return id;
26
+ }
27
+
28
+ //#endregion
29
+ export { charset, nanoid };
@@ -1,6 +1,9 @@
1
- import { AbbreviateOptions } from './types.js';
2
- export { AbbreviateOptions, AbbreviationSymbols } from './types.js';
1
+ import { AbbreviateOptions, AbbreviationSymbols } from "../types.js";
3
2
 
3
+ //#region src/number/index.d.ts
4
+ declare namespace index_d_exports {
5
+ export { AbbreviateOptions, AbbreviationSymbols, abbreviate, clamp, inRange };
6
+ }
4
7
  /**
5
8
  * Checks if a number is within a range
6
9
  * @param val The number to check
@@ -25,5 +28,5 @@ declare function clamp(val: number, min: number, max: number): number;
25
28
  */
26
29
  declare function abbreviate(value: number, precision?: number): string;
27
30
  declare function abbreviate(value: number, options?: AbbreviateOptions): string;
28
-
29
- export { abbreviate, clamp, inRange };
31
+ //#endregion
32
+ export { type AbbreviateOptions, type AbbreviationSymbols, abbreviate, clamp, inRange, index_d_exports as t };
@@ -0,0 +1,60 @@
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
+ import { isNumber, isObject } from "../assertions/index.js";
3
+
4
+ //#region src/number/index.ts
5
+ var number_exports = /* @__PURE__ */ __exportAll({
6
+ abbreviate: () => abbreviate,
7
+ clamp: () => clamp,
8
+ inRange: () => inRange
9
+ });
10
+ /**
11
+ * Checks if a number is within a range
12
+ * @param val The number to check
13
+ * @param min Minimum value
14
+ * @param max Maximum value
15
+ * @category Number
16
+ */
17
+ function inRange(val, min, max) {
18
+ return val >= min && val <= max;
19
+ }
20
+ /**
21
+ * Clamps a number between a minimum and maximum value
22
+ * @param val The number to clamp
23
+ * @param min Minimum value
24
+ * @param max Maximum value
25
+ * @category Number
26
+ */
27
+ function clamp(val, min, max) {
28
+ return Math.min(Math.max(val, min), max);
29
+ }
30
+ const baseAbbreviationSymbols = [
31
+ "",
32
+ "K",
33
+ "M",
34
+ "B",
35
+ "T"
36
+ ];
37
+ function abbreviate(value, arg) {
38
+ if (!isNumber(value)) return "0";
39
+ let precision = 1;
40
+ let symbols = baseAbbreviationSymbols;
41
+ if (typeof arg === "number") precision = arg;
42
+ else if (typeof arg === "object") {
43
+ precision = arg.precision ?? 1;
44
+ symbols = arg.symbols ?? baseAbbreviationSymbols;
45
+ }
46
+ const thresholds = isObject(symbols) ? Object.entries(symbols) : symbols.map((symbol, i) => [symbol, 10 ** (i * 3)]);
47
+ thresholds.sort((a, b) => b[1] - a[1]);
48
+ const sign = value < 0 ? "-" : "";
49
+ const abs = Math.abs(value);
50
+ for (const [symbol, threshold] of thresholds) {
51
+ const frac = (abs / threshold).toFixed(precision);
52
+ if (Number(frac) < 1) continue;
53
+ return `${sign}${frac}${symbol}`;
54
+ }
55
+ if (Math.floor(abs) === abs) return value.toString();
56
+ return `${sign}${abs.toFixed(precision)}`;
57
+ }
58
+
59
+ //#endregion
60
+ export { abbreviate, clamp, inRange, number_exports as t };
package/dist/object.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { Dictionary } from './types.js';
1
+ import { Dictionary } from "./types.js";
2
2
 
3
+ //#region src/object.d.ts
4
+ declare namespace object_d_exports {
5
+ export { keyInObject, omit, pick };
6
+ }
3
7
  /**
4
8
  * Checks if a given object has a specified key
5
9
  * @category Object
@@ -15,5 +19,5 @@ declare function pick<T extends object, K extends keyof T = keyof T>(input: T, k
15
19
  * @category Object
16
20
  */
17
21
  declare function omit<T extends object, K extends keyof T = keyof T>(input: T, keys: K | K[]): Omit<T, K>;
18
-
19
- export { keyInObject, omit, pick };
22
+ //#endregion
23
+ export { keyInObject, omit, pick, object_d_exports as t };
package/dist/object.js CHANGED
@@ -1 +1,38 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./array.js"),r=require("./assertions.js");exports.keyInObject=function(e,t){return r.isObject(e)&&t in e},exports.omit=function(r,t){let o={...r};for(let n of e.toArray(t))n in r&&delete o[n];return o},exports.pick=function(r,t){let o={};for(let n of e.toArray(t))n in r&&(o[n]=r[n]);return o};
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { isObject } from "./assertions/index.js";
3
+ import { toArray } from "./array/index.js";
4
+
5
+ //#region src/object.ts
6
+ var object_exports = /* @__PURE__ */ __exportAll({
7
+ keyInObject: () => keyInObject,
8
+ omit: () => omit,
9
+ pick: () => pick
10
+ });
11
+ /**
12
+ * Checks if a given object has a specified key
13
+ * @category Object
14
+ */
15
+ function keyInObject(val, key) {
16
+ return isObject(val) && key in val;
17
+ }
18
+ /**
19
+ * Picks a set of keys from an object
20
+ * @category Object
21
+ */
22
+ function pick(input, keys) {
23
+ const picked = {};
24
+ for (const key of toArray(keys)) if (key in input) picked[key] = input[key];
25
+ return picked;
26
+ }
27
+ /**
28
+ * Omits a set of keys from an object
29
+ * @category Object
30
+ */
31
+ function omit(input, keys) {
32
+ const partial = { ...input };
33
+ for (const key of toArray(keys)) if (key in input) delete partial[key];
34
+ return partial;
35
+ }
36
+
37
+ //#endregion
38
+ export { keyInObject, omit, pick, object_exports as t };
@@ -0,0 +1,31 @@
1
+ import { MaybePromise } from "../types.js";
2
+
3
+ //#region src/promise/index.d.ts
4
+ declare namespace index_d_exports {
5
+ export { retry, sleep, tryCatch };
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
+ */
13
+ declare function sleep(delay: number): Promise<void>;
14
+ /**
15
+ * Retries a function until it succeeds or the maximum number of retries is reached
16
+ * @param func The function to retry
17
+ * @param retries The number of retries
18
+ * @param delay The delay between retries (optional)
19
+ * @returns The result of the function
20
+ * @category promise
21
+ */
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]>;
30
+ //#endregion
31
+ export { retry, sleep, index_d_exports as t, tryCatch };
@@ -0,0 +1,56 @@
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
+ import { isNumber } from "../assertions/index.js";
3
+
4
+ //#region src/promise/index.ts
5
+ var promise_exports = /* @__PURE__ */ __exportAll({
6
+ retry: () => retry,
7
+ sleep: () => sleep,
8
+ tryCatch: () => tryCatch
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
+ */
16
+ function sleep(delay) {
17
+ if (!isNumber(delay)) throw new TypeError("sleep: delay must be a number");
18
+ else if (!Number.isFinite(delay) || delay < 0) throw new RangeError("sleep: delay must be a positive finite number");
19
+ if (delay === 0) return Promise.resolve();
20
+ return new Promise((resolve) => setTimeout(resolve, delay));
21
+ }
22
+ /**
23
+ * Retries a function until it succeeds or the maximum number of retries is reached
24
+ * @param func The function to retry
25
+ * @param retries The number of retries
26
+ * @param delay The delay between retries (optional)
27
+ * @returns The result of the function
28
+ * @category promise
29
+ */
30
+ async function retry(func, retries, delay = 0) {
31
+ try {
32
+ return await func();
33
+ } catch (error) {
34
+ if (retries > 0) {
35
+ await sleep(delay);
36
+ return retry(func, retries - 1, delay);
37
+ }
38
+ throw error;
39
+ }
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
+ }
54
+
55
+ //#endregion
56
+ export { retry, sleep, promise_exports as t, tryCatch };
@@ -0,0 +1,45 @@
1
+ //#region src/string/casing.d.ts
2
+ /**
3
+ * Converts a string to `camelCase`
4
+ * @param str The string to convert
5
+ * @category String
6
+ * @returns The CamelCase string
7
+ */
8
+ declare function toCamelCase(str: string): string;
9
+ /**
10
+ * Converts a string to `PascalCase`
11
+ * @param str The string to convert
12
+ * @category String
13
+ * @returns The PascalCase string
14
+ */
15
+ declare function toPascalCase(str: string): string;
16
+ /**
17
+ * Converts a string to `snake_case`
18
+ * @param str The string to convert
19
+ * @category String
20
+ * @returns The SnakeCase string
21
+ */
22
+ declare function toSnakeCase(str: string): string;
23
+ /**
24
+ * Converts a string to `kebab-case`
25
+ * @param str The string to convert
26
+ * @category String
27
+ * @returns The KebabCase string
28
+ */
29
+ declare function toKebabCase(str: string): string;
30
+ /**
31
+ * Converts a string to `Sentence case`
32
+ * @param str The string to convert
33
+ * @category String
34
+ * @returns The SentenceCase string
35
+ */
36
+ declare function toSentenceCase(str: string): string;
37
+ /**
38
+ * Converts a string to `Title Case`
39
+ * @param str The string to convert
40
+ * @category String
41
+ * @returns The TitleCase string
42
+ */
43
+ declare function toTitleCase(str: string): string;
44
+ //#endregion
45
+ export { toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase };
@@ -0,0 +1,92 @@
1
+ import { isEmpty } from "../assertions/index.js";
2
+
3
+ //#region src/string/casing.ts
4
+ 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
+ /**
6
+ * Splits a string into an array of words using Unicode-aware matching.
7
+ * @param str The input string to split into words.
8
+ * @returns An array of words found in the input string.
9
+ */
10
+ function words(str) {
11
+ return str.match(reWords) || [];
12
+ }
13
+ /**
14
+ * Joins the words in a string with the specified delimiter and converts the result to lowercase.
15
+ * @param str The input string to split into words and join.
16
+ * @param d The delimiter to use when joining the words.
17
+ * @returns The joined string in lowercase.
18
+ */
19
+ function join(str, d) {
20
+ return words(str).join(d).toLowerCase();
21
+ }
22
+ /**
23
+ * Capitalizes the first letter of a string
24
+ * @param str The string to convert
25
+ * @category String
26
+ * @returns The string with the first letter capitalized
27
+ */
28
+ function toUcFirst(str) {
29
+ if (isEmpty(str)) return "";
30
+ return str[0].toUpperCase() + str.slice(1);
31
+ }
32
+ /**
33
+ * Converts a string to `camelCase`
34
+ * @param str The string to convert
35
+ * @category String
36
+ * @returns The CamelCase string
37
+ */
38
+ function toCamelCase(str) {
39
+ return words(str).reduce((acc, next, i) => {
40
+ if (!next) return acc;
41
+ if (i === 0) return next.toLowerCase();
42
+ return acc + next[0].toUpperCase() + next.slice(1).toLowerCase();
43
+ }, "");
44
+ }
45
+ /**
46
+ * Converts a string to `PascalCase`
47
+ * @param str The string to convert
48
+ * @category String
49
+ * @returns The PascalCase string
50
+ */
51
+ function toPascalCase(str) {
52
+ return toUcFirst(toCamelCase(str));
53
+ }
54
+ /**
55
+ * Converts a string to `snake_case`
56
+ * @param str The string to convert
57
+ * @category String
58
+ * @returns The SnakeCase string
59
+ */
60
+ function toSnakeCase(str) {
61
+ return join(str, "_");
62
+ }
63
+ /**
64
+ * Converts a string to `kebab-case`
65
+ * @param str The string to convert
66
+ * @category String
67
+ * @returns The KebabCase string
68
+ */
69
+ function toKebabCase(str) {
70
+ return join(str, "-");
71
+ }
72
+ /**
73
+ * Converts a string to `Sentence case`
74
+ * @param str The string to convert
75
+ * @category String
76
+ * @returns The SentenceCase string
77
+ */
78
+ function toSentenceCase(str) {
79
+ return toUcFirst(join(str, " "));
80
+ }
81
+ /**
82
+ * Converts a string to `Title Case`
83
+ * @param str The string to convert
84
+ * @category String
85
+ * @returns The TitleCase string
86
+ */
87
+ function toTitleCase(str) {
88
+ return words(str).map(toUcFirst).join(" ");
89
+ }
90
+
91
+ //#endregion
92
+ export { toCamelCase, toKebabCase, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase };
@@ -1,3 +1,6 @@
1
+ declare namespace index_d_exports {
2
+ export { slash, truncate };
3
+ }
1
4
  /**
2
5
  * Replace backslash to slash
3
6
  * @category String
@@ -6,15 +9,9 @@ declare function slash(str: string): string;
6
9
  /**
7
10
  * Truncates a string to the specified length, adding "..." if it was longer.
8
11
  * @param text The string to truncate
9
- * @param length Maximum allowed length before truncation
12
+ * @param length Maximum allowed length before truncation (default: 80)
10
13
  * @category String
11
14
  */
12
15
  declare function truncate(input: string, length?: number): string;
13
- /**
14
- * Capitalizes the first letter of a string
15
- * @param input The string to capitalize
16
- * @category String
17
- */
18
- declare function capitalize(input: string): string;
19
-
20
- export { capitalize, slash, truncate };
16
+ //#endregion
17
+ export { slash, index_d_exports as t, truncate };
@@ -0,0 +1,30 @@
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/types.d.ts
1
2
  type Dictionary<T = any> = Record<string, T>;
2
3
  type AnyFunction<T = any> = (...args: any[]) => T;
3
4
  type ClassValue = string | number | bigint | null | boolean | undefined;
@@ -6,10 +7,11 @@ type ClassRecord = Record<string, any>;
6
7
  type ClassNameValue = ClassValue | ClassArray | ClassRecord;
7
8
  type AbbreviationSymbols = Dictionary<number> | string[];
8
9
  type AbbreviateOptions = {
9
- symbols?: AbbreviationSymbols;
10
- precision?: number;
10
+ symbols?: AbbreviationSymbols;
11
+ precision?: number;
11
12
  };
12
13
  type Predicate = ((val: unknown) => boolean) | ((val: unknown) => val is unknown);
13
- 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;
14
-
15
- export type { AbbreviateOptions, AbbreviationSymbols, AnyFunction, ClassNameValue, Dictionary, NegatePredicate, Predicate };
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.js ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/types.ts ADDED
@@ -0,0 +1,27 @@
1
+ export type Dictionary<T = any> = Record<string, T>;
2
+
3
+ export type AnyFunction<T = any> = (...args: any[]) => T;
4
+
5
+ type ClassValue = string | number | bigint | null | boolean | undefined;
6
+ type ClassArray = ClassValue[];
7
+ type ClassRecord = Record<string, any>;
8
+
9
+ export type ClassNameValue = ClassValue | ClassArray | ClassRecord;
10
+
11
+ export type AbbreviationSymbols = Dictionary<number> | string[];
12
+ export type AbbreviateOptions = {
13
+ symbols?: AbbreviationSymbols;
14
+ precision?: number;
15
+ };
16
+
17
+ export type Predicate =
18
+ | ((val: unknown) => boolean)
19
+ | ((val: unknown) => val is unknown);
20
+
21
+ export type NegatePredicate<T> = T extends (val: unknown) => val is infer U
22
+ ? <V>(val: V) => val is Exclude<V, U>
23
+ : T extends (val: unknown) => boolean
24
+ ? (val: unknown) => boolean
25
+ : never;
26
+
27
+ export type MaybePromise<T> = T | Promise<T>;
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,73 +1,43 @@
1
1
  {
2
2
  "name": "@oviirup/utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Collection of common JavaScript / TypeScript utilities bt @oviirup",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/oviirup/utils",
7
7
  "author": "Avirup Ghosh (github.com/oviirup)",
8
+ "type": "module",
8
9
  "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
13
- },
14
- "./array": {
15
- "types": "./dist/array.d.ts",
16
- "import": "./dist/array.mjs",
17
- "require": "./dist/array.js"
18
- },
19
- "./assertions": {
20
- "types": "./dist/assertions.d.ts",
21
- "import": "./dist/assertions.mjs",
22
- "require": "./dist/assertions.js"
23
- },
24
- "./clsx": {
25
- "types": "./dist/clsx.d.ts",
26
- "import": "./dist/clsx.mjs",
27
- "require": "./dist/clsx.js"
28
- },
29
- "./nanoid": {
30
- "types": "./dist/nanoid.d.ts",
31
- "import": "./dist/nanoid.mjs",
32
- "require": "./dist/nanoid.js"
33
- },
34
- "./number": {
35
- "types": "./dist/number.d.ts",
36
- "import": "./dist/number.mjs",
37
- "require": "./dist/number.js"
38
- },
39
- "./object": {
40
- "types": "./dist/object.d.ts",
41
- "import": "./dist/object.mjs",
42
- "require": "./dist/object.js"
43
- },
44
- "./promise": {
45
- "types": "./dist/promise.d.ts",
46
- "import": "./dist/promise.mjs",
47
- "require": "./dist/promise.js"
48
- },
49
- "./string": {
50
- "types": "./dist/string.d.ts",
51
- "import": "./dist/string.mjs",
52
- "require": "./dist/string.js"
53
- },
54
- "./types": {
55
- "types": "./dist/types.d.ts"
56
- }
10
+ ".": "./dist/index.js",
11
+ "./array": "./dist/array/index.js",
12
+ "./assertions": "./dist/assertions/index.js",
13
+ "./clsx": "./dist/clsx/index.js",
14
+ "./nanoid": "./dist/nanoid/index.js",
15
+ "./number": "./dist/number/index.js",
16
+ "./object": "./dist/object.js",
17
+ "./promise": "./dist/promise/index.js",
18
+ "./string": "./dist/string/index.js",
19
+ "./string/casing": "./dist/string/casing.js",
20
+ "./types": "./dist/types.js",
21
+ "./package.json": "./package.json"
57
22
  },
58
23
  "scripts": {
59
- "prepare": "lefthook install",
60
- "build": "bunchee --minify --no-sourcemap",
24
+ "build": "tsdown",
61
25
  "format": "biome format --write",
62
26
  "lint": "biome check",
27
+ "prepare": "lefthook install",
63
28
  "test": "bun test",
64
29
  "typecheck": "tsc --noEmit"
65
30
  },
66
31
  "devDependencies": {
67
- "@biomejs/biome": "^2",
68
- "@types/bun": "^1",
69
- "bunchee": "^6",
70
- "lefthook": "^2",
71
- "typescript": "^5"
32
+ "@biomejs/biome": "^2.3.14",
33
+ "@changesets/changelog-github": "^0.5.2",
34
+ "@changesets/cli": "^2.29.8",
35
+ "@types/bun": "^1.3.9",
36
+ "lefthook": "^2.1.0",
37
+ "tsdown": "^0.20.3",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
72
42
  }
73
43
  }
package/dist/array.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./assertions.js");function r(e,r){let t=e.length;if(t)return r<0&&(r+=t),e[r]}exports.at=r,exports.first=function(e){return r(e,0)},exports.last=function(e){return r(e,-1)},exports.move=function(r,t,n){if(e.isEmptyArray(r)||t===n)return r;let o=r[t];return r.splice(t,1),r.splice(n,0,o),r},exports.range=function(...e){let r,t=0,n=1;1===e.length?[r]=e:[t,r,n=1]=e;let o=[],u=t;for(;u<r;)o.push(u),u+=n;return o},exports.toArray=function(e){return Array.isArray(e=e??[])?e:[e]},exports.toFiltered=function(e,r){for(let t=e.length-1;t>=0;t--)r(e[t],t,e)||e.splice(t,1);return e},exports.unique=function(e,r){return"function"!=typeof r?Array.from(new Set(e)):e.reduce((e,t)=>(-1===e.findIndex(e=>r(e,t))&&e.push(t),e),[])};
package/dist/array.mjs DELETED
@@ -1 +0,0 @@
1
- import{isEmptyArray as r}from"./assertions.mjs";function t(r){return Array.isArray(r=r??[])?r:[r]}function n(r,t){return"function"!=typeof t?Array.from(new Set(r)):r.reduce((r,n)=>(-1===r.findIndex(r=>t(r,n))&&r.push(n),r),[])}function e(r,t){let n=r.length;if(n)return t<0&&(t+=n),r[t]}function u(r){return e(r,-1)}function i(r){return e(r,0)}function o(...r){let t,n=0,e=1;1===r.length?[t]=r:[n,t,e=1]=r;let u=[],i=n;for(;i<t;)u.push(i),i+=e;return u}function f(r,t){for(let n=r.length-1;n>=0;n--)t(r[n],n,r)||r.splice(n,1);return r}function c(t,n,e){if(r(t)||n===e)return t;let u=t[n];return t.splice(n,1),t.splice(e,0,u),t}export{e as at,i as first,u as last,c as move,o as range,t as toArray,f as toFiltered,n as unique};
@@ -1 +0,0 @@
1
- function t(t){return"number"==typeof t&&!Number.isNaN(t)}function r(t){return Array.isArray(t)}function e(t){return r(t)&&0===t.length}function n(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)}function o(t){return 0===Object.keys(t).length}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isArray=r,exports.isBrowser=function(){return"u">typeof window},exports.isEmpty=function(t){return null==t||"string"==typeof t&&""===t.trim()||(r(t)?e(t):!!n(t)&&o(t))},exports.isEmptyArray=e,exports.isEmptyObject=o,exports.isFloat=function(r){return t(r)&&!Number.isInteger(r)},exports.isFunction=function(t){return"function"==typeof t},exports.isInteger=function(r){return t(r)&&Number.isInteger(r)},exports.isNumber=t,exports.isObject=n,exports.isRegex=function(t){return t instanceof RegExp},exports.isString=function(t){return"string"==typeof t},exports.isTruthy=function(t){return!!t},exports.not=function(t){return r=>!t(r)};
@@ -1 +0,0 @@
1
- function n(n){return"string"==typeof n}function t(n){return"number"==typeof n&&!Number.isNaN(n)}function r(n){return t(n)&&Number.isInteger(n)}function e(n){return t(n)&&!Number.isInteger(n)}function i(n){return Array.isArray(n)}function u(n){return i(n)&&0===n.length}function o(n){return null!==n&&"object"==typeof n&&!Array.isArray(n)}function s(n){return 0===Object.keys(n).length}function f(n){return null==n||"string"==typeof n&&""===n.trim()||(i(n)?u(n):!!o(n)&&s(n))}function c(n){return"function"==typeof n}function y(n){return n instanceof RegExp}function p(n){return!!n}function g(){return"u">typeof window}function a(n){return t=>!n(t)}export{i as isArray,g as isBrowser,f as isEmpty,u as isEmptyArray,s as isEmptyObject,e as isFloat,c as isFunction,r as isInteger,t as isNumber,o as isObject,y as isRegex,n as isString,p as isTruthy,a as not};
package/dist/clsx.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./assertions.js");exports.clsx=function(...r){let t,i="";for(let s of r)s&&(t=function r(t){let i,s="";if(e.isString(t)||e.isNumber(t))t&&(s+=t.toString().trim());else if(e.isArray(t))for(let e of t)(i=r(e))&&(s&&(s+=" "),s+=i);else if(e.isObject(t))for(let e in t)t[e]&&(s&&(s+=" "),s+=e);return s}(s))&&(i&&(i+=" "),i+=t);return i};
package/dist/clsx.mjs DELETED
@@ -1 +0,0 @@
1
- import{isString as t,isNumber as e,isArray as r,isObject as o}from"./assertions.mjs";function f(...i){let n,l="";for(let f of i)f&&(n=function f(i){let n,l="";if(t(i)||e(i))i&&(l+=i.toString().trim());else if(r(i))for(let t of i)(n=f(t))&&(l&&(l+=" "),l+=n);else if(o(i))for(let t in i)i[t]&&(l&&(l+=" "),l+=t);return l}(f))&&(l&&(l+=" "),l+=n);return l}export{f as clsx};
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import*as r from"./array.mjs";export*from"./assertions.mjs";export*from"./clsx.mjs";export*from"./nanoid.mjs";import*as s from"./number.mjs";import*as m from"./object.mjs";import*as o from"./promise.mjs";import*as a from"./string.mjs";export{r as array,s as number,m as object,o as promise,a as string};
package/dist/nanoid.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("node:crypto");let t="abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789";exports.charset=t,exports.nanoid=function(r=21,o=t){let l=o.length;if(0===l||l>255)throw Error("Alphabet must contain less than 255 characters");let n=(2<<Math.floor(Math.log2(l-1)))-1,a=Math.ceil(1.6*n*r/l),h="";for(;h.length<r;){let t=e.randomBytes(a);for(let e=0;e<a&&h.length<r;e++){let r=t[e]&n;r<l&&(h+=o[r])}}return h};
package/dist/nanoid.mjs DELETED
@@ -1 +0,0 @@
1
- import{randomBytes as t}from"node:crypto";let e="abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789";function r(o=21,l=e){let n=l.length;if(0===n||n>255)throw Error("Alphabet must contain less than 255 characters");let h=(2<<Math.floor(Math.log2(n-1)))-1,a=Math.ceil(1.6*h*o/n),c="";for(;c.length<o;){let e=t(a);for(let t=0;t<a&&c.length<o;t++){let r=e[t]&h;r<n&&(c+=l[r])}}return c}export{e as charset,r as nanoid};
package/dist/number.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./assertions.js");let t=["","K","M","B","T"];exports.abbreviate=function(r,o){if(!e.isNumber(r))return"0";let n=1,i=t;"number"==typeof o?n=o:"object"==typeof o&&(n=o.precision??1,i=o.symbols??t);let s=e.isObject(i)?Object.entries(i):i.map((e,t)=>[e,10**(3*t)]);s.sort((e,t)=>t[1]-e[1]);let a=r<0?"-":"",u=Math.abs(r);for(let[e,t]of s){let r=(u/t).toFixed(n);if(!(1>Number(r)))return`${a}${r}${e}`}return Math.floor(u)===u?r.toString():`${a}${u.toFixed(n)}`},exports.clamp=function(e,t,r){return Math.min(Math.max(e,t),r)},exports.inRange=function(e,t,r){return e>=t&&e<=r};
package/dist/number.mjs DELETED
@@ -1 +0,0 @@
1
- import{isNumber as t,isObject as e}from"./assertions.mjs";function r(t,e,r){return t>=e&&t<=r}function o(t,e,r){return Math.min(Math.max(t,e),r)}let n=["","K","M","B","T"];function i(r,o){if(!t(r))return"0";let i=1,a=n;"number"==typeof o?i=o:"object"==typeof o&&(i=o.precision??1,a=o.symbols??n);let f=e(a)?Object.entries(a):a.map((t,e)=>[t,10**(3*e)]);f.sort((t,e)=>e[1]-t[1]);let m=r<0?"-":"",s=Math.abs(r);for(let[t,e]of f){let r=(s/e).toFixed(i);if(!(1>Number(r)))return`${m}${r}${t}`}return Math.floor(s)===s?r.toString():`${m}${s.toFixed(i)}`}export{i as abbreviate,o as clamp,r as inRange};
package/dist/object.mjs DELETED
@@ -1 +0,0 @@
1
- import{toArray as t}from"./array.mjs";import{isObject as r}from"./assertions.mjs";function e(t,e){return r(t)&&e in t}function n(r,e){let n={};for(let o of t(e))o in r&&(n[o]=r[o]);return n}function o(r,e){let n={...r};for(let o of t(e))o in r&&delete n[o];return n}export{e as keyInObject,o as omit,n as pick};
package/dist/promise.d.ts DELETED
@@ -1,11 +0,0 @@
1
- declare function sleep(delay: number): Promise<void>;
2
- /**
3
- * Retries a function until it succeeds or the maximum number of retries is reached
4
- * @param func The function to retry
5
- * @param retries The number of retries
6
- * @param delay The delay between retries (optional)
7
- * @returns The result of the function
8
- */
9
- declare function retry<T>(func: () => Promise<T>, retries: number, delay?: number): Promise<T>;
10
-
11
- export { retry, sleep };
package/dist/promise.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./assertions.js");function r(r){if(e.isNumber(r)){if(!Number.isFinite(r)||r<0)throw RangeError("sleep: delay must be a positive finite number")}else throw TypeError("sleep: delay must be a number");return 0===r?Promise.resolve():new Promise(e=>setTimeout(e,r))}async function t(e,s,i=0){try{return await e()}catch(o){if(s>0)return await r(i),t(e,s-1,i);throw o}}exports.retry=t,exports.sleep=r;
package/dist/promise.mjs DELETED
@@ -1 +0,0 @@
1
- import{isNumber as e}from"./assertions.mjs";function r(r){if(e(r)){if(!Number.isFinite(r)||r<0)throw RangeError("sleep: delay must be a positive finite number")}else throw TypeError("sleep: delay must be a number");return 0===r?Promise.resolve():new Promise(e=>setTimeout(e,r))}async function t(e,i,o=0){try{return await e()}catch(s){if(i>0)return await r(o),t(e,i-1,o);throw s}}export{t as retry,r as sleep};
package/dist/string.js DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.capitalize=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},exports.slash=function(e){return e.replace(/\\/g,"/")},exports.truncate=function(e,t=80){if(!e)return e;let r=e.trim(),n=Math.max(3,t);return r.length<=n?r:`${r.slice(0,n-3)}...`};
package/dist/string.mjs DELETED
@@ -1 +0,0 @@
1
- function t(t){return t.replace(/\\/g,"/")}function e(t,r=80){if(!t)return t;let n=t.trim(),a=Math.max(3,r);return n.length<=a?n:`${n.slice(0,a-3)}...`}function r(t){return t.charAt(0).toUpperCase()+t.slice(1)}export{r as capitalize,t as slash,e as truncate};