@gesslar/toolkit 0.1.4 → 0.1.5
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/package.json +1 -1
- package/src/lib/Data.js +3 -3
- package/src/lib/Valid.js +3 -4
- package/src/types/Valid.d.ts +2 -2
package/package.json
CHANGED
package/src/lib/Data.js
CHANGED
|
@@ -273,9 +273,9 @@ export default class Data {
|
|
|
273
273
|
* @returns {Promise<object>} The mapped object
|
|
274
274
|
*/
|
|
275
275
|
static async mapObject(original, transformer, mutate = false) {
|
|
276
|
-
Valid.
|
|
277
|
-
Valid.
|
|
278
|
-
Valid.
|
|
276
|
+
Valid.type(original, "object", {allowEmpty: true})
|
|
277
|
+
Valid.type(transformer, "function")
|
|
278
|
+
Valid.type(mutate, "boolean")
|
|
279
279
|
|
|
280
280
|
const result = mutate ? original : {}
|
|
281
281
|
|
package/src/lib/Valid.js
CHANGED
|
@@ -5,14 +5,13 @@ import Data from "./Data.js"
|
|
|
5
5
|
|
|
6
6
|
export default class Valid {
|
|
7
7
|
/**
|
|
8
|
-
* Validates a value against a type
|
|
8
|
+
* Validates a value against a type. Uses Data.isType.
|
|
9
9
|
*
|
|
10
10
|
* @param {unknown} value - The value to validate
|
|
11
|
-
* @param {string} type - The expected type in the form of "object",
|
|
12
|
-
* "object[]", "object|object[]"
|
|
11
|
+
* @param {string} type - The expected type in the form of "object", "object[]", "object|object[]"
|
|
13
12
|
* @param {object} [options] - Additional options for validation.
|
|
14
13
|
*/
|
|
15
|
-
static
|
|
14
|
+
static type(value, type, options) {
|
|
16
15
|
Valid.assert(
|
|
17
16
|
Data.isType(value, type, options),
|
|
18
17
|
`Invalid type. Expected ${type}, got ${JSON.stringify(value)}`,
|
package/src/types/Valid.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
export default class Valid {
|
|
5
5
|
/** Validate a value against a type specification */
|
|
6
|
-
static
|
|
6
|
+
static type(value: unknown, type: string, options?: { allowEmpty?: boolean }): void
|
|
7
7
|
|
|
8
8
|
/** Assert a condition */
|
|
9
9
|
static assert(condition: boolean, message: string, arg?: number | null): void
|
|
10
|
-
}
|
|
10
|
+
}
|