js-utils-kit 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("./char/index.cjs"),r=require("./env/index.cjs"),i=require("./file/index.cjs"),u=require("./number/index.cjs"),s=require("./object/index.cjs"),t=require("./string/index.cjs");require("fs"),require("path"),require("constants"),require("stream"),require("util"),require("assert"),require("buffer"),require("node:url"),require("node:path"),require("node:fs"),require("node:fs/promises"),require("node:events"),require("node:stream"),require("node:string_decoder"),require("zlib"),exports.char=e.default,exports.env=r.default,exports.file=i.default,exports.number=u.default,exports.object=s.default,exports.string=t.default;
package/dist/index.d.ts CHANGED
@@ -1,71 +1,7 @@
1
- import { ArchiverOptions } from 'archiver';
2
- export { ArchiverOptions } from 'archiver';
3
-
4
- /**
5
- * Supported archive formats.
6
- */
7
- type ArchiveFormat = 'zip' | 'tar';
8
- /**
9
- * Configuration options.
10
- */
11
- interface CreateArchiveOptions {
12
- /**
13
- * Archive format to use {@link ArchiveFormat}.
14
- */
15
- format: ArchiveFormat;
16
- /**
17
- * Path to the source directory that should be archived.
18
- */
19
- source: string;
20
- /**
21
- * Destination file path where the archive will be written
22
- * @example
23
- * - For `zip` format: `dist.zip`
24
- * - For `tar` format: `dist.tar`
25
- */
26
- destination: string;
27
- /**
28
- * Additional options passed directly to the archiver library. See {@link ArchiverOptions}.
29
- */
30
- options?: ArchiverOptions;
31
- /**
32
- * Optional flag to enable internal logging. Useful for CLI mode.
33
- */
34
- log?: boolean;
35
- /**
36
- * Called after archiving is complete — receives total size in bytes.
37
- */
38
- onSuccess?: (bytes: number) => void;
39
- }
40
- /**
41
- * Creates a {@link ArchiveFormat } archive from a specified directory.
42
- *
43
- * This function uses the `archiver` library to package a directory into an archive file.
44
- * It supports optional compression for `zip` and returns a Promise that resolves
45
- * when the archive is successfully created.
46
- *
47
- * @example
48
- *
49
- * Function usage:
50
- *
51
- * ```ts
52
- * await createArchive({
53
- * format: "zip",
54
- * source: "dist/",
55
- * destination: "dist.zip",
56
- * });
57
- * ```
58
- *
59
- * CLI usage:
60
- * ```sh
61
- * npx js-utils-kit createArchive -f zip -s dist -d dist.zip
62
- * ```
63
- *
64
- * @param options - Archive creation options
65
- * @returns A Promise that resolves when the archive is created
66
- * @throws If an error occurs during the archiving process
67
- */
68
- declare function createArchive({ format, source, destination, options, log, onSuccess, }: CreateArchiveOptions): Promise<void>;
69
-
70
- export { createArchive };
71
- export type { ArchiveFormat, CreateArchiveOptions };
1
+ export { default as char } from './char/index.js';
2
+ export { default as env } from './env/index.js';
3
+ export { default as file } from './file/index.js';
4
+ export { default as number } from './number/index.js';
5
+ export { default as object } from './object/index.js';
6
+ export { default as string } from './string/index.js';
7
+ import 'archiver';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export{default as char}from"./char/index.js";export{default as env}from"./env/index.js";export{default as file}from"./file/index.js";export{default as number}from"./number/index.js";export{default as object}from"./object/index.js";export{default as string}from"./string/index.js";import"fs";import"path";import"constants";import"stream";import"util";import"assert";import"buffer";import"node:url";import"node:path";import"node:fs";import"node:fs/promises";import"node:events";import"node:stream";import"node:string_decoder";import"zlib";
@@ -0,0 +1 @@
1
+ "use strict";function t(t,r,n){return Math.min(Math.max(t,r),n)}function r(t){return t%2==0}function n(t){return t%2!=0}function o(t,r){return Math.floor(Math.random()*(r-t+1))+t}function e(t,r){return Math.random()*(r-t)+t}Object.defineProperty(exports,"__esModule",{value:!0});var a={clamp:t,isEven:r,isOdd:n,randomInt:o,randomFloat:e};exports.clamp=t,exports.default=a,exports.isEven=r,exports.isOdd=n,exports.randomFloat=e,exports.randomInt=o;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Clamps a number between a minimum and maximum value.
3
+ *
4
+ * Ensures that the returned number is not less than `min` and not more than `max`.
5
+ *
6
+ * @param value - The number to clamp.
7
+ * @param min - The minimum allowed value.
8
+ * @param max - The maximum allowed value.
9
+ * @returns The clamped number.
10
+ *
11
+ * @example
12
+ * clamp(5, 1, 10); // 5
13
+ * clamp(0, 1, 10); // 1
14
+ * clamp(15, 1, 10); // 10
15
+ */
16
+ declare function clamp(value: number, min: number, max: number): number;
17
+
18
+ /**
19
+ * Checks if a number is even.
20
+ *
21
+ * @param value - The number to check.
22
+ * @returns True if the number is even, false otherwise.
23
+ *
24
+ * @example
25
+ * isEven(4); // true
26
+ * isEven(3); // false
27
+ */
28
+ declare function isEven(value: number): boolean;
29
+ /**
30
+ * Checks if a number is odd.
31
+ *
32
+ * @param value - The number to check.
33
+ * @returns True if the number is odd, false otherwise.
34
+ *
35
+ * @example
36
+ * isOdd(3); // true
37
+ * isOdd(4); // false
38
+ */
39
+ declare function isOdd(value: number): boolean;
40
+
41
+ /**
42
+ * Returns a random integer between `min` and `max`, inclusive.
43
+ *
44
+ * @param min - Minimum value (inclusive).
45
+ * @param max - Maximum value (inclusive).
46
+ * @returns A random integer between min and max.
47
+ *
48
+ * @example
49
+ * randomInt(1, 5); // 3
50
+ * randomInt(10, 20); // 17
51
+ */
52
+ declare function randomInt(min: number, max: number): number;
53
+ /**
54
+ * Returns a random floating-point number between `min` and `max`.
55
+ *
56
+ * @param min - Minimum value (inclusive).
57
+ * @param max - Maximum value (exclusive).
58
+ * @returns A random float between min and max.
59
+ *
60
+ * @example
61
+ * randomFloat(0, 1); // 0.624...
62
+ * randomFloat(1.5, 5.2); // 3.1415...
63
+ */
64
+ declare function randomFloat(min: number, max: number): number;
65
+
66
+ declare const _default: {
67
+ clamp: typeof clamp;
68
+ isEven: typeof isEven;
69
+ isOdd: typeof isOdd;
70
+ randomInt: typeof randomInt;
71
+ randomFloat: typeof randomFloat;
72
+ };
73
+
74
+ export { clamp, _default as default, isEven, isOdd, randomFloat, randomInt };
@@ -0,0 +1 @@
1
+ function n(n,t,r){return Math.min(Math.max(n,t),r)}function t(n){return n%2==0}function r(n){return n%2!=0}function a(n,t){return Math.floor(Math.random()*(t-n+1))+n}function o(n,t){return Math.random()*(t-n)+n}var u={clamp:n,isEven:t,isOdd:r,randomInt:a,randomFloat:o};export{n as clamp,u as default,t as isEven,r as isOdd,o as randomFloat,a as randomInt};
@@ -0,0 +1 @@
1
+ "use strict";function r(e=!1,...t){const o=r=>"object"==typeof r&&null!==r&&!Array.isArray(r);return t.reduce((t,s)=>{for(const n in s){const a=s[n],u=t[n];Array.isArray(a)?t[n]=e&&Array.isArray(u)?[...u,...a]:[...a]:o(a)?t[n]=r(e,o(u)?u:{},a):t[n]=a}return t},{})}Object.defineProperty(exports,"__esModule",{value:!0});var e={mergeObj:r};exports.default=e,exports.mergeObj=r;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Deeply merges multiple source objects into one.
3
+ *
4
+ * - Object properties are merged recursively.
5
+ * - If a key exists in multiple objects:
6
+ * - If the value is a plain object, it is deeply merged.
7
+ * - If the value is an array:
8
+ * - If `appendArray` is `true`, arrays are concatenated.
9
+ * - If `appendArray` is `false` (default), later arrays replace earlier ones.
10
+ * - Primitive values (string, number, boolean, etc.) are overwritten by later sources.
11
+ *
12
+ * - Objects passed later in the list of sources have **higher priority**.
13
+ * For example, values in the last object will override previous ones.
14
+ * - If you want to give **priority to a specific object**, **pass it last**.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const defaultConfig = { env: "dev", features: ["a"], flags: { debug: true } };
19
+ * const userConfig = { env: "prod", features: ["b"], flags: { beta: true } };
20
+ *
21
+ * const result = mergeObj(false, defaultConfig, userConfig);
22
+ * // {
23
+ * // env: "prod",
24
+ * // features: ["b"], // replaced, not merged
25
+ * // flags: { debug: true, beta: true }
26
+ * // }
27
+ *
28
+ * const result2 = mergeObj(true, defaultConfig, userConfig);
29
+ * // {
30
+ * // env: "prod",
31
+ * // features: ["a", "b"], // arrays merged
32
+ * // flags: { debug: true, beta: true }
33
+ * // }
34
+ * ```
35
+ *
36
+ * @param appendArray - If `true`, arrays are concatenated. If `false` (default), arrays are replaced.
37
+ * @param sources - One or more objects to deeply merge.
38
+ * @returns A new object containing deeply merged keys and values.
39
+ */
40
+ declare function mergeObj(appendArray?: boolean, ...sources: Record<string, unknown>[]): Record<string, unknown>;
41
+
42
+ declare const _default: {
43
+ mergeObj: typeof mergeObj;
44
+ };
45
+
46
+ export { _default as default, mergeObj };
@@ -0,0 +1 @@
1
+ function r(e=!1,...t){const a=r=>"object"==typeof r&&null!==r&&!Array.isArray(r);return t.reduce((t,n)=>{for(const o in n){const s=n[o],y=t[o];Array.isArray(s)?t[o]=e&&Array.isArray(y)?[...y,...s]:[...s]:a(s)?t[o]=r(e,a(y)?y:{},s):t[o]=s}return t},{})}var e={mergeObj:r};export{e as default,r as mergeObj};
@@ -0,0 +1 @@
1
+ "use strict";function t(t){return null!=t&&"string"==typeof t}function r(r,e=!0){return!!t(r)&&(e?r.trim().length>0:r.length>0)}function e(t){try{return new URL(t),!0}catch{return!1}}function i(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function n(t){return/^[a-zA-Z]+$/.test(t)}function s(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}Object.defineProperty(exports,"__esModule",{value:!0});var u={isString:t,isNonEmptyString:r,isURL:e,isEmail:i,isAlphabetic:n,isNumericString:s};exports.default=u,exports.isAlphabetic=n,exports.isEmail=i,exports.isNonEmptyString=r,exports.isNumericString=s,exports.isString=t,exports.isURL=e;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Determines whether the provided value is a string.
3
+ *
4
+ * This function returns `true` if the input is a non-null, non-undefined
5
+ * primitive string. It acts as a type guard, so TypeScript will narrow
6
+ * the type to `string` when used in conditionals.
7
+ *
8
+ * @template T - The type of the input value.
9
+ * @param value - The value to be checked.
10
+ * @returns - Whether the value is a string (`true`) or not (`false`).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * isString("hello"); // true
15
+ * isString(123); // false
16
+ * isString(null); // false
17
+ * isString(undefined); // false
18
+ *
19
+ * const value: unknown = "test";
20
+ * if (isString(value)) {
21
+ * console.log(value.toUpperCase());
22
+ * }
23
+ * ```
24
+ */
25
+ declare function isString<T>(value: T): value is T & string;
26
+ /**
27
+ * Determines whether the given value is a non-empty string.
28
+ *
29
+ * This function first checks if the input is a string using {@link isString}.
30
+ * If it is not a string, the function returns `false`.
31
+ * If it is a string, it then checks whether the string contains any non-empty content.
32
+ *
33
+ * By default, the function trims the string before checking its length,
34
+ * which means strings containing only whitespace (e.g., `" "`) will be considered empty.
35
+ * This behavior can be controlled using the `trim` parameter.
36
+ *
37
+ * @template T - The type of the value being checked.
38
+ *
39
+ * @param value - The value to validate as a non-empty string.
40
+ * @param trim - Whether to trim whitespace from the string before checking its length.
41
+ * Defaults to `true`.
42
+ *
43
+ * @returns - A boolean indicating whether the input is a non-empty string.
44
+ *
45
+ * @example
46
+ * isNonEmptyString('hello'); // true
47
+ * isNonEmptyString(' '); // false (trim is true by default)
48
+ * isNonEmptyString(' ', false); // true (whitespace is counted)
49
+ * isNonEmptyString(123); // false
50
+ * isNonEmptyString(null); // false
51
+ */
52
+ declare function isNonEmptyString<T>(value: T, trim?: boolean): boolean;
53
+ /**
54
+ * Checks whether a given string is a valid absolute URL.
55
+ *
56
+ * This function uses the native `URL` constructor to determine if the input is a valid,
57
+ * absolute URL with a supported protocol (e.g., `http`, `https`, `ftp`, etc.).
58
+ *
59
+ * @param value - The string to validate as a URL.
60
+ * @returns - `true` if the string is a valid absolute URL; otherwise, `false`.
61
+ *
62
+ * @example
63
+ * isURL('https://example.com'); // true
64
+ * isURL('ftp://files.example.com'); // true
65
+ * isURL('invalid-url'); // false
66
+ * isURL('/relative/path'); // false
67
+ */
68
+ declare function isURL(value: string): boolean;
69
+ /**
70
+ * Checks whether a given string is a valid email address.
71
+ *
72
+ * This function uses a practical regular expression to validate email addresses,
73
+ * allowing most common formats while ignoring edge cases defined by full RFC 5322.
74
+ * It requires the presence of an `@` symbol and at least one `.` after it.
75
+ *
76
+ * @param value - The string to validate as an email address.
77
+ * @returns - `true` if the string is a valid email; otherwise, `false`.
78
+ *
79
+ * @example
80
+ * isEmail('user@example.com'); // true
81
+ * isEmail('first.last@college.university.in'); // true
82
+ * isEmail('invalid-email'); // false
83
+ * isEmail('name@domain'); // false
84
+ */
85
+ declare function isEmail(value: string): boolean;
86
+ /**
87
+ * Checks if a string contains only alphabetic characters (A–Z, a–z).
88
+ *
89
+ * @param value - The string to check.
90
+ * @returns - `true` if the string contains only letters; otherwise, `false`.
91
+ *
92
+ * @example
93
+ * isAlphabetic("Hello"); // true
94
+ * isAlphabetic("world123"); // false
95
+ * isAlphabetic("Test!"); // false
96
+ */
97
+ declare function isAlphabetic(value: string): boolean;
98
+ /**
99
+ * Checks whether a given string represents a valid numeric value.
100
+ *
101
+ * This function attempts to convert the input string to a number using
102
+ * both `Number()` and `parseFloat()`. It returns `true` only if both
103
+ * conversions do not result in `NaN`, ensuring that the input is
104
+ * a fully numeric string.
105
+ *
106
+ * Accepts integers, decimals, scientific notation (e.g. "1e5"), and
107
+ * ignores surrounding whitespace. Does not allow trailing or embedded characters
108
+ * like "123abc" or "abc123".
109
+ *
110
+ * @param value - The string to validate.
111
+ * @returns - `true` if the string represents a valid number; otherwise, `false`.
112
+ *
113
+ * @example
114
+ * isNumericString("42"); // true
115
+ * isNumericString("-3.14"); // true
116
+ * isNumericString("1e5"); // true
117
+ * isNumericString(" 123 "); // true
118
+ * isNumericString("123abc"); // false
119
+ * isNumericString("abc123"); // false
120
+ *
121
+ * See also:
122
+ * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number()}
123
+ * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat()}
124
+ * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
125
+ */
126
+ declare function isNumericString(value: string): boolean;
127
+
128
+ declare const _default: {
129
+ isString: typeof isString;
130
+ isNonEmptyString: typeof isNonEmptyString;
131
+ isURL: typeof isURL;
132
+ isEmail: typeof isEmail;
133
+ isAlphabetic: typeof isAlphabetic;
134
+ isNumericString: typeof isNumericString;
135
+ };
136
+
137
+ export { _default as default, isAlphabetic, isEmail, isNonEmptyString, isNumericString, isString, isURL };
@@ -0,0 +1 @@
1
+ function t(t){return null!=t&&"string"==typeof t}function n(n,r=!0){return!!t(n)&&(r?n.trim().length>0:n.length>0)}function r(t){try{return new URL(t),!0}catch{return!1}}function i(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function e(t){return/^[a-zA-Z]+$/.test(t)}function u(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}var s={isString:t,isNonEmptyString:n,isURL:r,isEmail:i,isAlphabetic:e,isNumericString:u};export{s as default,e as isAlphabetic,i as isEmail,n as isNonEmptyString,u as isNumericString,t as isString,r as isURL};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "js-utils-kit",
3
3
  "displayName": "JS Utils Kit",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
5
  "description": "Essential JavaScript helpers",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -19,7 +19,22 @@
19
19
  "utils",
20
20
  "helpers",
21
21
  "toolkit",
22
- "typescript"
22
+ "typescript",
23
+ "js",
24
+ "utility",
25
+ "functions",
26
+ "modules",
27
+ "typed",
28
+ "common",
29
+ "cli",
30
+ "merge",
31
+ "random",
32
+ "string",
33
+ "array",
34
+ "object",
35
+ "number",
36
+ "date",
37
+ "type-check"
23
38
  ],
