@etsoo/shared 1.2.7 → 1.2.8

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/README.md CHANGED
@@ -41,6 +41,9 @@ Content disposition of HTTP
41
41
  |Methods||
42
42
  |format|Format to standard output|
43
43
 
44
+ ## DataError
45
+ Error with custom data
46
+
44
47
  ## EColor
45
48
  Etsoo implmented Color
46
49
 
@@ -60,7 +60,7 @@ var NumberUtils;
60
60
  const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
61
61
  return ((size / Math.pow(1024, i)).toFixed(fractionDigits) +
62
62
  ' ' +
63
- ['B', 'KB', 'MB', 'GB', 'TB'][i]);
63
+ ['B', 'KB', 'MB', 'GB', 'TB', 'PB'][i]);
64
64
  }
65
65
  NumberUtils.formatFileSize = formatFileSize;
66
66
  /**
@@ -1,4 +1,5 @@
1
1
  export * from './types/ContentDisposition';
2
+ export * from './types/DataError';
2
3
  export * from './types/DelayedExecutorType';
3
4
  export * from './types/EColor';
4
5
  export * from './types/EHistory';
package/lib/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types/ContentDisposition"), exports);
18
+ __exportStar(require("./types/DataError"), exports);
18
19
  __exportStar(require("./types/DelayedExecutorType"), exports);
19
20
  __exportStar(require("./types/EColor"), exports);
20
21
  __exportStar(require("./types/EHistory"), exports);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Error with custom data
3
+ * Other information can be hold by 'name', 'cause', and 'stack' property
4
+ *
5
+ */
6
+ export declare class DataError<T = Record<string, unknown>> extends Error {
7
+ /**
8
+ * Custom data
9
+ */
10
+ readonly data: T;
11
+ /**
12
+ * Constructor
13
+ * @param message Error message
14
+ * @param data Custom data
15
+ */
16
+ constructor(message: string, data: T);
17
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataError = void 0;
4
+ /**
5
+ * Error with custom data
6
+ * Other information can be hold by 'name', 'cause', and 'stack' property
7
+ *
8
+ */
9
+ class DataError extends Error {
10
+ /**
11
+ * Constructor
12
+ * @param message Error message
13
+ * @param data Custom data
14
+ */
15
+ constructor(message, data) {
16
+ super(message);
17
+ this.data = data;
18
+ // Set the prototype explicitly to ensure instanceof works correctly
19
+ Object.setPrototypeOf(this, DataError.prototype);
20
+ }
21
+ }
22
+ exports.DataError = DataError;
@@ -57,7 +57,7 @@ export var NumberUtils;
57
57
  const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
58
58
  return ((size / Math.pow(1024, i)).toFixed(fractionDigits) +
59
59
  ' ' +
60
- ['B', 'KB', 'MB', 'GB', 'TB'][i]);
60
+ ['B', 'KB', 'MB', 'GB', 'TB', 'PB'][i]);
61
61
  }
62
62
  NumberUtils.formatFileSize = formatFileSize;
63
63
  /**
@@ -1,4 +1,5 @@
1
1
  export * from './types/ContentDisposition';
2
+ export * from './types/DataError';
2
3
  export * from './types/DelayedExecutorType';
3
4
  export * from './types/EColor';
4
5
  export * from './types/EHistory';
package/lib/mjs/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types/ContentDisposition';
2
+ export * from './types/DataError';
2
3
  export * from './types/DelayedExecutorType';
3
4
  export * from './types/EColor';
4
5
  export * from './types/EHistory';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Error with custom data
3
+ * Other information can be hold by 'name', 'cause', and 'stack' property
4
+ *
5
+ */
6
+ export declare class DataError<T = Record<string, unknown>> extends Error {
7
+ /**
8
+ * Custom data
9
+ */
10
+ readonly data: T;
11
+ /**
12
+ * Constructor
13
+ * @param message Error message
14
+ * @param data Custom data
15
+ */
16
+ constructor(message: string, data: T);
17
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Error with custom data
3
+ * Other information can be hold by 'name', 'cause', and 'stack' property
4
+ *
5
+ */
6
+ export class DataError extends Error {
7
+ /**
8
+ * Constructor
9
+ * @param message Error message
10
+ * @param data Custom data
11
+ */
12
+ constructor(message, data) {
13
+ super(message);
14
+ this.data = data;
15
+ // Set the prototype explicitly to ensure instanceof works correctly
16
+ Object.setPrototypeOf(this, DataError.prototype);
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,12 +54,12 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^29.5.2",
57
+ "@types/jest": "^29.5.3",
58
58
  "@types/lodash.isequal": "^4.5.6",
59
- "jest": "^29.5.0",
60
- "jest-environment-jsdom": "^29.5.0",
61
- "ts-jest": "^29.1.0",
62
- "typescript": "^5.1.3"
59
+ "jest": "^29.6.1",
60
+ "jest-environment-jsdom": "^29.6.1",
61
+ "ts-jest": "^29.1.1",
62
+ "typescript": "^5.1.6"
63
63
  },
64
64
  "dependencies": {
65
65
  "lodash.isequal": "^4.5.0"
@@ -77,7 +77,7 @@ export namespace NumberUtils {
77
77
  return (
78
78
  (size / Math.pow(1024, i)).toFixed(fractionDigits) +
79
79
  ' ' +
80
- ['B', 'KB', 'MB', 'GB', 'TB'][i]
80
+ ['B', 'KB', 'MB', 'GB', 'TB', 'PB'][i]
81
81
  );
82
82
  }
83
83
 
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types/ContentDisposition';
2
+ export * from './types/DataError';
2
3
  export * from './types/DelayedExecutorType';
3
4
  export * from './types/EColor';
4
5
  export * from './types/EHistory';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Error with custom data
3
+ * Other information can be hold by 'name', 'cause', and 'stack' property
4
+ *
5
+ */
6
+ export class DataError<T = Record<string, unknown>> extends Error {
7
+ /**
8
+ * Custom data
9
+ */
10
+ public readonly data: T;
11
+
12
+ /**
13
+ * Constructor
14
+ * @param message Error message
15
+ * @param data Custom data
16
+ */
17
+ constructor(message: string, data: T) {
18
+ super(message);
19
+
20
+ this.data = data;
21
+
22
+ // Set the prototype explicitly to ensure instanceof works correctly
23
+ Object.setPrototypeOf(this, DataError.prototype);
24
+ }
25
+ }