@omnific/utils 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. package/dist/main.d.ts +139 -7
  2. package/dist/main.js +176 -18
  3. package/package.json +1 -1
package/dist/main.d.ts CHANGED
@@ -1,23 +1,155 @@
1
1
  //#region isArray.d.ts
2
- declare const isArray: <T = unknown>(value: unknown) => value is T[];
2
+ /**
3
+ * Checks if the given value is an array.
4
+ *
5
+ * This function tests whether the provided value is strictly an array.
6
+ * It returns `true` if the value is an array, and `false` otherwise.
7
+ *
8
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an array.
9
+ *
10
+ * @param {unknown} value - The value to test if it is an array.
11
+ * @returns {value is T[]} True if the value is an array, false otherwise.
12
+ *
13
+ * @example
14
+ * const value1 = [];
15
+ * const value2 = {};
16
+ * const value3 = 'abc';
17
+ *
18
+ * console.log(isArray(value1)); // true
19
+ * console.log(isArray(value2)); // false
20
+ * console.log(isArray(value3)); // false
21
+ */
22
+ declare function isArray<T = unknown>(value: unknown): value is T[];
3
23
  //#endregion
4
24
  //#region isBoolean.d.ts
5
- declare const isBoolean: (value: unknown) => value is boolean;
25
+ /**
26
+ * Checks if the given value is boolean.
27
+ *
28
+ * This function tests whether the provided value is strictly `boolean`.
29
+ * It returns `true` if the value is `boolean`, and `false` otherwise.
30
+ *
31
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
32
+ *
33
+ * @param {unknown} x - The Value to test if it is boolean.
34
+ * @returns {x is boolean} True if the value is boolean, false otherwise.
35
+ *
36
+ * @example
37
+ *
38
+ * const value1 = true;
39
+ * const value2 = 0;
40
+ * const value3 = 'abc';
41
+ *
42
+ * console.log(isBoolean(value1)); // true
43
+ * console.log(isBoolean(value2)); // false
44
+ * console.log(isBoolean(value3)); // false
45
+ *
46
+ */
47
+ declare function isBoolean(x: unknown): x is boolean;
6
48
  //#endregion
7
49
  //#region isFunction.d.ts
8
- type UnknownFunction<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => TResult;
9
- declare const isFunction: <TArgs extends unknown[] = unknown[], TResult = unknown>(value: unknown) => value is UnknownFunction<TArgs, TResult>;
50
+ /**
51
+ * Checks if `value` is a function.
52
+ *
53
+ * @param {any} value The value to check.
54
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
55
+ *
56
+ * @example
57
+ * isFunction(Array.prototype.slice); // true
58
+ * isFunction(async function () {}); // true
59
+ * isFunction(function* () {}); // true
60
+ * isFunction(Proxy); // true
61
+ * isFunction(Int8Array); // true
62
+ */
63
+ declare function isFunction(value: any): value is (...args: any[]) => any;
10
64
  //#endregion
11
65
  //#region isNil.d.ts
12
- declare const isNil: (value: unknown) => value is null | undefined;
66
+ /**
67
+ * Checks if a given value is null or undefined.
68
+ *
69
+ * This function tests whether the provided value is either `null` or `undefined`.
70
+ * It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
71
+ *
72
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
73
+ *
74
+ * @param {unknown} x - The value to test for null or undefined.
75
+ * @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
76
+ *
77
+ * @example
78
+ * const value1 = null;
79
+ * const value2 = undefined;
80
+ * const value3 = 42;
81
+ * const result1 = isNil(value1); // true
82
+ * const result2 = isNil(value2); // true
83
+ * const result3 = isNil(value3); // false
84
+ */
85
+ declare function isNil(x: unknown): x is null | undefined;
13
86
  //#endregion
14
87
  //#region isNumber.d.ts
15
- declare const isNumber: (value: unknown) => value is number;
88
+ /**
89
+ * Checks if the given value is a number.
90
+ *
91
+ * This function tests whether the provided value is strictly a `number`.
92
+ * It returns `true` if the value is a `number`, and `false` otherwise.
93
+ *
94
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
95
+ *
96
+ * @param {unknown} x - The value to test if it is a number.
97
+ * @returns {x is number} True if the value is a number, false otherwise.
98
+ *
99
+ * @example
100
+ *
101
+ * const value1 = 123;
102
+ * const value2 = 'abc';
103
+ * const value3 = true;
104
+ *
105
+ * console.log(isNumber(value1)); // true
106
+ * console.log(isNumber(value2)); // false
107
+ * console.log(isNumber(value3)); // false
108
+ *
109
+ */
110
+ declare function isNumber(value: unknown): value is number;
16
111
  //#endregion
