@webdeveric/utils 0.66.1 → 0.67.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/dist/cjs/hasAdditionalProperties.js +8 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/predicate/assume.js +5 -0
- package/dist/cjs/predicate/factory/is.js +1 -1
- package/dist/cjs/predicate/factory/shape.js +7 -3
- package/dist/cjs/predicate/index.js +1 -0
- package/dist/cjs/predicate/isAny.js +2 -2
- package/dist/cjs/predicate/isUnknown.js +2 -2
- package/dist/mjs/hasAdditionalProperties.js +4 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/predicate/assume.js +1 -0
- package/dist/mjs/predicate/factory/is.js +1 -1
- package/dist/mjs/predicate/factory/shape.js +7 -3
- package/dist/mjs/predicate/index.js +1 -0
- package/dist/mjs/predicate/isAny.js +2 -1
- package/dist/mjs/predicate/isUnknown.js +2 -1
- package/dist/types/hasAdditionalProperties.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/predicate/assume.d.ts +1 -0
- package/dist/types/predicate/factory/is.d.ts +1 -2
- package/dist/types/predicate/factory/shape.d.ts +1 -1
- package/dist/types/predicate/index.d.ts +1 -0
- package/dist/types/predicate/isAny.d.ts +1 -1
- package/dist/types/predicate/isUnknown.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasAdditionalProperties = void 0;
|
|
4
|
+
const hasAdditionalProperties = (input, knownProperties) => {
|
|
5
|
+
const properties = Array.isArray(input) ? [...knownProperties.map(String), 'length'] : knownProperties;
|
|
6
|
+
return !Reflect.ownKeys(input).every((key) => properties.includes(key));
|
|
7
|
+
};
|
|
8
|
+
exports.hasAdditionalProperties = hasAdditionalProperties;
|
package/dist/cjs/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __exportStar(require("./getPackageName.js"), exports);
|
|
|
48
48
|
__exportStar(require("./getPaths.js"), exports);
|
|
49
49
|
__exportStar(require("./getRandomItem.js"), exports);
|
|
50
50
|
__exportStar(require("./getType.js"), exports);
|
|
51
|
+
__exportStar(require("./hasAdditionalProperties.js"), exports);
|
|
51
52
|
__exportStar(require("./inRange.js"), exports);
|
|
52
53
|
__exportStar(require("./isEmpty.js"), exports);
|
|
53
54
|
__exportStar(require("./iterateForever.js"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.is = void 0;
|
|
4
|
-
const is = (...
|
|
4
|
+
const is = (...values) => (input) => values.some((value) => Object.is(input, value));
|
|
5
5
|
exports.is = is;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shape = void 0;
|
|
4
|
+
const hasAdditionalProperties_js_1 = require("../../hasAdditionalProperties.js");
|
|
4
5
|
const isAnyObject_js_1 = require("../isAnyObject.js");
|
|
5
6
|
const literal_js_1 = require("./literal.js");
|
|
6
7
|
const matching_js_1 = require("./matching.js");
|
|
7
|
-
const shape = (objectShape) => {
|
|
8
|
-
const
|
|
8
|
+
const shape = (objectShape, additionalProperties = true) => {
|
|
9
|
+
const knownProperties = Reflect.ownKeys(objectShape);
|
|
10
|
+
const entries = knownProperties.map((key) => {
|
|
9
11
|
const value = Reflect.get(objectShape, key);
|
|
10
12
|
const predicate = typeof value === 'function'
|
|
11
13
|
? value
|
|
@@ -16,6 +18,8 @@ const shape = (objectShape) => {
|
|
|
16
18
|
: (0, literal_js_1.literal)(value);
|
|
17
19
|
return [key, predicate];
|
|
18
20
|
});
|
|
19
|
-
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) &&
|
|
21
|
+
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) &&
|
|
22
|
+
entries.every(([key, predicate]) => predicate(Reflect.get(input, key))) &&
|
|
23
|
+
(additionalProperties || !(0, hasAdditionalProperties_js_1.hasAdditionalProperties)(input, knownProperties));
|
|
20
24
|
};
|
|
21
25
|
exports.shape = shape;
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./assume.js"), exports);
|
|
17
18
|
__exportStar(require("./isAny.js"), exports);
|
|
18
19
|
__exportStar(require("./isAnyObject.js"), exports);
|
|
19
20
|
__exportStar(require("./isAnyObjectWith.js"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isUnknown = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.isUnknown =
|
|
4
|
+
const assume_js_1 = require("./assume.js");
|
|
5
|
+
exports.isUnknown = (assume_js_1.assume);
|
package/dist/mjs/index.js
CHANGED
|
@@ -32,6 +32,7 @@ export * from './getPackageName.js';
|
|
|
32
32
|
export * from './getPaths.js';
|
|
33
33
|
export * from './getRandomItem.js';
|
|
34
34
|
export * from './getType.js';
|
|
35
|
+
export * from './hasAdditionalProperties.js';
|
|
35
36
|
export * from './inRange.js';
|
|
36
37
|
export * from './isEmpty.js';
|
|
37
38
|
export * from './iterateForever.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const assume = (_input, ..._args) => true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const is = (...
|
|
1
|
+
export const is = (...values) => (input) => values.some((value) => Object.is(input, value));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { hasAdditionalProperties } from '../../hasAdditionalProperties.js';
|
|
1
2
|
import { isAnyObject } from '../isAnyObject.js';
|
|
2
3
|
import { literal } from './literal.js';
|
|
3
4
|
import { matching } from './matching.js';
|
|
4
|
-
export const shape = (objectShape) => {
|
|
5
|
-
const
|
|
5
|
+
export const shape = (objectShape, additionalProperties = true) => {
|
|
6
|
+
const knownProperties = Reflect.ownKeys(objectShape);
|
|
7
|
+
const entries = knownProperties.map((key) => {
|
|
6
8
|
const value = Reflect.get(objectShape, key);
|
|
7
9
|
const predicate = typeof value === 'function'
|
|
8
10
|
? value
|
|
@@ -13,5 +15,7 @@ export const shape = (objectShape) => {
|
|
|
13
15
|
: literal(value);
|
|
14
16
|
return [key, predicate];
|
|
15
17
|
});
|
|
16
|
-
return (input) => isAnyObject(input) &&
|
|
18
|
+
return (input) => isAnyObject(input) &&
|
|
19
|
+
entries.every(([key, predicate]) => predicate(Reflect.get(input, key))) &&
|
|
20
|
+
(additionalProperties || !hasAdditionalProperties(input, knownProperties));
|
|
17
21
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { assume } from './assume.js';
|
|
2
|
+
export const isAny = (assume);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { assume } from './assume.js';
|
|
2
|
+
export const isUnknown = (assume);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hasAdditionalProperties: (input: object, knownProperties: PropertyKey[]) => boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export * from './getPackageName.js';
|
|
|
32
32
|
export * from './getPaths.js';
|
|
33
33
|
export * from './getRandomItem.js';
|
|
34
34
|
export * from './getType.js';
|
|
35
|
+
export * from './hasAdditionalProperties.js';
|
|
35
36
|
export * from './inRange.js';
|
|
36
37
|
export * from './isEmpty.js';
|
|
37
38
|
export * from './iterateForever.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const assume: <Type>(_input: unknown, ..._args: any[]) => _input is Type;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
|
-
|
|
3
|
-
export declare const is: <const T extends unknown[]>(...options: T) => TypePredicateFn<Pretty<Writable<T[number]>>>;
|
|
2
|
+
export declare const is: <const T extends unknown[]>(...values: T) => TypePredicateFn<T[number]>;
|
|
@@ -11,4 +11,4 @@ export type InferTypeFromShapeValue<Type> = Type extends RegExp ? string : Type
|
|
|
11
11
|
export type InferTypeFromShape<Shape extends ObjectShapeRecord<object>> = {
|
|
12
12
|
[Property in keyof Shape]: InferTypeFromShapeValue<Shape[Property]>;
|
|
13
13
|
};
|
|
14
|
-
export declare const shape: <Type extends object, Shape extends ObjectShapeRecord<Type> = ObjectShapeRecord<Type>>(objectShape: Shape) => TypePredicateFn<Pretty<Type & InferTypeFromShape<Shape>>>;
|
|
14
|
+
export declare const shape: <Type extends object, Shape extends ObjectShapeRecord<Type> = ObjectShapeRecord<Type>>(objectShape: Shape, additionalProperties?: boolean) => TypePredicateFn<Pretty<Type & InferTypeFromShape<Shape>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isAny: (_input: unknown) => _input is any;
|
|
1
|
+
export declare const isAny: (_input: unknown, ..._args: any[]) => _input is any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isUnknown: (_input: unknown) => _input is unknown;
|
|
1
|
+
export declare const isUnknown: (_input: unknown, ..._args: any[]) => _input is unknown;
|