@oviirup/utils 1.0.7 → 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.
@@ -1,4 +1,4 @@
1
- declare namespace index_d_exports {
1
+ declare namespace array_d_exports {
2
2
  export { at, chunk, first, last, move, range, toArray, toFiltered, unique };
3
3
  }
4
4
  /**
@@ -66,4 +66,4 @@ declare function move<T>(array: T[], from: number, to: number): T[];
66
66
  */
67
67
  declare function chunk<T>(array: T[], size: number): T[][];
68
68
  //#endregion
69
- export { at, chunk, first, last, move, range, index_d_exports as t, toArray, toFiltered, unique };
69
+ export { at, chunk, first, last, move, range, array_d_exports as t, toArray, toFiltered, unique };
@@ -1,7 +1,7 @@
1
- import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
- import { isEmptyArray } from "../assertions/index.js";
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { isEmptyArray } from "./assertions.js";
3
3
 
4
- //#region src/array/index.ts
4
+ //#region src/array.ts
5
5
  var array_exports = /* @__PURE__ */ __exportAll({
6
6
  at: () => at,
7
7
  chunk: () => chunk,
@@ -1,6 +1,6 @@
1
- import { AnyFunction, Dictionary, NegatePredicate, Predicate } from "../types.js";
1
+ import { AnyFunction, Dictionary, NegatePredicate, Predicate } from "./types.js";
2
2
 
3
- //#region src/assertions/index.d.ts
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,4 +1,4 @@
1
- //#region src/assertions/index.ts
1
+ //#region src/assertions.ts
2
2
  /** Check if given value is a string */
3
3
  function isString(val) {
4
4
  return typeof val === "string";
@@ -1,6 +1,6 @@
1
- import { ClassNameValue } from "../types.js";
1
+ import { ClassNameValue } from "./types.js";
2
2
 
3
- //#region src/clsx/index.d.ts
3
+ //#region src/clsx.d.ts
4
4
  /**
5
5
  * Utility function to construct class names conditionally
6
6
  * @category ClassNames
@@ -1,6 +1,6 @@
1
- import { isArray, isNumber, isObject, isString } from "../assertions/index.js";
1
+ import { isArray, isNumber, isObject, isString } from "./assertions.js";
2
2
 
3
- //#region src/clsx/index.ts
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 index_d_exports } from "./array/index.js";
1
+ import { t as array_d_exports } from "./array.js";
2
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";
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
- 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 };
8
+ import { t as promise_d_exports } from "./promise.js";
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/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";
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
- import { t as promise_exports } from "./promise/index.js";
8
- import { t as string_exports } from "./string/index.js";
7
+ import { t as promise_exports } from "./promise.js";
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,4 +1,4 @@
1
- //#region src/nanoid/index.d.ts
1
+ //#region src/nanoid.d.ts
2
2
  declare const charset = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789";
3
3
  /**
4
4
  * Generate a secure nanoid string using Node.js crypto module.
@@ -1,6 +1,6 @@
1
1
  import { randomBytes } from "crypto";
2
2
 
3
- //#region src/nanoid/index.ts
3
+ //#region src/nanoid.ts
4
4
  const charset = `abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789`;
5
5
  /**
6
6
  * Generate a secure nanoid string using Node.js crypto module.
@@ -1,7 +1,7 @@
1
- import { AbbreviateOptions, AbbreviationSymbols } from "../types.js";
1
+ import { AbbreviateOptions, AbbreviationSymbols } from "./types.js";
2
2
 
3
- //#region src/number/index.d.ts
4
- declare namespace index_d_exports {
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, index_d_exports as t };
32
+ export { type AbbreviateOptions, type AbbreviationSymbols, abbreviate, clamp, inRange, number_d_exports as t };
@@ -1,7 +1,7 @@
1
- import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
- import { isNumber, isObject } from "../assertions/index.js";
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { isNumber, isObject } from "./assertions.js";
3
3
 
4
- //#region src/number/index.ts
4
+ //#region src/number.ts
5
5
  var number_exports = /* @__PURE__ */ __exportAll({
6
6
  abbreviate: () => abbreviate,
7
7
  clamp: () => clamp,
package/dist/object.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
- import { isObject } from "./assertions/index.js";
3
- import { toArray } from "./array/index.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 };
@@ -1,7 +1,7 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "./types.js";
2
2
 
3
- //#region src/promise/index.d.ts
4
- declare namespace index_d_exports {
3
+ //#region src/promise.d.ts
4
+ declare namespace promise_d_exports {
5
5
  export { retry, sleep, tryCatch };
6
6
  }
7
7
  /**
@@ -28,4 +28,4 @@ declare function retry<T>(func: () => Promise<T>, retries: number, delay?: numbe
28
28
  */
29
29
  declare function tryCatch<T, E = Error>(input: Promise<T> | (() => MaybePromise<T>)): Promise<readonly [Awaited<T>, undefined] | readonly [null, E]>;
30
30
  //#endregion
31
- export { retry, sleep, index_d_exports as t, tryCatch };
31
+ export { retry, sleep, promise_d_exports as t, tryCatch };
@@ -1,7 +1,7 @@
1
- import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
- import { isNumber } from "../assertions/index.js";
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { isNumber } from "./assertions.js";
3
3
 
4
- //#region src/promise/index.ts
4
+ //#region src/promise.ts
5
5
  var promise_exports = /* @__PURE__ */ __exportAll({
6
6
  retry: () => retry,
7
7
  sleep: () => sleep,
@@ -1,4 +1,18 @@
1
- //#region src/string/casing.d.ts
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 { isEmpty } from "../assertions/index.js";
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { isEmpty } from "./assertions.js";
2
3
 
3
- //#region src/string/casing.ts
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oviirup/utils",
3
- "version": "1.0.7",
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/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",
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
- "./promise": "./dist/promise/index.js",
18
- "./string": "./dist/string/index.js",
19
- "./string/casing": "./dist/string/casing.js",
17
+ "./picocolors": "./dist/picocolors.js",
18
+ "./promise": "./dist/promise.js",
19
+ "./string": "./dist/string.js",
20
20
  "./types": "./dist/types.js",
21
21
  "./package.json": "./package.json"
22
22
  },
@@ -29,11 +29,11 @@
29
29
  "typecheck": "tsc --noEmit"
30
30
  },
31
31
  "devDependencies": {
32
- "@biomejs/biome": "^2.3.14",
32
+ "@biomejs/biome": "^2.4.8",
33
33
  "@changesets/changelog-github": "^0.5.2",
34
- "@changesets/cli": "^2.29.8",
35
- "@types/bun": "^1.3.9",
36
- "lefthook": "^2.1.0",
34
+ "@changesets/cli": "^2.30.0",
35
+ "@types/bun": "^1.3.11",
36
+ "lefthook": "^2.1.4",
37
37
  "tsdown": "^0.20.3",
38
38
  "typescript": "^5.9.3"
39
39
  },
@@ -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 };
@@ -1,30 +0,0 @@
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 };