js-utils-kit 0.2.3 → 0.3.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 CHANGED
@@ -1 +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;
1
+ "use strict";var e=require("./array/index.cjs"),r=require("./char/index.cjs"),s=require("./env/index.cjs"),t=require("./file/index.cjs"),i=require("./number/index.cjs"),o=require("./object/index.cjs"),a=require("./string/index.cjs"),p=require("./validate-BKQ-HFTd.js");require("fs"),require("path"),require("events"),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.array=e.default,exports.all=r.all,exports.char=r.default,exports.digits=r.digits,exports.lowercase=r.lowercase,exports.uppercase=r.uppercase,Object.defineProperty(exports,"Environment",{enumerable:!0,get:function(){return s.Environment}}),exports.env=s.default,exports.getRunTimeEnvironment=s.getRunTimeEnvironment,exports.isBrowser=s.isBrowser,exports.isDev=s.isDev,exports.isNode=s.isNode,exports.isProd=s.isProd,exports.isTest=s.isTest,exports.createArchive=t.createArchive,exports.file=t.default,exports.clamp=i.clamp,exports.isEven=i.isEven,exports.isOdd=i.isOdd,exports.number=i.default,exports.randomFloat=i.randomFloat,exports.randomInt=i.randomInt,exports.isEmptyObject=o.isEmptyObject,exports.isNonEmptyObject=o.isNonEmptyObject,exports.isObject=o.isObject,exports.mergeObj=o.mergeObj,exports.object=o.default,exports.capitalize=a.capitalize,exports.containsWhitespace=a.containsWhitespace,exports.endsWithPunctuation=a.endsWithPunctuation,exports.isAlphabetic=a.isAlphabetic,exports.isCamelCase=a.isCamelCase,exports.isEmail=a.isEmail,exports.isKebabCase=a.isKebabCase,exports.isLowerCase=a.isLowerCase,exports.isNonEmptyString=a.isNonEmptyString,exports.isNumericString=a.isNumericString,exports.isPascalCase=a.isPascalCase,exports.isSnakeCase=a.isSnakeCase,exports.isString=a.isString,exports.isURL=a.isURL,exports.isUpperCase=a.isUpperCase,exports.padLeft=a.padLeft,exports.padRight=a.padRight,exports.repeatString=a.repeatString,exports.startsWithUppercase=a.startsWithUppercase,exports.string=a.default,exports.trim=a.trim,exports.truncate=a.truncate,exports.isArray=p.isArray,exports.isDefined=p.isDefined,exports.isUndefinedOrNull=p.isUndefinedOrNull;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,37 @@
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';
1
+ export { default as array, isArray } from './array/index.js';
2
+ export { all, default as char, digits, lowercase, uppercase } from './char/index.js';
3
+ export { Environment, default as env, getRunTimeEnvironment, isBrowser, isDev, isNode, isProd, isTest } from './env/index.js';
4
+ export { ArchiveFormat, CreateArchiveOptions, createArchive, default as file } from './file/index.js';
5
+ export { clamp, isEven, isOdd, default as number, randomFloat, randomInt } from './number/index.js';
6
+ export { isEmptyObject, isNonEmptyObject, isObject, mergeObj, default as object } from './object/index.js';
7
+ export { Trim, capitalize, containsWhitespace, endsWithPunctuation, isAlphabetic, isCamelCase, isEmail, isKebabCase, isLowerCase, isNonEmptyString, isNumericString, isPascalCase, isSnakeCase, isString, isURL, isUpperCase, padLeft, padRight, repeatString, startsWithUppercase, default as string, trim, truncate } from './string/index.js';
8
+ export { ArchiverOptions } from 'archiver';
9
+
10
+ /**
11
+ * Checks if a value is neither null nor undefined.
12
+ * @param value - The value to check.
13
+ * @returns True if the value is defined (not null or undefined), false otherwise.
14
+ * @example
15
+ * ```ts
16
+ * isDefined(42); // true
17
+ * isDefined("hello"); // true
18
+ * isDefined(null); // false
19
+ * isDefined(undefined); // false
20
+ * ```
21
+ */
22
+ declare function isDefined<T>(value: T): boolean;
23
+ /**
24
+ * Checks if a value is either null or undefined.
25
+ * @param value - The value to check.
26
+ * @returns True if the value is null or undefined, false otherwise.
27
+ * @example
28
+ * ```ts
29
+ * isUndefinedOrNull(null); // true
30
+ * isUndefinedOrNull(undefined); // true
31
+ * isUndefinedOrNull(0); // false
32
+ * isUndefinedOrNull(""); // false
33
+ * ```
34
+ */
35
+ declare function isUndefinedOrNull<T>(value: T): boolean;
36
+
37
+ export { isDefined, isUndefinedOrNull };
package/dist/index.js CHANGED
@@ -1 +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";
1
+ export{default as array}from"./array/index.js";export{all,default as char,digits,lowercase,uppercase}from"./char/index.js";export{Environment,default as env,getRunTimeEnvironment,isBrowser,isDev,isNode,isProd,isTest}from"./env/index.js";export{createArchive,default as file}from"./file/index.js";export{clamp,isEven,isOdd,default as number,randomFloat,randomInt}from"./number/index.js";export{isEmptyObject,isNonEmptyObject,isObject,mergeObj,default as object}from"./object/index.js";export{capitalize,containsWhitespace,endsWithPunctuation,isAlphabetic,isCamelCase,isEmail,isKebabCase,isLowerCase,isNonEmptyString,isNumericString,isPascalCase,isSnakeCase,isString,isURL,isUpperCase,padLeft,padRight,repeatString,startsWithUppercase,default as string,trim,truncate}from"./string/index.js";export{i as isArray,a as isDefined,b as isUndefinedOrNull}from"./validate-D9J7otjc.js";import"fs";import"path";import"events";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";
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../validate-BKQ-HFTd.js");function t(e=!1,...r){const o=e=>"object"==typeof e&&null!==e,s={};for(const c of r)if(o(c))for(const r of Object.keys(c)){const n=c[r],y=s[r];Array.isArray(n)?s[r]=e&&Array.isArray(y)?[...y,...n]:[...n]:o(n)&&!Array.isArray(n)?s[r]=o(y)&&!Array.isArray(y)?t(e,y,n):t(e,{},n):s[r]=n}return s}function r(t){return e.isDefined(t)&&"object"==typeof t&&!e.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function o(t){return null!==t&&"object"==typeof t&&0===Object.keys(t).length&&!e.isArray(t)}function s(t){return null!==t&&"object"==typeof t&&Object.keys(t).length>0&&!e.isArray(t)}var c={mergeObj:t,isObject:r,isEmptyObject:o,isNonEmptyObject:s};exports.default=c,exports.isEmptyObject=o,exports.isNonEmptyObject=s,exports.isObject=r,exports.mergeObj=t;
@@ -18,7 +18,7 @@
18
18
  * const defaultConfig = { env: "dev", features: ["a"], flags: { debug: true } };
