@webdeveric/utils 0.42.0 → 0.44.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/index.js CHANGED
@@ -56,6 +56,7 @@ __exportStar(require("./resultify.js"), exports);
56
56
  __exportStar(require("./secToString.js"), exports);
57
57
  __exportStar(require("./sort-factory.js"), exports);
58
58
  __exportStar(require("./sort.js"), exports);
59
+ __exportStar(require("./stripWhitespace.js"), exports);
59
60
  __exportStar(require("./suffix.js"), exports);
60
61
  __exportStar(require("./toPascalCase.js"), exports);
61
62
  __exportStar(require("./trimEnd.js"), exports);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEmpty = isEmpty;
4
4
  const isLengthAware_js_1 = require("./predicate/isLengthAware.js");
5
5
  function isEmpty(input) {
6
- if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
6
+ if (input == null || (typeof input === 'string' && !input.length)) {
7
7
  return true;
8
8
  }
9
9
  if (input instanceof Set || input instanceof Map) {
@@ -13,7 +13,7 @@ function isEmpty(input) {
13
13
  return input.length === 0;
14
14
  }
15
15
  if (typeof input === 'object') {
16
- return Object.getOwnPropertyNames(input).length === 0 && Object.getOwnPropertySymbols(input).length === 0;
16
+ return Reflect.ownKeys(input).length === 0;
17
17
  }
18
18
  return false;
19
19
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIsInstanceOfPredicate = void 0;
4
+ const createIsInstanceOfPredicate = (constructor) => (input) => input instanceof constructor;
5
+ exports.createIsInstanceOfPredicate = createIsInstanceOfPredicate;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIsTuplePredicate = void 0;
4
+ const createIsTuplePredicate = (tupleShape) => {
5
+ return (input) => Array.isArray(input) && input.length === tupleShape.length
6
+ ? input.every((value, index) => {
7
+ const item = tupleShape[index];
8
+ return typeof item === 'function' ? item(value) : Object.is(value, item);
9
+ })
10
+ : false;
11
+ };
12
+ exports.createIsTuplePredicate = createIsTuplePredicate;
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./allOf.js"), exports);
18
18
  __exportStar(require("./anyOf.js"), exports);
19
19
  __exportStar(require("./createIsEnumPredicate.js"), exports);
20
+ __exportStar(require("./createIsInstanceOfPredicate.js"), exports);
21
+ __exportStar(require("./createIsTuplePredicate.js"), exports);
20
22
  __exportStar(require("./createStringMatchingPredicate.js"), exports);
21
23
  __exportStar(require("./everyItem.js"), exports);
22
24
  __exportStar(require("./maybeArray.js"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripWhitespace = void 0;
4
+ const stripWhitespace = (input) => input.replace(/\s+/g, '');
5
+ exports.stripWhitespace = stripWhitespace;
package/dist/cjs/until.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDelay = exports.isDelay = void 0;
4
4
  exports.until = until;
5
+ const asError_js_1 = require("./asError.js");
5
6
  const getType_js_1 = require("./getType.js");
6
7
  const defaultOptions = {
7
8
  delay: 10,
@@ -71,7 +72,7 @@ function until(fn, options = defaultOptions) {
71
72
  }
72
73
  }
73
74
  catch (error) {
74
- rejectFn(error instanceof Error ? error : new Error(`${error}`));
75
+ rejectFn((0, asError_js_1.asError)(error));
75
76
  }
76
77
  };
77
78
  callUntilDone(fn, delay, resolve, reject);
package/dist/mjs/index.js CHANGED
@@ -40,6 +40,7 @@ export * from './resultify.js';
40
40
  export * from './secToString.js';
41
41
  export * from './sort-factory.js';
42
42
  export * from './sort.js';
43
+ export * from './stripWhitespace.js';
43
44
  export * from './suffix.js';
44
45
  export * from './toPascalCase.js';
45
46
  export * from './trimEnd.js';
@@ -1,6 +1,6 @@
1
1
  import { isLengthAware } from './predicate/isLengthAware.js';
2
2
  export function isEmpty(input) {
3
- if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
3
+ if (input == null || (typeof input === 'string' && !input.length)) {
4
4
  return true;
5
5
  }
6
6
  if (input instanceof Set || input instanceof Map) {
@@ -10,7 +10,7 @@ export function isEmpty(input) {
10
10
  return input.length === 0;
11
11
  }
12
12
  if (typeof input === 'object') {
13
- return Object.getOwnPropertyNames(input).length === 0 && Object.getOwnPropertySymbols(input).length === 0;
13
+ return Reflect.ownKeys(input).length === 0;
14
14
  }
15
15
  return false;
16
16
  }
@@ -0,0 +1 @@
1
+ export const createIsInstanceOfPredicate = (constructor) => (input) => input instanceof constructor;
@@ -0,0 +1,8 @@
1
+ export const createIsTuplePredicate = (tupleShape) => {
2
+ return (input) => Array.isArray(input) && input.length === tupleShape.length
3
+ ? input.every((value, index) => {
4
+ const item = tupleShape[index];
5
+ return typeof item === 'function' ? item(value) : Object.is(value, item);
6
+ })
7
+ : false;
8
+ };
@@ -1,6 +1,8 @@
1
1
  export * from './allOf.js';
2
2
  export * from './anyOf.js';
3
3
  export * from './createIsEnumPredicate.js';
4
+ export * from './createIsInstanceOfPredicate.js';
5
+ export * from './createIsTuplePredicate.js';
4
6
  export * from './createStringMatchingPredicate.js';
5
7
  export * from './everyItem.js';
6
8
  export * from './maybeArray.js';
@@ -0,0 +1 @@
1
+ export const stripWhitespace = (input) => input.replace(/\s+/g, '');
package/dist/mjs/until.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { asError } from './asError.js';
1
2
  import { getType } from './getType.js';
2
3
  const defaultOptions = {
3
4
  delay: 10,
@@ -65,7 +66,7 @@ export function until(fn, options = defaultOptions) {
65
66
  }
66
67
  }
67
68
  catch (error) {
68
- rejectFn(error instanceof Error ? error : new Error(`${error}`));
69
+ rejectFn(asError(error));
69
70
  }
70
71
  };
71
72
  callUntilDone(fn, delay, resolve, reject);
@@ -40,6 +40,7 @@ export * from './resultify.js';
40
40
  export * from './secToString.js';
41
41
  export * from './sort-factory.js';
42
42
  export * from './sort.js';
43
+ export * from './stripWhitespace.js';
43
44
  export * from './suffix.js';
44
45
  export * from './toPascalCase.js';
45
46
  export * from './trimEnd.js';
@@ -0,0 +1,3 @@
1
+ import type { AnyNewable } from '../types/common.js';
2
+ import type { TypePredicateFn } from '../types/functions.js';
3
+ export declare const createIsInstanceOfPredicate: <T extends AnyNewable>(constructor: T) => TypePredicateFn<InstanceType<T>>;
@@ -0,0 +1,7 @@
1
+ import type { Primitive } from '../types/common.js';
2
+ import type { TypePredicateFn } from '../types/functions.js';
3
+ export type TuplePredicateInput = (Primitive | TypePredicateFn<unknown>)[];
4
+ export type GetTupleFromInput<Type extends TuplePredicateInput> = {
5
+ [Property in keyof Type]: Type[Property] extends TypePredicateFn<infer T> ? T : Type[Property];
6
+ };
7
+ export declare const createIsTuplePredicate: <const Input extends TuplePredicateInput>(tupleShape: Input) => TypePredicateFn<GetTupleFromInput<Input>>;
@@ -1,6 +1,8 @@
1
1
  export * from './allOf.js';
2
2
  export * from './anyOf.js';
3
3
  export * from './createIsEnumPredicate.js';
4
+ export * from './createIsInstanceOfPredicate.js';
5
+ export * from './createIsTuplePredicate.js';
4
6
  export * from './createStringMatchingPredicate.js';
5
7
  export * from './everyItem.js';
6
8
  export * from './maybeArray.js';
@@ -0,0 +1,2 @@
1
+ import type { StripWhitespace } from './types/strings.js';
2
+ export declare const stripWhitespace: <T extends string>(input: T) => StripWhitespace<T>;
@@ -4,7 +4,7 @@ export type AlphaCharacter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i'
4
4
  export type NumericCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
5
5
  export type AlphanumericCharacter = AlphaCharacter | Capitalize<AlphaCharacter> | NumericCharacter;
6
6
  export type MaybePlural<T extends string> = T | `${T}s`;
7
- export type StripWhitespace<Type extends string> = Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
7
+ export type StripWhitespace<Type extends string> = string extends Type ? Type : Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
8
8
  export type AlphanumericOnly<Type extends string> = Type extends EmptyString ? EmptyString : Type extends `${infer First}${infer Rest}` ? First extends AlphanumericCharacter | Space ? `${First}${AlphanumericOnly<Rest>}` : Rest extends EmptyString ? Rest : `${Space}${AlphanumericOnly<Rest>}` : never;
9
9
  export type Replace<Type extends string, Remove extends string, Replacement extends string> = Type extends `${infer First}${infer Rest}` ? First extends Remove ? `${Replacement}${Replace<Rest, Remove, Replacement>}` : `${First}${Replace<Rest, Remove, Replacement>}` : EmptyString;
10
10
  export type Strip<Type extends string, Remove extends string> = Replace<Type, Remove, EmptyString>;
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.42.0",
4
+ "version": "0.44.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
69
+ "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -87,26 +87,26 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/config-conventional": "^19.6.0",
89
89
  "@commitlint/types": "^19.5.0",
90
- "@types/node": "^22.10.2",
91
- "@vitest/coverage-v8": "^2.1.8",
90
+ "@types/node": "^22.10.7",
91
+ "@vitest/coverage-v8": "^3.0.2",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
94
  "commitlint": "^19.6.1",
95
95
  "commitlint-plugin-cspell": "^0.1.1",
96
96
  "conventional-changelog-conventionalcommits": "^8.0.0",
97
- "cspell": "^8.17.1",
97
+ "cspell": "^8.17.2",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-prettier": "^9.1.0",
100
100
  "eslint-import-resolver-typescript": "^3.7.0",
101
101
  "eslint-plugin-import": "^2.31.0",
102
102
  "husky": "^9.1.7",
103
- "jsdom": "^25.0.1",
104
- "lint-staged": "^15.2.11",
103
+ "jsdom": "^26.0.0",
104
+ "lint-staged": "^15.4.1",
105
105
  "prettier": "^3.4.2",
106
106
  "rimraf": "^6.0.1",
107
- "semantic-release": "^24.2.0",
108
- "typescript": "^5.7.2",
107
+ "semantic-release": "^24.2.1",
108
+ "typescript": "^5.7.3",
109
109
  "validate-package-exports": "^0.8.0",
110
- "vitest": "^2.1.8"
110
+ "vitest": "^3.0.2"
111
111
  }
112
112
  }