@duplojs/utils 1.3.24 → 1.3.26

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.
@@ -43,6 +43,7 @@ var chunk = require('./chunk.cjs');
43
43
  var insert$2 = require('./insert.cjs');
44
44
  var isLastIndex = require('./isLastIndex.cjs');
45
45
  var select = require('./select.cjs');
46
+ var lengthEqual = require('./lengthEqual.cjs');
46
47
  var _delete = require('./splice/delete.cjs');
47
48
  var insert = require('./splice/insert.cjs');
48
49
  var replace = require('./splice/replace.cjs');
@@ -104,6 +105,7 @@ exports.insert = insert$2.insert;
104
105
  exports.isLastIndex = isLastIndex.isLastIndex;
105
106
  exports.select = select.select;
106
107
  exports.selectTools = select.selectTools;
108
+ exports.lengthEqual = lengthEqual.lengthEqual;
107
109
  exports.spliceDelete = _delete.spliceDelete;
108
110
  exports.spliceInsert = insert.spliceInsert;
109
111
  exports.spliceReplace = replace.spliceReplace;
@@ -46,3 +46,4 @@ export * from "./chunk";
46
46
  export * from "./insert";
47
47
  export * from "./isLastIndex";
48
48
  export * from "./select";
49
+ export * from "./lengthEqual";
@@ -41,6 +41,7 @@ export { chunk } from './chunk.mjs';
41
41
  export { insert } from './insert.mjs';
42
42
  export { isLastIndex } from './isLastIndex.mjs';
43
43
  export { select, selectTools } from './select.mjs';
44
+ export { lengthEqual } from './lengthEqual.mjs';
44
45
  export { spliceDelete } from './splice/delete.mjs';
45
46
  export { spliceInsert } from './splice/insert.mjs';
46
47
  export { spliceReplace } from './splice/replace.mjs';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ function lengthEqual(...args) {
4
+ if (args.length === 1) {
5
+ const [minLength] = args;
6
+ return (array) => lengthEqual(array, minLength);
7
+ }
8
+ const [array, minLength] = args;
9
+ return array.length === minLength;
10
+ }
11
+
12
+ exports.lengthEqual = lengthEqual;
@@ -0,0 +1,3 @@
1
+ import { type CreateTuple } from "./types";
2
+ export declare function lengthEqual<GenericArray extends readonly unknown[], GenericLength extends number>(length: GenericLength): (array: GenericArray) => array is CreateTuple<GenericArray[number], GenericLength>;
3
+ export declare function lengthEqual<GenericArray extends readonly unknown[], GenericLength extends number>(array: GenericArray, length: GenericLength): array is CreateTuple<GenericArray[number], GenericLength>;
@@ -0,0 +1,10 @@
1
+ function lengthEqual(...args) {
2
+ if (args.length === 1) {
3
+ const [minLength] = args;
4
+ return (array) => lengthEqual(array, minLength);
5
+ }
6
+ const [array, minLength] = args;
7
+ return array.length === minLength;
8
+ }
9
+
10
+ export { lengthEqual };
@@ -1,2 +1,2 @@
1
1
  import { type IsEqual } from "../../common/types/isEqual";
2
- export type CreateTuple<GenericValue extends unknown, GenericLength extends number, GenericLastTuple extends unknown[] = []> = IsEqual<GenericLength, number> extends true ? GenericValue[] : [...GenericLastTuple, GenericValue] extends infer InferredResult extends any[] ? IsEqual<InferredResult["length"], GenericLength> extends true ? InferredResult : IsEqual<InferredResult["length"], 1000> extends true ? [...InferredResult, ...GenericValue[]] : CreateTuple<GenericValue, GenericLength, InferredResult> : never;
2
+ export type CreateTuple<GenericValue extends unknown, GenericLength extends number, GenericLastTuple extends unknown[] = []> = IsEqual<GenericLength, number> extends true ? GenericValue[] : IsEqual<GenericLength, 0> extends true ? [] : [...GenericLastTuple, GenericValue] extends infer InferredResult extends any[] ? IsEqual<InferredResult["length"], GenericLength> extends true ? InferredResult : IsEqual<InferredResult["length"], 1000> extends true ? [...InferredResult, ...GenericValue[]] : CreateTuple<GenericValue, GenericLength, InferredResult> : never;
@@ -30,6 +30,14 @@ function date(definition) {
30
30
  const isNegative = data < 0;
31
31
  return `date${Math.abs(data)}${isNegative ? "-" : "+"}`;
32
32
  }
33
+ if (typeof data === "string") {
34
+ const date = new Date(data);
35
+ const timestamp = date.getTime();
36
+ if (isSafeTimestamp.isSafeTimestamp(timestamp)) {
37
+ const isNegative = timestamp < 0;
38
+ return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
39
+ }
40
+ }
33
41
  }
34
42
  const theDateMatch = typeof data === "string" && data.match(constants.theDateRegex);