17
112
  //#region isString.d.ts
18
- declare const isString: (value: unknown) => value is string;
113
+ /**
114
+ * Checks if a given value is string.
115
+ *
116
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
117
+ *
118
+ * @param {unknown} value The value to check if it is string.
119
+ * @returns {value is string} Returns `true` if `value` is a string, else `false`.
120
+ *
121
+ * @example
122
+ * const value1 = 'abc';
123
+ * const value2 = 123;
124
+ * const value3 = true;
125
+ *
126
+ * console.log(isString(value1)); // true
127
+ * console.log(isString(value2)); // false
128
+ * console.log(isString(value3)); // false
129
+ */
130
+ declare function isString(value: unknown): value is string;
19
131
  //#endregion
20
132
  //#region isUndefined.d.ts
133
+ /**
134
+ * Checks if the given value is undefined.
135
+ *
136
+ * This function tests whether the provided value is strictly equal to `undefined`.
137
+ * It returns `true` if the value is `undefined`, and `false` otherwise.
138
+ *
139
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
140
+ *
141
+ * @param {unknown} value - The value to test if it is undefined.
142
+ * @returns {value is undefined} True if the value is undefined, false otherwise.
143
+ *
144
+ * @example
145
+ * const value1 = undefined;
146
+ * const value2 = null;
147
+ * const value3 = 42;
148
+ *
149
+ * console.log(isUndefined(value1)); // true
150
+ * console.log(isUndefined(value2)); // false
151
+ * console.log(isUndefined(value3)); // false
152
+ */
21
153
  declare const isUndefined: (value: unknown) => value is undefined;
22
154
  //#endregion
23
155
  export { isArray, isBoolean, isFunction, isNil, isNumber, isString, isUndefined };
package/dist/main.js CHANGED
@@ -1,36 +1,194 @@
1
1
  //#region isArray.ts
2
- const isArray = (value) => {
2
+ /**
3
+ * Checks if the given value is an array.
4
+ *
5
+ * This function tests whether the provided value is strictly an array.
6
+ * It returns `true` if the value is an array, and `false` otherwise.
7
+ *
8
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an array.
9
+ *
10
+ * @param {unknown} value - The value to test if it is an array.
11
+ * @returns {value is T[]} True if the value is an array, false otherwise.
12
+ *
13
+ * @example
14
+ * const value1 = [];
15
+ * const value2 = {};
16
+ * const value3 = 'abc';
17
+ *
18
+ * console.log(isArray(value1)); // true
19
+ * console.log(isArray(value2)); // false
20
+ * console.log(isArray(value3)); // false
21
+ */
22
+ function isArray(value) {
3
23
  return Array.isArray(value);
4
- };
24
+ }
5
25
  //#endregion
6
26
  //#region isBoolean.ts
7
- const isBoolean = (value) => {
8
- return typeof value === "boolean";
9
- };
27
+ /**
28
+ * Checks if the given value is boolean.
29
+ *
30
+ * This function tests whether the provided value is strictly `boolean`.
31
+ * It returns `true` if the value is `boolean`, and `false` otherwise.
32
+ *
33
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
34
+ *
35
+ * @param {unknown} x - The Value to test if it is boolean.
36
+ * @returns {x is boolean} True if the value is boolean, false otherwise.
37
+ *
38
+ * @example
39
+ *
40
+ * const value1 = true;
41
+ * const value2 = 0;
42
+ * const value3 = 'abc';
43
+ *
44
+ * console.log(isBoolean(value1)); // true
45
+ * console.log(isBoolean(value2)); // false
46
+ * console.log(isBoolean(value3)); // false
47
+ *
48
+ */
49
+ function isBoolean(x) {
50
+ return typeof x === "boolean";
51
+ }
10
52
  //#endregion
11
53
  //#region isFunction.ts