19
19
  * const userConfig = { env: "prod", features: ["b"], flags: { beta: true } };
20
20
  *
21
- * const result = mergeObj(false, defaultConfig, userConfig);
21
+ * const result = mergeObj(defaultConfig, userConfig);
22
22
  * // {
23
23
  * // env: "prod",
24
24
  * // features: ["b"], // replaced, not merged
@@ -37,10 +37,53 @@
37
37
  * @param sources - One or more objects to deeply merge.
38
38
  * @returns A new object containing deeply merged keys and values.
39
39
  */
40
- declare function mergeObj(appendArray?: boolean, ...sources: Record<string, unknown>[]): Record<string, unknown>;
40
+ declare function mergeObj(appendArray?: boolean, ...sources: object[]): object;
41
+
42
+ /**
43
+ * Checks if a value is a plain object (created by {} or new Object()).
44
+ * @param value - The value to check.
45
+ * @returns True if the value is a plain object, false otherwise.
46
+ * @example
47
+ * ```ts
48
+ * isObject({}); // true
49
+ * isObject(new Object()); // true
50
+ * isObject([]); // false
51
+ * isObject(new Date()); // false
52
+ * ```
53
+ */
54
+ declare function isObject<T>(value: T): boolean;
55
+ /**
56
+ * Checks if a value is an empty object (has no enumerable own properties).
57
+ * @param value - The value to check.
58
+ * @returns True if the value is a non-null object with no enumerable own properties, false otherwise.
59
+ * @example
60
+ * ```ts
61
+ * isEmptyObject({}); // true
62
+ * isEmptyObject({ key: 'value' }); // false
63
+ * isEmptyObject(null); // false
64
+ * isEmptyObject([]); // false
65
+ * ```
66
+ */
67
+ declare function isEmptyObject(value: object): boolean;
68
+ /**
69
+ * Checks if a value is a non-empty object (has at least one enumerable own property).
70
+ * @param value - The value to check.
71
+ * @returns True if the value is a non-null object with at least one enumerable own property, false otherwise.
72
+ * @example
73
+ * ```ts
74
+ * isNonEmptyObject({ key: 'value' }); // true
75
+ * isNonEmptyObject({}); // false
76
+ * isNonEmptyObject(null); // false
77
+ * isNonEmptyObject([]); // false
78
+ * ```
79
+ */
80
+ declare function isNonEmptyObject(value: object): boolean;
41
81
 