35
43
  if (theDateMatch) {
@@ -28,6 +28,14 @@ function date(definition) {
28
28
  const isNegative = data < 0;
29
29
  return `date${Math.abs(data)}${isNegative ? "-" : "+"}`;
30
30
  }
31
+ if (typeof data === "string") {
32
+ const date = new Date(data);
33
+ const timestamp = date.getTime();
34
+ if (isSafeTimestamp(timestamp)) {
35
+ const isNegative = timestamp < 0;
36
+ return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
37
+ }
38
+ }
31
39
  }
32
40
  const theDateMatch = typeof data === "string" && data.match(theDateRegex);
33
41
  if (theDateMatch) {
@@ -3,6 +3,7 @@
3
3
  var hasInformation = require('./hasInformation.cjs');
4
4
  var whenHasInformation = require('./whenHasInformation.cjs');
5
5
  var kind = require('./kind.cjs');
6
+ var safeCallback = require('./safeCallback.cjs');
6
7
  var create = require('./bool/create.cjs');
7
8
  var falsy = require('./bool/falsy.cjs');
8
9
  var truthy = require('./bool/truthy.cjs');
@@ -44,6 +45,9 @@ exports.hasInformation = hasInformation.hasInformation;
44
45
  exports.whenHasInformation = whenHasInformation.whenHasInformation;
45
46
  exports.createEitherKind = kind.createEitherKind;
46
47
  exports.eitherInformationKind = kind.eitherInformationKind;
48
+ exports.callbackError = safeCallback.callbackError;
49
+ exports.eitherCallbackErrorKind = safeCallback.eitherCallbackErrorKind;
50
+ exports.safeCallback = safeCallback.safeCallback;
47
51
  exports.bool = create.bool;
48
52
  exports.boolFalsy = falsy.boolFalsy;
49
53
  exports.eitherBoolFalsyKind = falsy.eitherBoolFalsyKind;
@@ -8,3 +8,4 @@ export * from "./right";
8
8
  export * from "./hasInformation";
9
9
  export * from "./whenHasInformation";
10
10
  export * from "./kind";
11
+ export * from "./safeCallback";
@@ -1,6 +1,7 @@
1
1
  export { hasInformation } from './hasInformation.mjs';
2
2
  export { whenHasInformation } from './whenHasInformation.mjs';
3
3
  export { createEitherKind, eitherInformationKind } from './kind.mjs';
4
+ export { callbackError, eitherCallbackErrorKind, safeCallback } from './safeCallback.mjs';
4
5
  export { bool } from './bool/create.mjs';
5
6
  export { boolFalsy, eitherBoolFalsyKind, isBoolFalsy, whenIsBoolFalsy } from './bool/falsy.mjs';
6
7
  export { boolTruthy, eitherBoolTruthyKind, isBoolTruthy, whenIsBoolTruthy } from './bool/truthy.mjs';
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var kind = require('./kind.cjs');
4
+ var create = require('./left/create.cjs');
5
+
6
+ const eitherCallbackErrorKind = kind.createEitherKind("callback-error");
7
+ function callbackError(value) {
8
+ return eitherCallbackErrorKind.setTo(create.left("callback", value));
9
+ }
10
+ function safeCallback(theFunction) {
11
+ try {
12
+ return theFunction();
13
+ }
14
+ catch (error) {
15
+ return callbackError(error);
16
+ }
17
+ }
18
+
19
+ exports.callbackError = callbackError;
20
+ exports.eitherCallbackErrorKind = eitherCallbackErrorKind;
21
+ exports.safeCallback = safeCallback;
@@ -0,0 +1,9 @@
1
+ import { type Kind } from "../common";
2
+ import { type EitherLeft } from "./left";
3
+ export declare const eitherCallbackErrorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-error", unknown>>;
4
+ type _EitherCallbackError = (EitherLeft<"callback", unknown> & Kind<typeof eitherCallbackErrorKind.definition>);
5
+ export interface EitherCallbackError extends _EitherCallbackError {
6
+ }
7
+ export declare function callbackError(value: unknown): EitherCallbackError;
8
+ export declare function safeCallback<GenericOutput extends unknown>(theFunction: () => GenericOutput): GenericOutput | EitherCallbackError;
9
+ export {};
@@ -0,0 +1,17 @@
1
+ import { createEitherKind } from './kind.mjs';
2
+ import { left } from './left/create.mjs';
3
+
4
+ const eitherCallbackErrorKind = createEitherKind("callback-error");
5
+ function callbackError(value) {
6
+ return eitherCallbackErrorKind.setTo(left("callback", value));
7
+ }
8
+ function safeCallback(theFunction) {
9
+ try {
10
+ return theFunction();
11
+ }
12
+ catch (error) {
13
+ return callbackError(error);
14
+ }
15
+ }
16
+
17
+ export { callbackError, eitherCallbackErrorKind, safeCallback };