12
- const isFunction = (value) => {
54
+ /**
55
+ * Checks if `value` is a function.
56
+ *
57
+ * @param {any} value The value to check.
58
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
59
+ *
60
+ * @example
61
+ * isFunction(Array.prototype.slice); // true
62
+ * isFunction(async function () {}); // true
63
+ * isFunction(function* () {}); // true
64
+ * isFunction(Proxy); // true
65
+ * isFunction(Int8Array); // true
66
+ */
67
+ function isFunction(value) {
13
68
  return typeof value === "function";
69
+ }
70
+ //#endregion
71
+ //#region isUndefined.ts
72
+ /**
73
+ * Checks if the given value is undefined.
74
+ *
75
+ * This function tests whether the provided value is strictly equal to `undefined`.
76
+ * It returns `true` if the value is `undefined`, and `false` otherwise.
77
+ *
78
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
79
+ *
80
+ * @param {unknown} value - The value to test if it is undefined.
81
+ * @returns {value is undefined} True if the value is undefined, false otherwise.
82
+ *
83
+ * @example
84
+ * const value1 = undefined;
85
+ * const value2 = null;
86
+ * const value3 = 42;
87
+ *
88
+ * console.log(isUndefined(value1)); // true
89
+ * console.log(isUndefined(value2)); // false
90
+ * console.log(isUndefined(value3)); // false
91
+ */
92
+ const isUndefined = (value) => {
93
+ return value === void 0;
14
94
  };
15
95
  //#endregion
96
+ //#region isNull.ts
97
+ /**
98
+ * Checks if the given value is null.
99
+ *
100
+ * This function tests whether the provided value is strictly equal to `null`.
101
+ * It returns `true` if the value is `null`, and `false` otherwise.
102
+ *
103
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
104
+ *
105
+ * @param {unknown} x - The value to test if it is null.
106
+ * @returns {x is null} True if the value is null, false otherwise.
107
+ *
108
+ * @example
109
+ * const value1 = null;
110
+ * const value2 = undefined;
111
+ * const value3 = 42;
112
+ *
113
+ * console.log(isNull(value1)); // true
114
+ * console.log(isNull(value2)); // false
115
+ * console.log(isNull(value3)); // false
116
+ */
117
+ function isNull(x) {
118
+ return x === null;
119
+ }
120
+ //#endregion
16
121
  //#region isNil.ts
17
- const isNil = (value) => {
18
- return value === null || value === void 0;
19
- };
122
+ /**
123
+ * Checks if a given value is null or undefined.
124
+ *
125
+ * This function tests whether the provided value is either `null` or `undefined`.
126
+ * It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
127
+ *
128
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
129
+ *
130
+ * @param {unknown} x - The value to test for null or undefined.
131
+ * @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
132
+ *
133
+ * @example
134
+ * const value1 = null;
135
+ * const value2 = undefined;
136
+ * const value3 = 42;
137
+ * const result1 = isNil(value1); // true
138
+ * const result2 = isNil(value2); // true
139
+ * const result3 = isNil(value3); // false
140
+ */
141
+ function isNil(x) {
142
+ return isNull(x) || isUndefined(x);
143
+ }
20
144
  //#endregion
21
145
  //#region isNumber.ts
22
- const isNumber = (value) => {
146
+ /**
147
+ * Checks if the given value is a number.
148
+ *
149
+ * This function tests whether the provided value is strictly a `number`.
150
+ * It returns `true` if the value is a `number`, and `false` otherwise.
151
+ *
152
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
153
+ *
154
+ * @param {unknown} x - The value to test if it is a number.
155
+ * @returns {x is number} True if the value is a number, false otherwise.
156
+ *
157
+ * @example
158
+ *
159
+ * const value1 = 123;
160
+ * const value2 = 'abc';
161
+ * const value3 = true;
162
+ *
163
+ * console.log(isNumber(value1)); // true
164
+ * console.log(isNumber(value2)); // false
165
+ * console.log(isNumber(value3)); // false
166
+ *
167
+ */
168
+ function isNumber(value) {
23
169
  return typeof value === "number" && !Number.isNaN(value);
24
- };
170
+ }
25
171
  //#endregion
26
172
  //#region isString.ts
27
- const isString = (value) => {
173
+ /**
174
+ * Checks if a given value is string.
175
+ *
176
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
177
+ *
178
+ * @param {unknown} value The value to check if it is string.
179
+ * @returns {value is string} Returns `true` if `value` is a string, else `false`.
180
+ *
181
+ * @example
182
+ * const value1 = 'abc';
183
+ * const value2 = 123;
184
+ * const value3 = true;
185
+ *
186
+ * console.log(isString(value1)); // true
187
+ * console.log(isString(value2)); // false
188
+ * console.log(isString(value3)); // false
189
+ */
190
+ function isString(value) {
28
191
  return typeof value === "string";
29
- };
30
- //#endregion
31
- //#region isUndefined.ts
32
- const isUndefined = (value) => {
33
- return value === void 0;
34
- };
192
+ }
35
193
  //#endregion
36
194
  export { isArray, isBoolean, isFunction, isNil, isNumber, isString, isUndefined };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Shared utility predicates for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",