@poppinss/utils 6.0.1-0 → 6.2.0-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 +9 -10
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/build/src/define_static_property.d.ts +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 +5 -0
- package/build/src/exceptions/runtime_exception.js +5 -0
- package/build/src/safe_equal.d.ts +1 -1
- package/build/src/types.d.ts +9 -9
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -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
|
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,5 +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
16
|
export declare function getDirname(url: string | URL): string;
|
|
16
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,6 +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
17
|
export function getDirname(url) {
|
|
17
18
|
return pathDirname(getFilename(url));
|
|
18
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type Constructor = new (...args: any[]) => any;
|
|
2
|
+
type AbstractConstructor = abstract new (...args: any[]) => any;
|
|
3
3
|
export declare function defineStaticProperty<T extends Constructor | AbstractConstructor, Prop extends keyof T>(self: T, propertyName: Prop, { initialValue, strategy, }: {
|
|
4
4
|
initialValue: T[Prop];
|
|
5
5
|
strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop]);
|
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/build/src/types.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
type PickKeysByValue<T, V> = {
|
|
2
2
|
[K in keyof T]: T[K] extends V ? K : never;
|
|
3
3
|
}[keyof T];
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export type OmitProperties<T, P> = Omit<T, PickKeysByValue<T, P>>;
|
|
5
|
+
type ScanFsBaseOptions = {
|
|
6
6
|
ignoreMissingRoot?: boolean;
|
|
7
7
|
filter?: (filePath: string, index: number) => boolean;
|
|
8
8
|
sort?: (current: string, next: string) => number;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type ImportAllFilesOptions = ScanFsBaseOptions & {
|
|
11
11
|
transformKeys?: (keys: string[]) => string[];
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type ReadAllFilesOptions = ScanFsBaseOptions & {
|
|
14
14
|
pathType?: 'relative' | 'unixRelative' | 'absolute' | 'unixAbsolute' | 'url';
|
|
15
15
|
};
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
16
|
+
export type JSONReplacer = (this: any, key: string, value: any) => any;
|
|
17
|
+
export type JSONReviver = (this: any, key: string, value: any) => any;
|
|
18
|
+
export type Constructor = new (...args: any[]) => any;
|
|
19
|
+
export type NormalizeConstructor<T extends Constructor> = {
|
|
20
20
|
new (...args: any[]): InstanceType<T>;
|
|
21
21
|
} & Omit<T, 'constructor'>;
|
|
22
22
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/utils",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.2.0-0",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -53,32 +53,32 @@
|
|
|
53
53
|
"author": "virk,poppinss",
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@commitlint/cli": "^17.
|
|
57
|
-
"@commitlint/config-conventional": "^17.
|
|
56
|
+
"@commitlint/cli": "^17.3.0",
|
|
57
|
+
"@commitlint/config-conventional": "^17.3.0",
|
|
58
58
|
"@japa/assert": "^1.3.6",
|
|
59
59
|
"@japa/expect-type": "^1.0.2",
|
|
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.23",
|
|
64
64
|
"@types/fs-extra": "^9.0.13",
|
|
65
|
-
"@types/node": "^18.11.
|
|
65
|
+
"@types/node": "^18.11.15",
|
|
66
66
|
"c8": "^7.12.0",
|
|
67
67
|
"del-cli": "^5.0.0",
|
|
68
|
-
"eslint": "^8.
|
|
68
|
+
"eslint": "^8.29.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": "^
|
|
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
78
|
"np": "^7.6.2",
|
|
79
|
-
"prettier": "^2.
|
|
79
|
+
"prettier": "^2.8.1",
|
|
80
80
|
"ts-node": "^10.9.1",
|
|
81
|
-
"typescript": "^4.
|
|
81
|
+
"typescript": "^4.9.4"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@lukeed/ms": "^2.0.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"flattie": "^1.1.0",
|
|
90
90
|
"pluralize": "^8.0.0",
|
|
91
91
|
"safe-stable-stringify": "^2.4.1",
|
|
92
|
-
"secure-json-parse": "^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"
|