phane-js-utils 1.0.8 → 1.0.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 phane-tech
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/README.md CHANGED
@@ -1,27 +1,27 @@
1
1
  <a name="module_DataTypeCheck"></a>
2
2
 
3
3
  ## DataTypeCheck
4
- Data Check helpers.
4
+ Data Type Check helpers.
5
5
 
6
6
 
7
7
  * [DataTypeCheck](#module_DataTypeCheck)
8
- * [.checkIsNumber(userInput)](#module_DataTypeCheck.checkIsNumber) ⇒ <code>boolean</code> \| <code>undefined</code>
9
- * [.checkIsString(userInput)](#module_DataTypeCheck.checkIsString) ⇒ <code>boolean</code> \| <code>undefined</code>
10
- * [.checkIsBoolean(userInput)](#module_DataTypeCheck.checkIsBoolean) ⇒ <code>boolean</code> \| <code>undefined</code>
11
- * [.checkIsBigint(userInput)](#module_DataTypeCheck.checkIsBigint) ⇒ <code>boolean</code> \| <code>undefined</code>
12
- * [.checkIsFunction(userInput)](#module_DataTypeCheck.checkIsFunction) ⇒ <code>boolean</code> \| <code>undefined</code>
13
- * [.checkIsObject(userInput)](#module_DataTypeCheck.checkIsObject) ⇒ <code>boolean</code> \| <code>undefined</code>
8
+ * [.checkIsNumber(userInput)](#module_DataTypeCheck.checkIsNumber) ⇒ <code>boolean</code>
9
+ * [.checkIsString(userInput)](#module_DataTypeCheck.checkIsString) ⇒ <code>boolean</code>
10
+ * [.checkIsBoolean(userInput)](#module_DataTypeCheck.checkIsBoolean) ⇒ <code>boolean</code>
11
+ * [.checkIsBigint(userInput)](#module_DataTypeCheck.checkIsBigint) ⇒ <code>boolean</code>
12
+ * [.checkIsFunction(userInput)](#module_DataTypeCheck.checkIsFunction) ⇒ <code>boolean</code>
13
+ * [.checkIsObject(userInput)](#module_DataTypeCheck.checkIsObject) ⇒ <code>boolean</code>
14
14
  * [.checkObjectLength(userInput)](#module_DataTypeCheck.checkObjectLength) ⇒ <code>number</code> \| <code>undefined</code>
15
- * [.checkIsArray(userInput)](#module_DataTypeCheck.checkIsArray) ⇒ <code>boolean</code> \| <code>undefined</code>
15
+ * [.checkIsArray(userInput)](#module_DataTypeCheck.checkIsArray) ⇒ <code>boolean</code>
16
16
  * [.checkArrayLength(userInput)](#module_DataTypeCheck.checkArrayLength) ⇒ <code>number</code> \| <code>undefined</code>
17
17
 
18
18
  <a name="module_DataTypeCheck.checkIsNumber"></a>
19
19
 
20
- ### DataTypeCheck.checkIsNumber(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
20
+ ### DataTypeCheck.checkIsNumber(userInput) ⇒ <code>boolean</code>
21
21
  Check if the user input is a number or not.
22
22
 
23
23
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
24
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if number, false if not, undefined if input is null/undefined
24
+ **Returns**: <code>boolean</code> - Returns true if number, false if not
25
25
 
26
26
  | Param | Type | Description |
27
27
  | --- | --- | --- |
@@ -29,15 +29,15 @@ Check if the user input is a number or not.
29
29
 
30
30
  **Example**
31
31
  ```js
32
- checkIsNumber(37) => true
32
+ checkIsNumber(37) => true
33
33
  ```
34
34
  <a name="module_DataTypeCheck.checkIsString"></a>
35
35
 
36
- ### DataTypeCheck.checkIsString(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
36
+ ### DataTypeCheck.checkIsString(userInput) ⇒ <code>boolean</code>
37
37
  Check if the user input is a string or not.
38
38
 
39
39
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
40
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if string, false if not, undefined if input is null/undefined
40
+ **Returns**: <code>boolean</code> - Returns true if string, false if not
41
41
 
42
42
  | Param | Type | Description |
43
43
  | --- | --- | --- |
@@ -45,15 +45,15 @@ Check if the user input is a string or not.
45
45
 
46
46
  **Example**
47
47
  ```js
48
- checkIsString(37) => false
48
+ checkIsString(37) // false
49
49
  ```
50
50
  <a name="module_DataTypeCheck.checkIsBoolean"></a>
51
51
 
52
- ### DataTypeCheck.checkIsBoolean(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
52
+ ### DataTypeCheck.checkIsBoolean(userInput) ⇒ <code>boolean</code>
53
53
  Check if the user input is a boolean or not.
54
54
 
55
55
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
56
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if boolean, false if not, undefined if input is null/undefined
56
+ **Returns**: <code>boolean</code> - Returns true if boolean, false if not
57
57
 
58
58
  | Param | Type | Description |
59
59
  | --- | --- | --- |
@@ -61,15 +61,15 @@ Check if the user input is a boolean or not.
61
61
 
62
62
  **Example**
63
63
  ```js
64
- checkIsBoolean(37) => false
64
+ checkIsBoolean(37) => false
65
65
  ```
66
66
  <a name="module_DataTypeCheck.checkIsBigint"></a>
67
67
 
68
- ### DataTypeCheck.checkIsBigint(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
68
+ ### DataTypeCheck.checkIsBigint(userInput) ⇒ <code>boolean</code>
69
69
  Check if the user input is a Bigint or not.
70
70
 
71
71
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
72
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if bigint, false if not, undefined if input is null/undefined
72
+ **Returns**: <code>boolean</code> - Returns true if bigint, false if not
73
73
 
74
74
  | Param | Type | Description |
75
75
  | --- | --- | --- |
@@ -77,15 +77,15 @@ Check if the user input is a Bigint or not.
77
77
 
78
78
  **Example**
79
79
  ```js
80
- checkIsBigint(37n) => true
80
+ checkIsBigint(37n) => true
81
81
  ```
82
82
  <a name="module_DataTypeCheck.checkIsFunction"></a>
83
83
 
84
- ### DataTypeCheck.checkIsFunction(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
84
+ ### DataTypeCheck.checkIsFunction(userInput) ⇒ <code>boolean</code>
85
85
  Check if the user input is a function.
86
86
 
87
87
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
88
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if function, false if not, undefined if input is null/undefined
88
+ **Returns**: <code>boolean</code> - Returns true if function, false if not
89
89
 
90
90
  | Param | Type | Description |
91
91
  | --- | --- | --- |
@@ -93,15 +93,15 @@ Check if the user input is a function.
93
93
 
94
94
  **Example**
95
95
  ```js
96
- checkIsFunction(function() {}) => true
96
+ checkIsFunction(function() {}) => true
97
97
  ```
98
98
  <a name="module_DataTypeCheck.checkIsObject"></a>
99
99
 
100
- ### DataTypeCheck.checkIsObject(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
100
+ ### DataTypeCheck.checkIsObject(userInput) ⇒ <code>boolean</code>
101
101
  Check if the user input is an object.
102
102
 
103
103
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
104
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if object, false if not, undefined if input is null/undefined
104
+ **Returns**: <code>boolean</code> - Returns true if object, false if not
105
105
 
106
106
  | Param | Type | Description |
107
107
  | --- | --- | --- |
@@ -109,7 +109,7 @@ Check if the user input is an object.
109
109
 
110
110
  **Example**
111
111
  ```js
112
- checkIsObject({}) => true
112
+ checkIsObject({}) // true
113
113
  ```
114
114
  <a name="module_DataTypeCheck.checkObjectLength"></a>
115
115
 
@@ -125,15 +125,15 @@ Get the number of key-value pairs in an object.
125
125
 
126
126
  **Example**
127
127
  ```js
128
- checkObjectLength({ a: 1, b: 2 }) => 2
128
+ checkObjectLength({ a: 1, b: 2 }) => 2
129
129
  ```
130
130
  <a name="module_DataTypeCheck.checkIsArray"></a>
131
131
 
132
- ### DataTypeCheck.checkIsArray(userInput) ⇒ <code>boolean</code> \| <code>undefined</code>
132
+ ### DataTypeCheck.checkIsArray(userInput) ⇒ <code>boolean</code>
133
133
  Check if the user input is an array.
134
134
 
135
135
  **Kind**: static method of [<code>DataTypeCheck</code>](#module_DataTypeCheck)
136
- **Returns**: <code>boolean</code> \| <code>undefined</code> - Returns true if array, false if not, undefined if input is null/undefined
136
+ **Returns**: <code>boolean</code> - Returns true if array, false if not
137
137
 
138
138
  | Param | Type | Description |
139
139
  | --- | --- | --- |
@@ -141,7 +141,7 @@ Check if the user input is an array.
141
141
 
142
142
  **Example**
143
143
  ```js
144
- checkIsArray([1, 2, 3]) => true
144
+ checkIsArray([1, 2, 3]) => true
145
145
  ```
146
146
  <a name="module_DataTypeCheck.checkArrayLength"></a>
147
147
 
@@ -157,5 +157,5 @@ Get the length of an array.
157
157
 
158
158
  **Example**
159
159
  ```js
160
- checkArrayLength([1, 2, 3]) => 3
160
+ checkArrayLength([1, 2, 3]) => 3
161
161
  ```
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./js/index.js";
1
+ export * from "./js/dataTypeCheck.js";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Data Check helpers.
2
+ * Data Type Check helpers.
3
3
  * @module DataTypeCheck
4
4
  */
5
5
 
@@ -10,20 +10,21 @@
10
10
  * @memberof module:DataTypeCheck
11
11
  *
12
12
  * @param {*} userInput - Any value to check
13
- * @returns {boolean|undefined} Returns true if number, false if not, undefined if input is null/undefined
13
+ * @returns {boolean} Returns true if number, false if not
14
14
  *
15
15
  * @example
16
16
  * checkIsNumber(37) => true
17
17
  *
18
18
  * checkIsNumber("hello") => false
19
19
  *
20
- * checkIsNumber() => undefined
20
+ * checkIsNumber() => false
21
21
  *
22
- * checkIsNumber(null) => undefined
22
+ * checkIsNumber(null) => false
23
23
  *
24
+ * checkIsNumber(undefined) => false
24
25
  */
26
+
25
27
  export function checkIsNumber(userInput) {
26
- if (userInput === null || userInput === undefined) return undefined;
27
28
  return typeof userInput === "number";
28
29
  }
29
30
 
@@ -34,20 +35,20 @@ export function checkIsNumber(userInput) {
34
35
  * @memberof module:DataTypeCheck
35
36
  *
36
37
  * @param {*} userInput - Any value to check
37
- * @returns {boolean|undefined} Returns true if string, false if not, undefined if input is null/undefined
38
+ * @returns {boolean} Returns true if string, false if not
38
39
  *
39
- * @example
40
- * checkIsString(37) => false
40
+ * @example
41
+ * checkIsString(37) // false
41
42
  *
42
- * checkIsString("hello") => true
43
+ * checkIsString("hello") // true
43
44
  *
44
- * checkIsString() => undefined
45
+ * checkIsString() // false
45
46
  *
46
- * checkIsString(null) => undefined
47
+ * checkIsString(null) // false
47
48
  *
49
+ * checkIsString(undefined) // false
48
50
  */
49
51
  export function checkIsString(userInput) {
50
- if (userInput === null || userInput === undefined) return undefined;
51
52
  return typeof userInput === "string";
52
53
  }
53
54
 
@@ -58,7 +59,7 @@ export function checkIsString(userInput) {
58
59
  * @memberof module:DataTypeCheck
59
60
  *
60
61
  * @param {*} userInput - Any value to check
61
- * @returns {boolean|undefined} Returns true if boolean, false if not, undefined if input is null/undefined
62
+ * @returns {boolean} Returns true if boolean, false if not
62
63
  *
63
64
  * @example
64
65
  * checkIsBoolean(37) => false
@@ -67,13 +68,12 @@ export function checkIsString(userInput) {
67
68
  *
68
69
  * checkIsBoolean(false) => true
69
70
  *
70
- * checkIsBoolean() => undefined
71
+ * checkIsBoolean() => false
71
72
  *
72
- * checkIsBoolean(null) => undefined
73
+ * checkIsBoolean(null) => false
73
74
  *
74
75
  */
75
76
  export function checkIsBoolean(userInput) {
76
- if (userInput === null || userInput === undefined) return undefined;
77
77
  return typeof userInput === "boolean";
78
78
  }
79
79
 
@@ -84,7 +84,7 @@ export function checkIsBoolean(userInput) {
84
84
  * @memberof module:DataTypeCheck
85
85
  *
86
86
  * @param {*} userInput - Any value to check
87
- * @returns {boolean|undefined} Returns true if bigint, false if not, undefined if input is null/undefined
87
+ * @returns {boolean} Returns true if bigint, false if not
88
88
  *
89
89
  * @example
90
90
  * checkIsBigint(37n) => true
@@ -93,12 +93,11 @@ export function checkIsBoolean(userInput) {
93
93
  *
94
94
  * checkIsBigint(37) => false
95
95
  *
96
- * checkIsBigint() => undefined
96
+ * checkIsBigint() => false
97
97
  *
98
- * checkIsBigint(null) => undefined
98
+ * checkIsBigint(null) => false
99
99
  */
100
100
  export function checkIsBigint(userInput) {
101
- if (userInput === null || userInput === undefined) return undefined;
102
101
  return typeof userInput === "bigint";
103
102
  }
104
103
 
@@ -109,7 +108,7 @@ export function checkIsBigint(userInput) {
109
108
  * @memberof module:DataTypeCheck
110
109
  *
111
110
  * @param {*} userInput - Any value to check
112
- * @returns {boolean|undefined} Returns true if function, false if not, undefined if input is null/undefined
111
+ * @returns {boolean} Returns true if function, false if not
113
112
  *
114
113
  * @example
115
114
  * checkIsFunction(function() {}) => true
@@ -118,12 +117,11 @@ export function checkIsBigint(userInput) {
118
117
  *
119
118
  * checkIsFunction(42) => false
120
119
  *
121
- * checkIsFunction(null) => undefined
120
+ * checkIsFunction(null) => false
122
121
  *
123
- * checkIsFunction() => undefined
122
+ * checkIsFunction() => false
124
123
  */
125
124
  export function checkIsFunction(userInput) {
126
- if (userInput === null || userInput === undefined) return undefined;
127
125
  return typeof userInput === "function";
128
126
  }
129
127
 
@@ -134,22 +132,21 @@ export function checkIsFunction(userInput) {
134
132
  * @memberof module:DataTypeCheck
135
133
  *
136
134
  * @param {*} userInput - Any value to check
137
- * @returns {boolean|undefined} Returns true if object, false if not, undefined if input is null/undefined
135
+ * @returns {boolean} Returns true if object, false if not
138
136
  *
139
137
  * @example
140
- * checkIsObject({}) => true
138
+ * checkIsObject({}) // true
141
139
  *
142
- * checkIsObject({ a: 1 }) => true
140
+ * checkIsObject({ a: 1 }) // true
143
141
  *
144
- * checkIsObject([]) => true (arrays are objects in JavaScript)
142
+ * checkIsObject([]) // false
145
143
  *
146
- * checkIsObject(null) => undefined
144
+ * checkIsObject(null) // false
147
145
  *
148
- * checkIsObject(42) => false
146
+ * checkIsObject(42) // false
149
147
  */
150
148
  export function checkIsObject(userInput) {
151
- if (userInput === null || userInput === undefined) return undefined;
152
- return typeof userInput === "object";
149
+ return (typeof userInput === "object" && userInput !== null && !Array.isArray(userInput));
153
150
  }
154
151
 
155
152
  /**
@@ -166,7 +163,7 @@ export function checkIsObject(userInput) {
166
163
  *
167
164
  * checkObjectLength({}) => 0
168
165
  *
169
- * checkObjectLength([]) => 0 (arrays are objects in JavaScript)
166
+ * checkObjectLength([]) => undefined
170
167
  *
171
168
  * checkObjectLength(null) => undefined
172
169
  *
@@ -184,7 +181,7 @@ export function checkObjectLength(userInput) {
184
181
  * @memberof module:DataTypeCheck
185
182
  *
186
183
  * @param {*} userInput - Any value to check
187
- * @returns {boolean|undefined} Returns true if array, false if not, undefined if input is null/undefined
184
+ * @returns {boolean} Returns true if array, false if not
188
185
  *
189
186
  * @example
190
187
  * checkIsArray([1, 2, 3]) => true
@@ -193,12 +190,15 @@ export function checkObjectLength(userInput) {
193
190
  *
194
191
  * checkIsArray({}) => false
195
192
  *
196
- * checkIsArray(null) => undefined
193
+ * checkIsArray(null) => false
194
+ *
195
+ * checkIsArray() => false
196
+ *
197
+ * checkIsArray(undefined) => false
197
198
  *
198
199
  * checkIsArray(42) => false
199
200
  */
200
201
  export function checkIsArray(userInput) {
201
- if (userInput === null || userInput === undefined) return undefined;
202
202
  return Array.isArray(userInput);
203
203
  }
204
204
 
@@ -217,6 +217,8 @@ export function checkIsArray(userInput) {
217
217
  * checkArrayLength([]) => 0
218
218
  *
219
219
  * checkArrayLength({}) => undefined
220
+ *
221
+ * checkArrayLength() => undefined
220
222
  *
221
223
  * checkArrayLength(null) => undefined
222
224
  *
@@ -7,157 +7,243 @@ import {
7
7
  checkIsObject,
8
8
  checkObjectLength,
9
9
  checkIsArray,
10
- checkArrayLength
11
- } from './dataTypeCheck.js';
10
+ checkArrayLength,
11
+ } from "./dataTypeCheck.js";
12
12
 
13
+ describe("Check Is Number Function", () => {
14
+ test("42 should return true", () => expect(checkIsNumber(42)).toBe(true));
15
+ test("0 should return true", () => expect(checkIsNumber(0)).toBe(true));
16
+ test("-1 should return true", () => expect(checkIsNumber(-1)).toBe(true));
17
+ test("NaN should return true", () => expect(checkIsNumber(NaN)).toBe(true));
18
+ test("Infinity should return true", () =>
19
+ expect(checkIsNumber(Infinity)).toBe(true));
20
+ test('"hello" should return false', () =>
21
+ expect(checkIsNumber("hello")).toBe(false));
22
+ test("true should return false", () =>
23
+ expect(checkIsNumber(true)).toBe(false));
24
+ test("false should return false", () =>
25
+ expect(checkIsNumber(false)).toBe(false));
26
+ test("[] should return false", () => expect(checkIsNumber([])).toBe(false));
27
+ test("{} should return false", () => expect(checkIsNumber({})).toBe(false));
28
+ test("() => {} should return false", () =>
29
+ expect(checkIsNumber(() => {})).toBe(false));
30
+ test("123n should return false", () =>
31
+ expect(checkIsNumber(123n)).toBe(false));
32
+ test("null should return false", () =>
33
+ expect(checkIsNumber(null)).toBe(false));
34
+ test("undefined should return false", () =>
35
+ expect(checkIsNumber(undefined)).toBe(false));
36
+ test("new Number(42) should return false", () =>
37
+ expect(checkIsNumber(new Number(42))).toBe(false));
38
+ test("3.14 should return true", () => expect(checkIsNumber(3.14)).toBe(true));
39
+ test("-Infinity should return true", () =>
40
+ expect(checkIsNumber(-Infinity)).toBe(true));
41
+ test("1e5 should return true", () => expect(checkIsNumber(1e5)).toBe(true));
42
+ test('"42" should return false', () =>
43
+ expect(checkIsNumber("42")).toBe(false));
44
+ test('Symbol("42") should return false', () =>
45
+ expect(checkIsNumber(Symbol("42"))).toBe(false));
46
+ test("0n should return false", () => expect(checkIsNumber(0n)).toBe(false));
47
+ });
13
48
 
14
- describe("DataTypeCheck Helpers - Comprehensive Tests", () => {
49
+ describe("Check Is String Function", () => {
50
+ test('"hello" should return true', () =>
51
+ expect(checkIsString("hello")).toBe(true));
52
+ test('"" should return true', () => expect(checkIsString("")).toBe(true));
53
+ test('"123" should return true', () =>
54
+ expect(checkIsString("123")).toBe(true));
55
+ test("42 should return false", () => expect(checkIsString(42)).toBe(false));
56
+ test("true should return false", () =>
57
+ expect(checkIsString(true)).toBe(false));
58
+ test("false should return false", () =>
59
+ expect(checkIsString(false)).toBe(false));
60
+ test("[] should return false", () => expect(checkIsString([])).toBe(false));
61
+ test("{} should return false", () => expect(checkIsString({})).toBe(false));
62
+ test("() => {} should return false", () =>
63
+ expect(checkIsString(() => {})).toBe(false));
64
+ test("123n should return false", () =>
65
+ expect(checkIsString(123n)).toBe(false));
66
+ test("null should return false", () =>
67
+ expect(checkIsString(null)).toBe(false));
68
+ test("undefined should return false", () =>
69
+ expect(checkIsString(undefined)).toBe(false));
70
+ test('new String("hello") should return false', () =>
71
+ expect(checkIsString(new String("hello"))).toBe(false));
72
+ test('" " should return true', () =>
73
+ expect(checkIsString(" ")).toBe(true));
74
+ test("template literal should return true", () =>
75
+ expect(checkIsString(`hello ${42}`)).toBe(true));
76
+ test('Symbol("test") should return false', () =>
77
+ expect(checkIsString(Symbol("test"))).toBe(false));
78
+ });
15
79
 
16
- describe("checkIsNumber", () => {
17
- // Positive
18
- test('42 should return true', () => expect(checkIsNumber(42)).toBe(true));
19
- test('0 should return true', () => expect(checkIsNumber(0)).toBe(true));
20
- test('-1 should return true', () => expect(checkIsNumber(-1)).toBe(true));
21
- test('NaN should return true', () => expect(checkIsNumber(NaN)).toBe(true));
22
- test('Infinity should return true', () => expect(checkIsNumber(Infinity)).toBe(true));
23
- // Negative
24
- test('"hello" should return false', () => expect(checkIsNumber("hello")).toBe(false));
25
- test('true should return false', () => expect(checkIsNumber(true)).toBe(false));
26
- test('false should return false', () => expect(checkIsNumber(false)).toBe(false));
27
- test('[] should return false', () => expect(checkIsNumber([])).toBe(false));
28
- test('{} should return false', () => expect(checkIsNumber({})).toBe(false));
29
- test('() => {} should return false', () => expect(checkIsNumber(() => {})).toBe(false));
30
- test('123n should return false', () => expect(checkIsNumber(123n)).toBe(false));
31
- // Null / Undefined
32
- test('null should return undefined', () => expect(checkIsNumber(null)).toBeUndefined());
33
- test('undefined should return undefined', () => expect(checkIsNumber(undefined)).toBeUndefined());
34
- });
80
+ describe("Check Is Boolean Function", () => {
81
+ test("true should return true", () =>
82
+ expect(checkIsBoolean(true)).toBe(true));
83
+ test("false should return true", () =>
84
+ expect(checkIsBoolean(false)).toBe(true));
85
+ test("0 should return false", () => expect(checkIsBoolean(0)).toBe(false));
86
+ test("1 should return false", () => expect(checkIsBoolean(1)).toBe(false));
87
+ test('"true" should return false', () =>
88
+ expect(checkIsBoolean("true")).toBe(false));
89
+ test("[] should return false", () => expect(checkIsBoolean([])).toBe(false));
90
+ test("{} should return false", () => expect(checkIsBoolean({})).toBe(false));
91
+ test("() => {} should return false", () =>
92
+ expect(checkIsBoolean(() => {})).toBe(false));
93
+ test("123n should return false", () =>
94
+ expect(checkIsBoolean(123n)).toBe(false));
95
+ test("null should return false", () =>
96
+ expect(checkIsBoolean(null)).toBe(false));
97
+ test("undefined should return false", () =>
98
+ expect(checkIsBoolean(undefined)).toBe(false));
99
+ test("new Boolean(true) should return false", () =>
100
+ expect(checkIsBoolean(new Boolean(true))).toBe(false));
101
+ test("true && false should return true", () =>
102
+ expect(checkIsBoolean(true && false)).toBe(true));
103
+ test("1 === 1 should return true", () =>
104
+ expect(checkIsBoolean(1 === 1)).toBe(true));
105
+ test("Symbol() should return false", () =>
106
+ expect(checkIsBoolean(Symbol())).toBe(false));
107
+ });
35
108
 
36
- describe("checkIsString", () => {
37
- // Positive
38
- test('"hello" should return true', () => expect(checkIsString("hello")).toBe(true));
39
- test('"" should return true', () => expect(checkIsString("")).toBe(true));
40
- test('"123" should return true', () => expect(checkIsString("123")).toBe(true));
41
- // Negative
42
- test('42 should return false', () => expect(checkIsString(42)).toBe(false));
43
- test('true should return false', () => expect(checkIsString(true)).toBe(false));
44
- test('false should return false', () => expect(checkIsString(false)).toBe(false));
45
- test('[] should return false', () => expect(checkIsString([])).toBe(false));
46
- test('{} should return false', () => expect(checkIsString({})).toBe(false));
47
- test('() => {} should return false', () => expect(checkIsString(() => {})).toBe(false));
48
- test('123n should return false', () => expect(checkIsString(123n)).toBe(false));
49
- // Null / Undefined
50
- test('null should return undefined', () => expect(checkIsString(null)).toBeUndefined());
51
- test('undefined should return undefined', () => expect(checkIsString(undefined)).toBeUndefined());
52
- });
109
+ describe("Check Is Bigint Function", () => {
110
+ test("0n should return true", () => expect(checkIsBigint(0n)).toBe(true));
111
+ test("123n should return true", () => expect(checkIsBigint(123n)).toBe(true));
112
+ test("-999n should return true", () =>
113
+ expect(checkIsBigint(-999n)).toBe(true));
114
+ test("42 should return false", () => expect(checkIsBigint(42)).toBe(false));
115
+ test('"123"', () => expect(checkIsBigint("123")).toBe(false));
116
+ test("true should return false", () =>
117
+ expect(checkIsBigint(true)).toBe(false));
118
+ test("[] should return false", () => expect(checkIsBigint([])).toBe(false));
119
+ test("{} should return false", () => expect(checkIsBigint({})).toBe(false));
120
+ test("() => {} should return false", () =>
121
+ expect(checkIsBigint(() => {})).toBe(false));
122
+ test("null should return false", () =>
123
+ expect(checkIsBigint(null)).toBe(false));
124
+ test("undefined should return false", () =>
125
+ expect(checkIsBigint(undefined)).toBe(false));
126
+ test("Object(1n) should return false", () =>
127
+ expect(checkIsBigint(Object(1n))).toBe(false));
128
+ test("very large bigint should return true", () =>
129
+ expect(checkIsBigint(9007199254740993123456789n)).toBe(true));
130
+ test("BigInt(42) should return true", () =>
131
+ expect(checkIsBigint(BigInt(42))).toBe(true));
132
+ test("NaN should return false", () => expect(checkIsBigint(NaN)).toBe(false));
133
+ test("Symbol() should return false", () =>
134
+ expect(checkIsBigint(Symbol())).toBe(false));
135
+ });
53
136
 
54
- describe("checkIsBoolean", () => {
55
- // Positive
56
- test('true should return true', () => expect(checkIsBoolean(true)).toBe(true));
57
- test('false should return true', () => expect(checkIsBoolean(false)).toBe(true));
58
- // Negative
59
- test('0 should return false', () => expect(checkIsBoolean(0)).toBe(false));
60
- test('1 should return false', () => expect(checkIsBoolean(1)).toBe(false));
61
- test('"true" should return false', () => expect(checkIsBoolean("true")).toBe(false));
62
- test('[] should return false', () => expect(checkIsBoolean([])).toBe(false));
63
- test('{} should return false', () => expect(checkIsBoolean({})).toBe(false));
64
- test('() => {} should return false', () => expect(checkIsBoolean(() => {})).toBe(false));
65
- test('123n should return false', () => expect(checkIsBoolean(123n)).toBe(false));
66
- // Null / Undefined
67
- test('null should return undefined', () => expect(checkIsBoolean(null)).toBeUndefined());
68
- test('undefined should return undefined', () => expect(checkIsBoolean(undefined)).toBeUndefined());
69
- });
137
+ describe("Check Is Function Function", () => {
138
+ test('function declaration should return true', () => expect(checkIsFunction(function() {})).toBe(true));
139
+ test('arrow function should return true', () => expect(checkIsFunction(() => {})).toBe(true));
140
+ test('async function should return true', () => expect(checkIsFunction(async function() {})).toBe(true));
141
+ test('42 should return false', () => expect(checkIsFunction(42)).toBe(false));
142
+ test('"hello" should return false', () => expect(checkIsFunction("hello")).toBe(false));
143
+ test('true should return false', () => expect(checkIsFunction(true)).toBe(false));
144
+ test('[] should return false', () => expect(checkIsFunction([])).toBe(false));
145
+ test('{} should return false', () => expect(checkIsFunction({})).toBe(false));
146
+ test('123n should return false', () => expect(checkIsFunction(123n)).toBe(false));
147
+ test('null should return false', () => expect(checkIsFunction(null)).toBe(false));
148
+ test('undefined should return false', () => expect(checkIsFunction(undefined)).toBe(false));
149
+ test('class should return true', () => expect(checkIsFunction(class Test {})).toBe(true));
150
+ test('generator function should return true', () => expect(checkIsFunction(function* () {})).toBe(true));
151
+ test('async arrow function should return true', () => expect(checkIsFunction(async () => {})).toBe(true));
152
+ test('bound function should return true', () => expect(checkIsFunction(function () {}.bind(null))).toBe(true));
153
+ test('new Date() should return false', () => expect(checkIsFunction(new Date())).toBe(false));
154
+ test('Symbol() should return false', () => expect(checkIsFunction(Symbol())).toBe(false))
155
+ });
70
156
 
71
- describe("checkIsBigint", () => {
72
- // Positive
73
- test('0n should return true', () => expect(checkIsBigint(0n)).toBe(true));
74
- test('123n should return true', () => expect(checkIsBigint(123n)).toBe(true));
75
- test('-999n should return true', () => expect(checkIsBigint(-999n)).toBe(true));
76
- // Negative
77
- test('42 should return false', () => expect(checkIsBigint(42)).toBe(false));
78
- test('"123"' , () => expect(checkIsBigint("123")).toBe(false));
79
- test('true should return false', () => expect(checkIsBigint(true)).toBe(false));
80
- test('[] should return false', () => expect(checkIsBigint([])).toBe(false));
81
- test('{} should return false', () => expect(checkIsBigint({})).toBe(false));
82
- test('() => {} should return false', () => expect(checkIsBigint(() => {})).toBe(false));
83
- // Null / Undefined
84
- test('null should return undefined', () => expect(checkIsBigint(null)).toBeUndefined());
85
- test('undefined should return undefined', () => expect(checkIsBigint(undefined)).toBeUndefined());
86
- });
157
+ describe("Check Is Object Function", () => {
158
+ test('{} should return true', () => expect(checkIsObject({})).toBe(true));
159
+ test('{ a: 1 } should return true', () => expect(checkIsObject({ a: 1 })).toBe(true));
160
+ test('[] should return false', () => expect(checkIsObject([])).toBe(false));
161
+ test('42 should return false', () => expect(checkIsObject(42)).toBe(false));
162
+ test('"hello" should return false', () => expect(checkIsObject("hello")).toBe(false));
163
+ test('true should return false', () => expect(checkIsObject(true)).toBe(false));
164
+ test('() => {} should return false', () => expect(checkIsObject(() => {})).toBe(false));
165
+ test('123n should return false', () => expect(checkIsObject(123n)).toBe(false));
166
+ test('null should return false', () => expect(checkIsObject(null)).toBe(false));
167
+ test('undefined should return false', () => expect(checkIsObject(undefined)).toBe(false));
168
+ test('new Date() should return true', () => expect(checkIsObject(new Date())).toBe(true));
169
+ test('/abc/ should return true', () => expect(checkIsObject(/abc/)).toBe(true));
170
+ test('new Map() should return true', () => expect(checkIsObject(new Map())).toBe(true));
171
+ test('new Set() should return true', () => expect(checkIsObject(new Set())).toBe(true));
172
+ test('Object.create(null) should return true', () => expect(checkIsObject(Object.create(null))).toBe(true));
173
+ test('new Number(1) should return true', () => expect(checkIsObject(new Number(1))).toBe(true));
174
+ test('new String("x") should return true', () => expect(checkIsObject(new String("x"))).toBe(true));
175
+ });
87
176
 
88
- describe("checkIsFunction", () => {
89
- // Positive
90
- test('function declaration should return true', () => expect(checkIsFunction(function() {})).toBe(true));
91
- test('arrow function should return true', () => expect(checkIsFunction(() => {})).toBe(true));
92
- test('async function should return true', () => expect(checkIsFunction(async function() {})).toBe(true));
93
- // Negative
94
- test('42 should return false', () => expect(checkIsFunction(42)).toBe(false));
95
- test('"hello" should return false', () => expect(checkIsFunction("hello")).toBe(false));
96
- test('true should return false', () => expect(checkIsFunction(true)).toBe(false));
97
- test('[] should return false', () => expect(checkIsFunction([])).toBe(false));
98
- test('{} should return false', () => expect(checkIsFunction({})).toBe(false));
99
- test('123n should return false', () => expect(checkIsFunction(123n)).toBe(false));
100
- // Null / Undefined
101
- test('null should return undefined', () => expect(checkIsFunction(null)).toBeUndefined());
102
- test('undefined should return undefined', () => expect(checkIsFunction(undefined)).toBeUndefined());
177
+ describe("Check Is Object Length Function", () => {
178
+ test('{} should return 0', () => expect(checkObjectLength({})).toBe(0));
179
+ test('{ a: 1, b: 2 } should return 2', () => expect(checkObjectLength({ a: 1, b: 2 })).toBe(2));
180
+ test('[] should return undefined', () => expect(checkObjectLength([])).toBe(undefined));
181
+ test('42 should return undefined', () => expect(checkObjectLength(42)).toBeUndefined());
182
+ test('"hello" should return undefined', () => expect(checkObjectLength("hello")).toBeUndefined());
183
+ test('null should return undefined', () => expect(checkObjectLength(null)).toBeUndefined());
184
+ test('undefined should return undefined', () => expect(checkObjectLength(undefined)).toBeUndefined());
185
+ test('() => {} should return undefined', () => expect(checkObjectLength(() => {})).toBeUndefined());
186
+ test('object with prototype properties should return only own keys count', () => {
187
+ const parent = { a: 1 };
188
+ const child = Object.create(parent);
189
+ child.b = 2;
190
+ expect(checkObjectLength(child)).toBe(1);
103
191
  });
104
-
105
- describe("checkIsObject", () => {
106
- // Positive
107
- test('{} should return true', () => expect(checkIsObject({})).toBe(true));
108
- test('{ a: 1 } should return true', () => expect(checkIsObject({ a: 1 })).toBe(true));
109
- test('[] should return true (arrays are objects)', () => expect(checkIsObject([])).toBe(true));
110
- // Negative
111
- test('42 should return false', () => expect(checkIsObject(42)).toBe(false));
112
- test('"hello" should return false', () => expect(checkIsObject("hello")).toBe(false));
113
- test('true should return false', () => expect(checkIsObject(true)).toBe(false));
114
- test('() => {} should return false', () => expect(checkIsObject(() => {})).toBe(false));
115
- test('123n should return false', () => expect(checkIsObject(123n)).toBe(false));
116
- // Null / Undefined
117
- test('null should return undefined', () => expect(checkIsObject(null)).toBeUndefined());
118
- test('undefined should return undefined', () => expect(checkIsObject(undefined)).toBeUndefined());
192
+ test('object with non-enumerable properties should return 0', () => {
193
+ const obj = {};
194
+ Object.defineProperty(obj, 'hidden', {
195
+ value: 1,
196
+ enumerable: false,
197
+ });
198
+ expect(checkObjectLength(obj)).toBe(0);
119
199
  });
120
-
121
- describe("checkObjectLength", () => {
122
- // Positive
123
- test('{} should return 0', () => expect(checkObjectLength({})).toBe(0));
124
- test('{ a: 1, b: 2 } should return 2', () => expect(checkObjectLength({ a: 1, b: 2 })).toBe(2));
125
- test('[] should return 0 (array is object)', () => expect(checkObjectLength([])).toBe(0));
126
- // Negative / Non-object
127
- test('42 should return undefined', () => expect(checkObjectLength(42)).toBeUndefined());
128
- test('"hello" should return undefined', () => expect(checkObjectLength("hello")).toBeUndefined());
129
- test('null should return undefined', () => expect(checkObjectLength(null)).toBeUndefined());
130
- test('undefined should return undefined', () => expect(checkObjectLength(undefined)).toBeUndefined());
131
- test('() => {} should return undefined', () => expect(checkObjectLength(() => {})).toBeUndefined());
200
+ test('object with symbol keys should return 0', () => {
201
+ const sym = Symbol('key');
202
+ const obj = { [sym]: 1 };
203
+ expect(checkObjectLength(obj)).toBe(0);
132
204
  });
133
-
134
- describe("checkIsArray", () => {
135
- // Positive
136
- test('[] should return true', () => expect(checkIsArray([])).toBe(true));
137
- test('[1,2,3] should return true', () => expect(checkIsArray([1,2,3])).toBe(true));
138
- // Negative
139
- test('{} should return false', () => expect(checkIsArray({})).toBe(false));
140
- test('42 should return false', () => expect(checkIsArray(42)).toBe(false));
141
- test('"hello" should return false', () => expect(checkIsArray("hello")).toBe(false));
142
- test('true should return false', () => expect(checkIsArray(true)).toBe(false));
143
- test('123n should return false', () => expect(checkIsArray(123n)).toBe(false));
144
- // Null / Undefined
145
- test('null should return undefined', () => expect(checkIsArray(null)).toBeUndefined());
146
- test('undefined should return undefined', () => expect(checkIsArray(undefined)).toBeUndefined());
205
+ test('frozen object should return correct length', () => {
206
+ const obj = Object.freeze({ a: 1, b: 2 });
207
+ expect(checkObjectLength(obj)).toBe(2);
147
208
  });
209
+ });
148
210
 
149
- describe("checkArrayLength", () => {
150
- // Positive
151
- test('[] should return 0', () => expect(checkArrayLength([])).toBe(0));
152
- test('[1,2,3] should return 3', () => expect(checkArrayLength([1,2,3])).toBe(3));
153
- test('["a", "b"] should return 2', () => expect(checkArrayLength(["a","b"])).toBe(2));
154
- // Negative / Non-array
155
- test('{} should return undefined', () => expect(checkArrayLength({})).toBeUndefined());
156
- test('42 should return undefined', () => expect(checkArrayLength(42)).toBeUndefined());
157
- test('"hello" should return undefined', () => expect(checkArrayLength("hello")).toBeUndefined());
158
- test('true should return undefined', () => expect(checkArrayLength(true)).toBeUndefined());
159
- test('null should return undefined', () => expect(checkArrayLength(null)).toBeUndefined());
160
- test('undefined should return undefined', () => expect(checkArrayLength(undefined)).toBeUndefined());
211
+ describe("Check Is Array Function", () => {
212
+ test('[] should return true', () => expect(checkIsArray([])).toBe(true));
213
+ test('[1,2,3] should return true', () => expect(checkIsArray([1,2,3])).toBe(true));
214
+ test('{} should return false', () => expect(checkIsArray({})).toBe(false));
215
+ test('42 should return false', () => expect(checkIsArray(42)).toBe(false));
216
+ test('"hello" should return false', () => expect(checkIsArray("hello")).toBe(false));
217
+ test('true should return false', () => expect(checkIsArray(true)).toBe(false));
218
+ test('123n should return false', () => expect(checkIsArray(123n)).toBe(false));
219
+ test('null should return false', () => expect(checkIsArray(null)).toBe(false));
220
+ test('undefined should return false', () => expect(checkIsArray(undefined)).toBe(false));
221
+ test('sparse array should return true', () => expect(checkIsArray([, , ])).toBe(true));
222
+ test('sparse array should return true', () => expect(checkIsArray([, , ])).toBe(true));
223
+ test('new Array() should return true', () => expect(checkIsArray(new Array())).toBe(true));
224
+ test('arguments object should return false', () => {
225
+ function testFn() {
226
+ return expect(checkIsArray(arguments)).toBe(false);
227
+ }
228
+ testFn(1, 2, 3);
161
229
  });
230
+ test('typed array should return false', () => expect(checkIsArray(new Uint8Array())).toBe(false));
231
+ });
162
232
 
233
+ describe("Check Is Array Length Function", () => {
234
+ test('[] should return 0', () => expect(checkArrayLength([])).toBe(0));
235
+ test('[1,2,3] should return 3', () => expect(checkArrayLength([1,2,3])).toBe(3));
236
+ test('["a", "b"] should return 2', () => expect(checkArrayLength(["a","b"])).toBe(2));
237
+ test('{} should return undefined', () => expect(checkArrayLength({})).toBeUndefined());
238
+ test('42 should return undefined', () => expect(checkArrayLength(42)).toBeUndefined());
239
+ test('"hello" should return undefined', () => expect(checkArrayLength("hello")).toBeUndefined());
240
+ test('true should return undefined', () => expect(checkArrayLength(true)).toBeUndefined());
241
+ test('null should return undefined', () => expect(checkArrayLength(null)).toBeUndefined());
242
+ test('undefined should return undefined', () => expect(checkArrayLength(undefined)).toBeUndefined());
243
+ test('sparse array with 2 empty slots should return 2', () => expect(checkArrayLength([, , ])).toBe(2));
244
+ test('sparse array with 3 empty slots should return 3', () => expect(checkArrayLength([,,,])).toBe(3));
245
+ test('nested array should return top-level length only', () => expect(checkArrayLength([[1], [2, 3]])).toBe(2));
246
+ test('new Array(5) should return 5', () => expect(checkArrayLength(new Array(5))).toBe(5));
247
+ test('array with holes and values should return correct length', () => expect(checkArrayLength([1, , 3])).toBe(3));
248
+ test('typed array should return undefined', () => expect(checkArrayLength(new Uint8Array(3))).toBeUndefined());
163
249
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phane-js-utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Pure JavaScript utility functions",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -12,17 +12,29 @@
12
12
  "utils",
13
13
  "library"
14
14
  ],
15
+ "homepage": "https://phane-tech.github.io/js-data-type-check/module-DataTypeCheck.html",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/phane-tech/js-data-type-check"
19
+ },
15
20
  "author": "Kotipalli Phaneendra Kumar",
16
21
  "license": "MIT",
17
22
  "scripts": {
18
- "docs": "jsdoc -c jsdoc.json",
23
+ "test": "jest",
19
24
  "readme": "npx jsdoc-to-markdown \"js/*.js\" > README.md",
20
- "release": "npm run readme && npm version patch && npm publish --access public"
25
+ "docs": "rimraf docs && npm run test && npx jsdoc -c jsdoc.json",
26
+ "release": "npm run docs && npm version patch && npm run readme && npm publish --access public"
21
27
  },
22
28
  "devDependencies": {
29
+ "@babel/core": "^7.28.5",
30
+ "@babel/preset-env": "^7.28.5",
31
+ "babel-jest": "^30.2.0",
23
32
  "docdash": "^2.0.2",
24
33
  "jest": "^30.2.0",
25
34
  "jest-environment-jsdom": "^30.2.0",
26
- "jsdoc-to-markdown": "^9.1.3"
35
+ "jest-html-reporter": "^4.3.0",
36
+ "jsdoc": "^4.0.5",
37
+ "jsdoc-to-markdown": "^9.1.3",
38
+ "rimraf": "^6.1.2"
27
39
  }
28
40
  }
package/js/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dataTypeCheck.js";