@duplojs/utils 1.3.25 → 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.
@@ -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 };