@poppinss/utils 6.1.0-0 → 6.2.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/README.md +12 -13
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/src/exception.d.ts +5 -0
- package/build/src/exception.js +11 -0
- package/build/src/exceptions/runtime_exception.d.ts +4 -0
- package/build/src/exceptions/runtime_exception.js +4 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -33,8 +33,8 @@ Even though I do not care much about the package size (most of work is consumed
|
|
|
33
33
|
|
|
34
34
|
| | |
|
|
35
35
|
| ----------------- | --------------- |
|
|
36
|
-
| Source code size | `
|
|
37
|
-
| Dependencies size | `
|
|
36
|
+
| Source code size | `436K` (approx) |
|
|
37
|
+
| Dependencies size | `496K` (approx) |
|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
@@ -771,19 +771,18 @@ class ResourceNotFound extends Exception {
|
|
|
771
771
|
throw new ResourceNotFound()
|
|
772
772
|
```
|
|
773
773
|
|
|
774
|
-
|
|
774
|
+
#### Anonymous error classes
|
|
775
|
+
You can also create an anonymous exception class using the `createError` method. The return value is a class
|
|
776
|
+
constructor that accepts an array of values to use for interpolation.
|
|
775
777
|
|
|
776
|
-
|
|
777
|
-
import { Exception } from '@poppinss/utils'
|
|
778
|
-
import string from '@poppinss/utils/string'
|
|
778
|
+
The interpolation of error message is performed using the `util.format` message.
|
|
779
779
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
static message = 'Unable to find resource with id {{ id }}'
|
|
784
|
-
}
|
|
780
|
+
```ts
|
|
781
|
+
import { createError } from '@poppinss/utils'
|
|
782
|
+
const E_RESOURCE_NOT_FOUND = createError('Unable to find resource with id %d', 'E_RESOURCE_NOT_FOUND')
|
|
785
783
|
|
|
786
|
-
|
|
784
|
+
const id = 1
|
|
785
|
+
throw new E_RESOURCE_NOT_FOUND([id])
|
|
787
786
|
```
|
|
788
787
|
|
|
789
788
|
#### flatten
|
|
@@ -1074,7 +1073,7 @@ const dirname = getDirname(import.meta.url)
|
|
|
1074
1073
|
const filename = getFilename(import.meta.url)
|
|
1075
1074
|
```
|
|
1076
1075
|
|
|
1077
|
-
[gh-workflow-image]: https://img.shields.io/github/workflow/status/poppinss/utils/test?style=for-the-badge
|
|
1076
|
+
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/utils/test.yml?style=for-the-badge
|
|
1078
1077
|
[gh-workflow-url]: https://github.com/poppinss/utils/actions/workflows/test.yml 'Github action'
|
|
1079
1078
|
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
|
1080
1079
|
[typescript-url]: "typescript"
|
package/build/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { base64 } from './src/base64.js';
|
|
3
3
|
export { compose } from './src/compose.js';
|
|
4
4
|
export { defineStaticProperty } from './src/define_static_property.js';
|
|
5
|
-
export { Exception } from './src/exception.js';
|
|
5
|
+
export { Exception, createError } from './src/exception.js';
|
|
6
6
|
export { flatten } from './src/flatten.js';
|
|
7
7
|
export { fsImportAll } from './src/fs_import_all.js';
|
|
8
8
|
export { fsReadAll } from './src/fs_read_all.js';
|
|
@@ -12,6 +12,6 @@ export { naturalSort } from './src/natural_sort.js';
|
|
|
12
12
|
export { ObjectBuilder } from './src/object_builder.js';
|
|
13
13
|
export { safeEqual } from './src/safe_equal.js';
|
|
14
14
|
export { slash } from './src/slash.js';
|
|
15
|
-
export { RuntimeException } from './src/exceptions/runtime_exception.js';
|
|
15
|
+
export { RuntimeException, InvalidArgumentExceptiom } from './src/exceptions/runtime_exception.js';
|
|
16
16
|
export declare function getDirname(url: string | URL): string;
|
|
17
17
|
export declare function getFilename(url: string | URL): string;
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { dirname as pathDirname } from 'node:path';
|
|
|
3
3
|
export { base64 } from './src/base64.js';
|
|
4
4
|
export { compose } from './src/compose.js';
|
|
5
5
|
export { defineStaticProperty } from './src/define_static_property.js';
|
|
6
|
-
export { Exception } from './src/exception.js';
|
|
6
|
+
export { Exception, createError } from './src/exception.js';
|
|
7
7
|
export { flatten } from './src/flatten.js';
|
|
8
8
|
export { fsImportAll } from './src/fs_import_all.js';
|
|
9
9
|
export { fsReadAll } from './src/fs_read_all.js';
|
|
@@ -13,7 +13,7 @@ export { naturalSort } from './src/natural_sort.js';
|
|
|
13
13
|
export { ObjectBuilder } from './src/object_builder.js';
|
|
14
14
|
export { safeEqual } from './src/safe_equal.js';
|
|
15
15
|
export { slash } from './src/slash.js';
|
|
16
|
-
export { RuntimeException } from './src/exceptions/runtime_exception.js';
|
|
16
|
+
export { RuntimeException, InvalidArgumentExceptiom } from './src/exceptions/runtime_exception.js';
|
|
17
17
|
export function getDirname(url) {
|
|
18
18
|
return pathDirname(getFilename(url));
|
|
19
19
|
}
|
package/build/src/exception.d.ts
CHANGED
|
@@ -14,3 +14,8 @@ export declare class Exception extends Error {
|
|
|
14
14
|
get [Symbol.toStringTag](): string;
|
|
15
15
|
toString(): string;
|
|
16
16
|
}
|
|
17
|
+
export declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
|
18
|
+
new (args?: any, options?: ErrorOptions): Exception;
|
|
19
|
+
} : {
|
|
20
|
+
new (args: T, options?: ErrorOptions): Exception;
|
|
21
|
+
};
|
package/build/src/exception.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { format } from 'node:util';
|
|
1
2
|
export class Exception extends Error {
|
|
2
3
|
name;
|
|
3
4
|
status;
|
|
@@ -27,3 +28,13 @@ export class Exception extends Error {
|
|
|
27
28
|
return `${this.name}: ${this.message}`;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
export function createError(message, code, status) {
|
|
32
|
+
return class extends Exception {
|
|
33
|
+
static message = message;
|
|
34
|
+
static code = code;
|
|
35
|
+
static status = status;
|
|
36
|
+
constructor(args, options) {
|
|
37
|
+
super(format(message, ...(args || [])), options);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -60,25 +60,25 @@
|
|
|
60
60
|
"@japa/run-failed-tests": "^1.1.0",
|
|
61
61
|
"@japa/runner": "^2.2.2",
|
|
62
62
|
"@japa/spec-reporter": "^1.3.2",
|
|
63
|
-
"@swc/core": "^1.3.
|
|
63
|
+
"@swc/core": "^1.3.24",
|
|
64
64
|
"@types/fs-extra": "^9.0.13",
|
|
65
|
-
"@types/node": "^18.11.
|
|
65
|
+
"@types/node": "^18.11.18",
|
|
66
66
|
"c8": "^7.12.0",
|
|
67
67
|
"del-cli": "^5.0.0",
|
|
68
|
-
"eslint": "^8.
|
|
68
|
+
"eslint": "^8.30.0",
|
|
69
69
|
"eslint-config-prettier": "^8.5.0",
|
|
70
70
|
"eslint-plugin-adonis": "^3.0.3",
|
|
71
71
|
"eslint-plugin-prettier": "^4.2.1",
|
|
72
|
-
"fs-extra": "^11.
|
|
72
|
+
"fs-extra": "^11.1.0",
|
|
73
73
|
"github-label-sync": "^2.2.0",
|
|
74
74
|
"husky": "^8.0.1",
|
|
75
75
|
"lodash": "^4.17.21",
|
|
76
76
|
"lodash-cli": "^4.17.5",
|
|
77
77
|
"move-file-cli": "^3.0.0",
|
|
78
|
-
"np": "^7.6.
|
|
79
|
-
"prettier": "^2.8.
|
|
78
|
+
"np": "^7.6.3",
|
|
79
|
+
"prettier": "^2.8.1",
|
|
80
80
|
"ts-node": "^10.9.1",
|
|
81
|
-
"typescript": "^4.9.
|
|
81
|
+
"typescript": "^4.9.4"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@lukeed/ms": "^2.0.0",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"case-anything": "^2.1.10",
|
|
89
89
|
"flattie": "^1.1.0",
|
|
90
90
|
"pluralize": "^8.0.0",
|
|
91
|
-
"safe-stable-stringify": "^2.4.
|
|
92
|
-
"secure-json-parse": "^2.
|
|
91
|
+
"safe-stable-stringify": "^2.4.2",
|
|
92
|
+
"secure-json-parse": "^2.6.0",
|
|
93
93
|
"slash": "^5.0.0",
|
|
94
94
|
"slugify": "^1.6.5",
|
|
95
95
|
"truncatise": "^0.0.8"
|