@pixpilot/string 2.5.0 → 3.0.0

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/README.md CHANGED
@@ -50,7 +50,7 @@ if (isString(value)) {
50
50
 
51
51
  ### Validation Functions
52
52
 
53
- - `isEmpty(str: string, trimWhitespace?: boolean): boolean` - Check if a string is empty
53
+ - `isEmptyString(str: string, trimWhitespace?: boolean): boolean` - Check if a string is empty
54
54
  - `isAlphanumeric(str: string): boolean` - Check if a string contains only alphanumeric characters
55
55
  - `isEmail(str: string): boolean` - Check if a string is a valid email address
56
56
  - `isUrl(str: string): boolean` - Check if a string is a valid URL
package/dist/index.cjs CHANGED
@@ -8,7 +8,8 @@ exports.capitalizeFirst = require_manipulation.capitalizeFirst;
8
8
  exports.countOccurrences = require_manipulation.countOccurrences;
9
9
  exports.isAlphanumeric = require_validation.isAlphanumeric;
10
10
  exports.isEmail = require_validation.isEmail;
11
- exports.isEmpty = require_validation.isEmpty;
11
+ exports.isEmptyString = require_validation.isEmptyString;
12
+ exports.isEmptyStringOrNil = require_validation.isEmptyStringOrNil;
12
13
  exports.isString = require_type_guards.isString;
13
14
  exports.isUrl = require_validation.isUrl;
14
15
  exports.normalizeSpaces = require_manipulation.normalizeSpaces;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.cjs";
2
2
  import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.cjs";
3
3
  import { isString } from "./type-guards.cjs";
4
- import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.cjs";
5
- export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
4
+ import { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl } from "./validation.cjs";
5
+ export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.js";
2
2
  import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.js";
3
3
  import { isString } from "./type-guards.js";
4
- import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.js";
5
- export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
4
+ import { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl } from "./validation.js";
5
+ export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.js";
2
2
  import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.js";
3
3
  import { isString } from "./type-guards.js";
4
- import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.js";
4
+ import { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl } from "./validation.js";
5
5
 
6
- export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
6
+ export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
@@ -8,16 +8,26 @@
8
8
  * @returns True if the string is empty, false otherwise
9
9
  *
10
10
  * @example
11
- * ```typescript
12
- * isEmpty(''); // true
13
- * isEmpty(' '); // true
14
- * isEmpty(' ', false); // false
15
- * isEmpty('hello'); // false
16
- * ```
11
+ * isEmpty(''); // true
12
+ * isEmpty(' '); // true
13
+ * isEmpty('hello'); // false
14
+ */
15
+ function isEmptyString(str, trimWhitespace = true) {
16
+ return trimWhitespace ? str.trim().length === 0 : str.length === 0;
17
+ }
18
+ /**
19
+ * Like isEmptyString, but also returns true for null or undefined.
20
+ * Use this when working with optional fields, API responses, or environment variables.
21
+ *
22
+ * @example
23
+ * isEmptyStringOrNil(null); // true
24
+ * isEmptyStringOrNil(undefined); // true
25
+ * isEmptyStringOrNil(' '); // true
26
+ * isEmptyStringOrNil('hello'); // false
17
27
  */
18
- function isEmpty(str, trimWhitespace = true) {
19
- if (trimWhitespace) return str.trim().length === 0;
20
- return str.length === 0;
28
+ function isEmptyStringOrNil(str, trimWhitespace = true) {
29
+ if (str == null) return true;
30
+ return isEmptyString(str, trimWhitespace);
21
31
  }
22
32
  /**
23
33
  * Check if a string contains only alphanumeric characters.
@@ -74,5 +84,6 @@ function isUrl(str) {
74
84
  //#endregion
75
85
  exports.isAlphanumeric = isAlphanumeric;
76
86
  exports.isEmail = isEmail;
77
- exports.isEmpty = isEmpty;
87
+ exports.isEmptyString = isEmptyString;
88
+ exports.isEmptyStringOrNil = isEmptyStringOrNil;
78
89
  exports.isUrl = isUrl;
@@ -7,14 +7,22 @@
7
7
  * @returns True if the string is empty, false otherwise
8
8
  *
9
9
  * @example
10
- * ```typescript
11
- * isEmpty(''); // true
12
- * isEmpty(' '); // true
13
- * isEmpty(' ', false); // false
14
- * isEmpty('hello'); // false
15
- * ```
10
+ * isEmpty(''); // true
11
+ * isEmpty(' '); // true
12
+ * isEmpty('hello'); // false
13
+ */
14
+ declare function isEmptyString(str: string, trimWhitespace?: boolean): boolean;
15
+ /**
16
+ * Like isEmptyString, but also returns true for null or undefined.
17
+ * Use this when working with optional fields, API responses, or environment variables.
18
+ *
19
+ * @example
20
+ * isEmptyStringOrNil(null); // true
21
+ * isEmptyStringOrNil(undefined); // true
22
+ * isEmptyStringOrNil(' '); // true
23
+ * isEmptyStringOrNil('hello'); // false
16
24
  */
17
- declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
25
+ declare function isEmptyStringOrNil(str: string | null | undefined, trimWhitespace?: boolean): boolean;
18
26
  /**
19
27
  * Check if a string contains only alphanumeric characters.
20
28
  *
@@ -56,4 +64,4 @@ declare function isEmail(str: string): boolean;
56
64
  */
57
65
  declare function isUrl(str: string): boolean;
58
66
  //#endregion
59
- export { isAlphanumeric, isEmail, isEmpty, isUrl };
67
+ export { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl };
@@ -7,14 +7,22 @@
7
7
  * @returns True if the string is empty, false otherwise
8
8
  *
9
9
  * @example
10
- * ```typescript
11
- * isEmpty(''); // true
12
- * isEmpty(' '); // true
13
- * isEmpty(' ', false); // false
14
- * isEmpty('hello'); // false
15
- * ```
10
+ * isEmpty(''); // true
11
+ * isEmpty(' '); // true
12
+ * isEmpty('hello'); // false
13
+ */
14
+ declare function isEmptyString(str: string, trimWhitespace?: boolean): boolean;
15
+ /**
16
+ * Like isEmptyString, but also returns true for null or undefined.
17
+ * Use this when working with optional fields, API responses, or environment variables.
18
+ *
19
+ * @example
20
+ * isEmptyStringOrNil(null); // true
21
+ * isEmptyStringOrNil(undefined); // true
22
+ * isEmptyStringOrNil(' '); // true
23
+ * isEmptyStringOrNil('hello'); // false
16
24
  */
17
- declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
25
+ declare function isEmptyStringOrNil(str: string | null | undefined, trimWhitespace?: boolean): boolean;
18
26
  /**
19
27
  * Check if a string contains only alphanumeric characters.
20
28
  *
@@ -56,4 +64,4 @@ declare function isEmail(str: string): boolean;
56
64
  */
57
65
  declare function isUrl(str: string): boolean;
58
66
  //#endregion
59
- export { isAlphanumeric, isEmail, isEmpty, isUrl };
67
+ export { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl };
@@ -7,16 +7,26 @@
7
7
  * @returns True if the string is empty, false otherwise
8
8
  *
9
9
  * @example
10
- * ```typescript
11
- * isEmpty(''); // true
12
- * isEmpty(' '); // true
13
- * isEmpty(' ', false); // false
14
- * isEmpty('hello'); // false
15
- * ```
10
+ * isEmpty(''); // true
11
+ * isEmpty(' '); // true
12
+ * isEmpty('hello'); // false
13
+ */
14
+ function isEmptyString(str, trimWhitespace = true) {
15
+ return trimWhitespace ? str.trim().length === 0 : str.length === 0;
16
+ }
17
+ /**
18
+ * Like isEmptyString, but also returns true for null or undefined.
19
+ * Use this when working with optional fields, API responses, or environment variables.
20
+ *
21
+ * @example
22
+ * isEmptyStringOrNil(null); // true
23
+ * isEmptyStringOrNil(undefined); // true
24
+ * isEmptyStringOrNil(' '); // true
25
+ * isEmptyStringOrNil('hello'); // false
16
26
  */
17
- function isEmpty(str, trimWhitespace = true) {
18
- if (trimWhitespace) return str.trim().length === 0;
19
- return str.length === 0;
27
+ function isEmptyStringOrNil(str, trimWhitespace = true) {
28
+ if (str == null) return true;
29
+ return isEmptyString(str, trimWhitespace);
20
30
  }
21
31
  /**
22
32
  * Check if a string contains only alphanumeric characters.
@@ -71,4 +81,4 @@ function isUrl(str) {
71
81
  }
72
82
 
73
83
  //#endregion
74
- export { isAlphanumeric, isEmail, isEmpty, isUrl };
84
+ export { isAlphanumeric, isEmail, isEmptyString, isEmptyStringOrNil, isUrl };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixpilot/string",
3
3
  "type": "module",
4
- "version": "2.5.0",
4
+ "version": "3.0.0",
5
5
  "description": "A collection of utility functions for string manipulation and validation.",
6
6
  "author": "Pixpilot <m.doaie@hotmail.com>",
7
7
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "typescript": "^5.9.3",
35
35
  "@internal/eslint-config": "0.3.0",
36
36
  "@internal/prettier-config": "0.0.1",
37
- "@internal/tsconfig": "0.1.0",
38
37
  "@internal/tsdown-config": "0.1.0",
39
- "@internal/vitest-config": "0.1.0"
38
+ "@internal/vitest-config": "0.1.0",
39
+ "@internal/tsconfig": "0.1.0"
40
40
  },
41
41
  "prettier": "@internal/prettier-config",
42
42
  "scripts": {