42
82
  declare const _default: {
43
83
  mergeObj: typeof mergeObj;
84
+ isObject: typeof isObject;
85
+ isEmptyObject: typeof isEmptyObject;
86
+ isNonEmptyObject: typeof isNonEmptyObject;
44
87
  };
45
88
 
46
- export { _default as default, mergeObj };
89
+ export { _default as default, isEmptyObject, isNonEmptyObject, isObject, mergeObj };
@@ -1 +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};
1
+ import{i as t,a as e}from"../validate-D9J7otjc.js";function r(t=!1,...e){const o=t=>"object"==typeof t&&null!==t,n={};for(const c of e)if(o(c))for(const e of Object.keys(c)){const y=c[e],s=n[e];Array.isArray(y)?n[e]=t&&Array.isArray(s)?[...s,...y]:[...y]:o(y)&&!Array.isArray(y)?n[e]=o(s)&&!Array.isArray(s)?r(t,s,y):r(t,{},y):n[e]=y}return n}function o(r){return e(r)&&"object"==typeof r&&!t(r)&&Object.getPrototypeOf(r)===Object.prototype}function n(e){return null!==e&&"object"==typeof e&&0===Object.keys(e).length&&!t(e)}function c(e){return null!==e&&"object"==typeof e&&Object.keys(e).length>0&&!t(e)}var y={mergeObj:r,isObject:o,isEmptyObject:n,isNonEmptyObject:c};export{y as default,n as isEmptyObject,c as isNonEmptyObject,o as isObject,r as mergeObj};
@@ -1 +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;
1
+ "use strict";function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function e(t,e,r=" "){return t.padStart(e,r)}function r(t,e,r=" "){return t.padEnd(e,r)}function s(t,e,r="..."){return t.length>e?t.slice(0,e-r.length)+r:t}function n(t,e){return t.repeat(e)}Object.defineProperty(exports,"__esModule",{value:!0});const i={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function a(t){return null!=t&&"string"==typeof t}function o(t,e=!0){return!!a(t)&&("string"==typeof t&&(e?t.trim().length>0:t.length>0))}function p(t){try{return new URL(t),!0}catch{return!1}}function u(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function c(t){return/^[a-zA-Z]+$/.test(t)}function f(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function x(t){return/[\p{P}]$/u.test(t)}function g(t){return/\s/.test(t)}function m(t){return/^[a-z][a-zA-Z0-9]*$/.test(t)}function h(t){return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function C(t){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(t)}function d(t){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(t)}function z(t){return/^[A-Z]+$/.test(t)}function S(t){return/^[a-z]+$/.test(t)}var N={capitalize:t,padLeft:e,padRight:r,truncate:s,repeatString:n,trim:i,isString:a,isNonEmptyString:o,isURL:p,isEmail:u,isAlphabetic:c,isNumericString:f,startsWithUppercase:l,endsWithPunctuation:x,containsWhitespace:g,isCamelCase:m,isPascalCase:h,isKebabCase:C,isSnakeCase:d,isUpperCase:z,isLowerCase:S};exports.capitalize=t,exports.containsWhitespace=g,exports.default=N,exports.endsWithPunctuation=x,exports.isAlphabetic=c,exports.isCamelCase=m,exports.isEmail=u,exports.isKebabCase=C,exports.isLowerCase=S,exports.isNonEmptyString=o,exports.isNumericString=f,exports.isPascalCase=h,exports.isSnakeCase=d,exports.isString=a,exports.isURL=p,exports.isUpperCase=z,exports.padLeft=e,exports.padRight=r,exports.repeatString=n,exports.startsWithUppercase=l,exports.trim=i,exports.truncate=s;
@@ -1,3 +1,153 @@
1
+ /**
2
+ * String trimming utilities.
3
+ * Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.
4
+ */
5
+ interface Trim {
6
+ /**
7
+ * Removes whitespace from both ends of a string.
8
+ *
9
+ * @param str - The string to trim.
10
+ * @returns The trimmed string.
11
+ */
12
+ function(str: string): string;
13
+ /**
14
+ * Removes leading whitespace from a string.
15
+ *
16
+ * @param str - The string to trim.
17
+ * @returns The string with leading whitespace removed.
18
+ */
19
+ start(str: string): string;
20
+ /**
21
+ * Removes trailing whitespace from a string.
22
+ *
23
+ * @param str - The string to trim.
24
+ * @returns The string with trailing whitespace removed.
25
+ */
26
+ end(str: string): string;
27
+ /**
28
+ * Trims the string and replaces sequences of whitespace with a single space.
29
+ *
30
+ * @param str - The string to normalize.
31
+ * @returns The string with normalized whitespace.
32
+ */
33
+ normalizeWhitespace(str: string): string;
34
+ }
35
+ /**
36
+ * String trimming utilities.
37
+ * Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.
38
+ *
39
+ * @param str - The string to trim.
40
+ *
41
+ * @returns The string with leading and trailing whitespace removed.
42
+ *
43
+ * @remarks
44
+ * - The main callable form behaves like {@link String.prototype.trim}, removing whitespace from both ends.
45
+ * - `.start` removes only leading whitespace (like {@link String.prototype.trimStart}).
46
+ * - `.end` removes only trailing whitespace (like {@link String.prototype.trimEnd}).
47
+ * - `.normalizeWhitespace` trims the string and replaces any sequence of whitespace characters with a single space.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * // Trim both sides
52
+ * console.log(trim(" hello ")); // "hello"
53
+ * console.log(trim("")); // ""
54
+ * console.log(trim("hello")); // "hello"
55
+ *
56
+ * // Trim leading whitespace
57
+ * console.log(trim.start(" hello ")); // "hello "
58
+ * console.log(trim.start("")); // ""
59
+ * console.log(trim.start("hello")); // "hello"
60
+ *
61
+ * // Trim trailing whitespace
62
+ * console.log(trim.end(" hello ")); // " hello"
63
+ * console.log(trim.end("")); // ""
64
+ * console.log(trim.end("hello")); // "hello"
65
+ *
66
+ * // Normalize whitespace
67
+ * console.log(trim.normalizeWhitespace(" hello world ")); // "hello world"
68
+ * console.log(trim.normalizeWhitespace("hello\t world")); // "hello world"
69
+ * console.log(trim.normalizeWhitespace("")); // ""
70
+ * ```
71
+ */
72
+ declare const trim: Trim;
73
+
74
+ /**
75
+ * Capitalizes the first character of a string using a regular expression.
76
+ *
77
+ * @param value - The string to capitalize.
78
+ *
79
+ * @returns The input string with its first character capitalized, or the original string if empty or not a string.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * capitalize("hello"); // "Hello"
84
+ * capitalize("world"); // "World"
85
+ * capitalize(""); // ""
86
+ * capitalize("a"); // "A"
87
+ * ```
88
+ */
89
+ declare function capitalize(value: string): string;
90
+
91
+ /**
92
+ * Pads a string on the left with a specified character until it reaches the desired length.
93
+ * @param str - The string to pad.
94
+ * @param length - The target length of the padded string.
95
+ * @param char - The character to use for padding (defaults to a space).
96
+ * @returns The padded string, or the original string if its length is already greater than or equal to the target length.
97
+ * @example
98
+ * ```ts
99
+ * console.log(padLeft("hello", 8)); // " hello"
100
+ * console.log(padLeft("hi", 5, "*")); // "***hi"
101
+ * console.log(padLeft("hello", 3)); // "hello"
102
+ * console.log(padLeft("", 3, "0")); // "000"
103
+ * ```
104
+ */
105
+ declare function padLeft(str: string, length: number, char?: string): string;
106
+ /**
107
+ * Pads a string on the right with a specified character until it reaches the desired length.
108
+ * @param str - The string to pad.
109
+ * @param length - The target length of the padded string.
110
+ * @param char - The character to use for padding (defaults to a space).
111
+ * @returns The padded string, or the original string if its length is already greater than or equal to the target length.
112
+ * @example
113
+ * ```ts
114
+ * console.log(padRight("hello", 8)); // "hello "
115
+ * console.log(padRight("hi", 5, "*")); // "hi***"
116
+ * console.log(padRight("hello", 3)); // "hello"
117
+ * console.log(padRight("", 3, "0")); // "000"
118
+ * ```
119
+ */
120
+ declare function padRight(str: string, length: number, char?: string): string;
121
+ /**
122
+ * Truncates a string to a specified length, appending a suffix if the string is too long.
123
+ * @param str - The string to truncate.
124
+ * @param length - The maximum length of the resulting string (including the suffix).
125
+ * @param suffix - The suffix to append if truncation occurs (defaults to "...").
126
+ * @returns The truncated string with the suffix if the original string exceeds the length, otherwise the original string.
127
+ * @example
128
+ * ```ts
129
+ * console.log(truncate("hello world", 8)); // "hello..."
130
+ * console.log(truncate("hi", 5)); // "hi"
131
+ * console.log(truncate("hello", 5, "...")); // "he..."
132
+ * console.log(truncate("", 3)); // ""
133
+ * ```
134
+ */
135
+ declare function truncate(str: string, length: number, suffix?: string): string;
136
+ /**
137
+ * Repeats a string a specified number of times.
138
+ * @param str - The string to repeat.
139
+ * @param count - The number of times to repeat the string (must be non-negative).
140
+ * @returns The string repeated the specified number of times.
141
+ * @example
142
+ * ```ts
143
+ * console.log(repeatString("hi", 3)); // "hihihi"
144
+ * console.log(repeatString("a", 2)); // "aa"
145
+ * console.log(repeatString("test", 0)); // ""
146
+ * console.log(repeatString("", 5)); // ""
147
+ * ```
148
+ */
149
+ declare function repeatString(str: string, count: number): string;
150
+
1
151
  /**
2
152
  * Determines whether the provided value is a string.
3
153
  *
@@ -22,7 +172,7 @@
22
172
  * }
23
173
  * ```
24
174
  */
25
- declare function isString<T>(value: T): value is T & string;
175
+ declare function isString<T>(value: T): boolean;
26
176
  /**
27
177
  * Determines whether the given value is a non-empty string.
28
178
  *
@@ -43,11 +193,13 @@ declare function isString<T>(value: T): value is T & string;
43
193
  * @returns - A boolean indicating whether the input is a non-empty string.
44
194
  *
45
195
  * @example
196
+ * ```ts
46
197
  * isNonEmptyString('hello'); // true
47
198
  * isNonEmptyString(' '); // false (trim is true by default)
48
199
  * isNonEmptyString(' ', false); // true (whitespace is counted)
49
200
  * isNonEmptyString(123); // false
50
201
  * isNonEmptyString(null); // false
202
+ * ```
51
203
  */
52
204
  declare function isNonEmptyString<T>(value: T, trim?: boolean): boolean;
53
205
  /**
@@ -60,10 +212,12 @@ declare function isNonEmptyString<T>(value: T, trim?: boolean): boolean;
60
212
  * @returns - `true` if the string is a valid absolute URL; otherwise, `false`.
61
213
  *
62
214
  * @example
215
+ * ```ts
63
216
  * isURL('https://example.com'); // true
64
217
  * isURL('ftp://files.example.com'); // true
65
218
  * isURL('invalid-url'); // false
66
219
  * isURL('/relative/path'); // false
220
+ * ```
67
221
  */
68
222
  declare function isURL(value: string): boolean;
69
223
  /**
@@ -77,10 +231,12 @@ declare function isURL(value: string): boolean;
77
231
  * @returns - `true` if the string is a valid email; otherwise, `false`.
78
232
  *
79
233
  * @example
234
+ * ```ts
80
235
  * isEmail('user@example.com'); // true
81
236
  * isEmail('first.last@college.university.in'); // true
82
237
  * isEmail('invalid-email'); // false
83
238
  * isEmail('name@domain'); // false
239
+ * ```
84
240
  */
85
241
  declare function isEmail(value: string): boolean;
86
242
  /**
@@ -90,9 +246,11 @@ declare function isEmail(value: string): boolean;
90
246
  * @returns - `true` if the string contains only letters; otherwise, `false`.
91
247
  *
92
248
  * @example
249
+ * ```ts
93
250
  * isAlphabetic("Hello"); // true
94
251
  * isAlphabetic("world123"); // false
95
252
  * isAlphabetic("Test!"); // false
253
+ * ```
96
254
  */
97
255
  declare function isAlphabetic(value: string): boolean;
98
256
  /**
@@ -111,27 +269,145 @@ declare function isAlphabetic(value: string): boolean;
111
269
  * @returns - `true` if the string represents a valid number; otherwise, `false`.
112
270
  *
113
271
  * @example
272
+ * ```ts
114
273
  * isNumericString("42"); // true
115
274
  * isNumericString("-3.14"); // true
116
275
  * isNumericString("1e5"); // true
117
276
  * isNumericString(" 123 "); // true
118
277
  * isNumericString("123abc"); // false
119
278
  * isNumericString("abc123"); // false
120
- *
279
+ * ```
121
280
  * See also:
122
281
  * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number()}
123
282
  * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat()}
124
283
  * - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
125
284
  */
126
285
  declare function isNumericString(value: string): boolean;
286
+ /**
287
+ * Checks if a string starts with an uppercase letter.
288
+ * @param value - The input string to check.
289
+ * @returns True if the first character is uppercase, false otherwise.
290
+ * @example
291
+ * ```ts
292
+ * startsWithUppercase('Hello') // true
293
+ * startsWithUppercase('world') // false
294
+ * ```
295
+ */
296
+ declare function startsWithUppercase(value: string): boolean;
297
+ /**
298
+ * Checks if a string ends with any Unicode punctuation character.
299
+ *
300
+ * @param value - The string to check.
301
+ * @returns True if the string ends with a punctuation character.
302
+ * @example
303
+ * ```ts
304
+ * endsWithPunctuation("Hi!") // true
305
+ * endsWithPunctuation("Hello—") // true
306
+ * endsWithPunctuation("Okay") // false
307
+ * ```
308
+ */
309
+ declare function endsWithPunctuation(value: string): boolean;
310
+ /**
311
+ * Checks if a string contains any whitespace.
312
+ * @param value - The string to check.
313
+ * @returns True if the string contains whitespace.
314
+ * @example
315
+ * ```ts
316
+ * containsWhitespace("Hello world") // true
317
+ * containsWhitespace("Nowordspace") // false
318
+ * ```
319
+ */
320
+ declare function containsWhitespace(value: string): boolean;
321
+ /**
322
+ * Checks if a string is in camelCase format.
323
+ * @param value - The input string.
324
+ * @returns True if the string is camelCase.
325
+ * @example
326
+ * ```ts
327
+ * isCamelCase("helloWorld") // true
328
+ * isCamelCase("HelloWorld") // false
329
+ * ```
330
+ */
331
+ declare function isCamelCase(value: string): boolean;
332
+ /**
333
+ * Checks if a string is in PascalCase format.
334
+ * @param value - The input string.
335
+ * @returns True if the string is PascalCase.
336
+ * @example
337
+ * ```ts
338
+ * isPascalCase("HelloWorld") // true
339
+ * isPascalCase("helloWorld") // false
340
+ * ```
341
+ */
342
+ declare function isPascalCase(value: string): boolean;
343
+ /**
344
+ * Checks if a string is in kebab-case format.
345
+ * @param value - The input string.
346
+ * @returns True if the string is kebab-case.
347
+ * @example
348
+ * ```ts
349
+ * isKebabCase("hello-world") // true
350
+ * isKebabCase("hello_world") // false
351
+ * ```
352
+ */
353
+ declare function isKebabCase(value: string): boolean;
354
+ /**
355
+ * Checks if a string is in snake_case format.
356
+ * @param value - The input string.
357
+ * @returns True if the string is snake_case.
358
+ * @example
359
+ * ```ts
360
+ * isSnakeCase("hello_world") // true
361
+ * isSnakeCase("hello-world") // false
362
+ * ```
363
+ */
364
+ declare function isSnakeCase(value: string): boolean;
365
+ /**
366
+ * Checks if a string contains only uppercase letters.
367
+ * @param value - The input string.
368
+ * @returns True if all letters are uppercase.
369
+ * @example
370
+ * ```ts
371
+ * isUpperCase("HELLO") // true
372
+ * isUpperCase("Hello") // false
373
+ * ```
374
+ */
375
+ declare function isUpperCase(value: string): boolean;
376
+ /**
377
+ * Checks if a string contains only lowercase letters.
378
+ * @param value - The input string.
379
+ * @returns True if all letters are lowercase.
380
+ * @example
381
+ * ```ts
382
+ * isLowerCase("hello") // true
383
+ * isLowerCase("Hello") // false
384
+ * ```
385
+ */
386
+ declare function isLowerCase(value: string): boolean;
127
387
 
128
388
  declare const _default: {
389
+ capitalize: typeof capitalize;
390
+ padLeft: typeof padLeft;
391
+ padRight: typeof padRight;
392
+ truncate: typeof truncate;
393
+ repeatString: typeof repeatString;
394
+ trim: Trim;
129
395
  isString: typeof isString;
130
396
  isNonEmptyString: typeof isNonEmptyString;
131
397
  isURL: typeof isURL;
132
398
  isEmail: typeof isEmail;
133
399
  isAlphabetic: typeof isAlphabetic;
134
400
  isNumericString: typeof isNumericString;
401
+ startsWithUppercase: typeof startsWithUppercase;
402
+ endsWithPunctuation: typeof endsWithPunctuation;
403
+ containsWhitespace: typeof containsWhitespace;
404
+ isCamelCase: typeof isCamelCase;
405
+ isPascalCase: typeof isPascalCase;
406
+ isKebabCase: typeof isKebabCase;
407
+ isSnakeCase: typeof isSnakeCase;
408
+ isUpperCase: typeof isUpperCase;
409
+ isLowerCase: typeof isLowerCase;
135
410
  };
136
411
 
137
- export { _default as default, isAlphabetic, isEmail, isNonEmptyString, isNumericString, isString, isURL };
412
+ export { capitalize, containsWhitespace, _default as default, endsWithPunctuation, isAlphabetic, isCamelCase, isEmail, isKebabCase, isLowerCase, isNonEmptyString, isNumericString, isPascalCase, isSnakeCase, isString, isURL, isUpperCase, padLeft, padRight, repeatString, startsWithUppercase, trim, truncate };
413
+ export type { Trim };
@@ -1 +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};
1
+ function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function n(t,n,e=" "){return t.padStart(n,e)}function e(t,n,e=" "){return t.padEnd(n,e)}function r(t,n,e="..."){return t.length>n?t.slice(0,n-e.length)+e:t}function i(t,n){return t.repeat(n)}const a={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function s(t){return null!=t&&"string"==typeof t}function u(t,n=!0){return!!s(t)&&("string"==typeof t&&(n?t.trim().length>0:t.length>0))}function c(t){try{return new URL(t),!0}catch{return!1}}function o(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function f(t){return/^[a-zA-Z]+$/.test(t)}function p(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function g(t){return/[\p{P}]$/u.test(t)}function m(t){return/\s/.test(t)}function h(t){return/^[a-z][a-zA-Z0-9]*$/.test(t)}function z(t){return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function d(t){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(t)}function $(t){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(t)}function C(t){return/^[A-Z]+$/.test(t)}function A(t){return/^[a-z]+$/.test(t)}var N={capitalize:t,padLeft:n,padRight:e,truncate:r,repeatString:i,trim:a,isString:s,isNonEmptyString:u,isURL:c,isEmail:o,isAlphabetic:f,isNumericString:p,startsWithUppercase:l,endsWithPunctuation:g,containsWhitespace:m,isCamelCase:h,isPascalCase:z,isKebabCase:d,isSnakeCase:$,isUpperCase:C,isLowerCase:A};export{t as capitalize,m as containsWhitespace,N as default,g as endsWithPunctuation,f as isAlphabetic,h as isCamelCase,o as isEmail,d as isKebabCase,A as isLowerCase,u as isNonEmptyString,p as isNumericString,z as isPascalCase,$ as isSnakeCase,s as isString,c as isURL,C as isUpperCase,n as padLeft,e as padRight,i as repeatString,l as startsWithUppercase,a as trim,r as truncate};
@@ -0,0 +1 @@
1
+ "use strict";function r(r){return null!=r}exports.isArray=function(n){return r(n)&&Array.isArray(n)},exports.isDefined=r,exports.isUndefinedOrNull=function(r){return null==r};
@@ -0,0 +1 @@
1
+ function n(n){return null!=n}function r(n){return null==n}function u(r){return n(r)&&Array.isArray(r)}export{n as a,r as b,u as i};
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "js-utils-kit",
3
3
  "displayName": "JS Utils Kit",
4
- "version": "0.2.3",
4
+ "version": "0.3.1",
5
5
  "description": "Essential JavaScript helpers",
6
6
  "license": "MIT",
7
7
  "private": false,
8
- "repository": "https://github.com/TenEplaysOfficial/js-utils-kit",
8
+ "repository": "https://github.com/teneplaysofficial/js-utils-kit",
9
9
  "bugs": {
10
- "url": "https://github.com/TenEplaysOfficial/js-utils-kit/issues"
10
+ "url": "https://github.com/teneplaysofficial/js-utils-kit/issues"
11
11
  },
12
12
  "author": {
13
13
  "name": "Sriman",
@@ -52,6 +52,11 @@
52
52
  "require": "./dist/index.cjs",
53
53
  "types": "./dist/index.d.ts"
54
54
  },
55
+ "./array": {
56
+ "import": "./dist/array/index.js",
57
+ "require": "./dist/array/index.cjs",
58
+ "types": "./dist/array/index.d.ts"
59
+ },
55
60
  "./char": {
56
61
  "import": "./dist/char/index.js",
57
62
  "require": "./dist/char/index.cjs",
@@ -110,8 +115,8 @@
110
115
  },
111
116
  "devDependencies": {
112
117
  "@eslint/js": "^9.29.0",
113
- "@eslint/json": "^0.12.0",
114
- "@eslint/markdown": "^6.6.0",
118
+ "@eslint/json": "^0.13.0",
119
+ "@eslint/markdown": "^7.0.0",
115
120
  "@release-it/conventional-changelog": "^10.0.1",
116
121
  "@rollup/plugin-commonjs": "^28.0.6",
117
122
  "@rollup/plugin-node-resolve": "^16.0.1",