24
39
  "type": "module",
25
40
  "files": [
@@ -28,19 +43,49 @@
28
43
  "bin": {
29
44
  "js-utils-kit": "dist/cli/index.js"
30
45
  },
31
- "main": "dist/index.cjs.js",
32
- "module": "dist/index.esm.js",
46
+ "main": "dist/index.cjs",
47
+ "module": "dist/index.js",
33
48
  "types": "dist/index.d.ts",
34
49
  "exports": {
35
50
  ".": {
36
- "import": {
37
- "types": "./dist/index.d.ts",
38
- "default": "./dist/index.esm.js"
39
- },
40
- "require": {
41
- "types": "./dist/index.d.ts",
42
- "default": "./dist/index.cjs.js"
43
- }
51
+ "import": "./dist/index.js",
52
+ "require": "./dist/index.cjs",
53
+ "types": "./dist/index.d.ts"
54
+ },
55
+ "./char": {
56
+ "import": "./dist/char/index.js",
57
+ "require": "./dist/char/index.cjs",
58
+ "types": "./dist/char/index.d.ts"
59
+ },
60
+ "./cli": {
61
+ "import": "./dist/cli/index.js",
62
+ "require": "./dist/cli/index.cjs",
63
+ "types": "./dist/cli/index.d.ts"
64
+ },
65
+ "./env": {
66
+ "import": "./dist/env/index.js",
67
+ "require": "./dist/env/index.cjs",
68
+ "types": "./dist/env/index.d.ts"
69
+ },
70
+ "./file": {
71
+ "import": "./dist/file/index.js",
72
+ "require": "./dist/file/index.cjs",
73
+ "types": "./dist/file/index.d.ts"
74
+ },
75
+ "./number": {
76
+ "import": "./dist/number/index.js",
77
+ "require": "./dist/number/index.cjs",
78
+ "types": "./dist/number/index.d.ts"
79
+ },
80
+ "./object": {
81
+ "import": "./dist/object/index.js",
82
+ "require": "./dist/object/index.cjs",
83
+ "types": "./dist/object/index.d.ts"
84
+ },
85
+ "./string": {
86
+ "import": "./dist/string/index.js",
87
+ "require": "./dist/string/index.cjs",
88
+ "types": "./dist/string/index.d.ts"
44
89
  }
45
90
  },
46
91
  "lint-staged": {
@@ -48,7 +93,9 @@
48
93
  },
49
94
  "scripts": {
50
95
  "test": "jest",
51
- "build": "rollup -c && yarn docs",
96
+ "prebuild": "yarn gen:indexes",
97
+ "build": "rollup -c",
98
+ "postbuild": "yarn gen:exports && yarn docs",
52
99
  "release": "release-it",
53
100
  "watch": "rollup -c --watch",
54
101
  "lint": "eslint .",
@@ -56,7 +103,10 @@
56
103
  "format": "prettier --write",
57
104
  "format:check": "prettier --check .",
58
105
  "prepare": "husky",
59
- "docs": "typedoc"
106
+ "prepare:release": "yarn test && yarn prebuild && yarn build && yarn postbuild",
107
+ "docs": "typedoc",
108
+ "gen:exports": "node scripts/gen-exports.js",
109
+ "gen:indexes": "node scripts/gen-indexes.js"
60
110
  },
61
111
  "devDependencies": {
62
112
  "@eslint/js": "^9.29.0",
@@ -71,14 +121,12 @@
71
121
  "@types/jest": "^30.0.0",
72
122
  "@types/node": "^24.0.4",
73
123
  "archiver": "^7.0.1",
74
- "commander": "^14.0.0",
75
124
  "eslint": "^9.29.0",
76
125
  "globals": "^16.2.0",
77
126
  "husky": "^9.1.7",
78
127
  "jest": "^30.0.3",
79
128
  "jest-environment-node": "^30.0.2",
80
129
  "lint-staged": "^16.1.2",
81
- "ora": "^8.2.0",
82
130
  "prettier": "^3.6.0",
83
131
  "release-it": "^19.0.3",
84
132
  "rollup": "^4.44.0",
@@ -90,5 +138,9 @@
90
138
  "typedoc": "^0.28.5",
91
139
  "typescript": "^5.8.3",
92
140
  "typescript-eslint": "^8.35.0"
141
+ },
142
+ "dependencies": {
143
+ "commander": "^14.0.0",
144
+ "ora": "^8.2.0"
93
145
  }
94
146
  }