@webdeveric/utils 0.66.0 → 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.
@@ -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);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assume = void 0;
4
+ const assume = (_input, ..._args) => true;
5
+ exports.assume = assume;
@@ -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 = (...options) => (input) => options.some((option) => Object.is(input, option));
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 entries = Reflect.ownKeys(objectShape).map((key) => {
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) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
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.isAny = void 0;
4
- const isAny = (_input) => true;
5
- exports.isAny = isAny;
4
+ const assume_js_1 = require("./assume.js");
5
+ exports.isAny = (assume_js_1.assume);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isDateString = void 0;
4
- const isDateString = (input) => typeof input === 'string' && !Number.isNaN(new Date(input).getTime());
4
+ const isDateString = (input) => typeof input === 'string' && !Number.isNaN(Date.parse(input));
5
5
  exports.isDateString = isDateString;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUnknown = void 0;
4
- const isUnknown = (_input) => true;
5
- exports.isUnknown = isUnknown;
4
+ const assume_js_1 = require("./assume.js");
5
+ exports.isUnknown = (assume_js_1.assume);
@@ -0,0 +1,4 @@
1
+ export const hasAdditionalProperties = (input, knownProperties) => {
2
+ const properties = Array.isArray(input) ? [...knownProperties.map(String), 'length'] : knownProperties;
3
+ return !Reflect.ownKeys(input).every((key) => properties.includes(key));
4
+ };
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 = (...options) => (input) => options.some((option) => Object.is(input, option));
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 entries = Reflect.ownKeys(objectShape).map((key) => {
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) && entries.every(([key, predicate]) => predicate(Reflect.get(input, key)));
18
+ return (input) => isAnyObject(input) &&
19
+ entries.every(([key, predicate]) => predicate(Reflect.get(input, key))) &&
20
+ (additionalProperties || !hasAdditionalProperties(input, knownProperties));
17
21
  };
@@ -1,3 +1,4 @@
1
+ export * from './assume.js';
1
2
  export * from './isAny.js';
2
3
  export * from './isAnyObject.js';
3
4
  export * from './isAnyObjectWith.js';
@@ -1 +1,2 @@
1
- export const isAny = (_input) => true;
1
+ import { assume } from './assume.js';
2
+ export const isAny = (assume);
@@ -1 +1 @@
1
- export const isDateString = (input) => typeof input === 'string' && !Number.isNaN(new Date(input).getTime());
1
+ export const isDateString = (input) => typeof input === 'string' && !Number.isNaN(Date.parse(input));
@@ -1 +1,2 @@
1
- export const isUnknown = (_input) => true;
1
+ import { assume } from './assume.js';
2
+ export const isUnknown = (assume);
@@ -0,0 +1 @@
1
+ export declare const hasAdditionalProperties: (input: object, knownProperties: PropertyKey[]) => boolean;
@@ -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
- import type { Pretty, Writable } from '../../types/utils.js';
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,3 +1,4 @@
1
+ export * from './assume.js';
1
2
  export * from './isAny.js';
2
3
  export * from './isAnyObject.js';
3
4
  export * from './isAnyObjectWith.js';
@@ -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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.66.0",
4
+ "version": "0.67.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -87,7 +87,7 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/config-conventional": "^19.8.1",
89
89
  "@commitlint/types": "^19.8.1",
90
- "@types/node": "^22.15.34",
90
+ "@types/node": "^22.16.0",
91
91
  "@vitest/coverage-v8": "^3.2.4",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",