diff --git a/package.json b/package.json index 951671a0..1a266f4a 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "typecheck:watch": "vitest typecheck" }, "dependencies": { - "@flex-development/errnode": "1.0.1", + "@flex-development/errnode": "1.2.0", "@flex-development/tutils": "6.0.0-alpha.7" }, "devDependencies": { diff --git a/src/internal/__tests__/err-invalid-arg-type.spec.ts b/src/internal/__tests__/err-invalid-arg-type.spec.ts deleted file mode 100644 index 241511bf..00000000 --- a/src/internal/__tests__/err-invalid-arg-type.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file Units Tests - ERR_INVALID_ARG_TYPE - * @module pathe/internal/tests/unit/ERR_INVALID_ARG_TYPE - */ - -import { ErrorCode, type NodeError } from '@flex-development/errnode' -import TestSubject from '../err-invalid-arg-type' - -describe('unit:internal/ERR_INVALID_ARG_TYPE', () => { - let result: NodeError - - beforeEach(() => { - result = new TestSubject('path', 'string', null) - }) - - it('should return TypeError instance', () => { - expect(result).to.be.instanceof(TypeError) - }) - - it('should set error code', () => { - // Arrange - const code: ErrorCode = ErrorCode.ERR_INVALID_ARG_TYPE - - // Expect - expect(result).to.have.property('code').equal(code) - }) - - it('should set error message', () => { - // Arrange - const message: string = - 'The "path" argument must be of type string. Received null' - - // Expect - expect(result).to.have.property('message').equal(message) - }) -}) diff --git a/src/internal/err-invalid-arg-type.ts b/src/internal/err-invalid-arg-type.ts deleted file mode 100644 index 7d3f90ed..00000000 --- a/src/internal/err-invalid-arg-type.ts +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file Internal - ERR_INVALID_ARG_TYPE - * @module pathe/internal/ERR_INVALID_ARG_TYPE - */ - -import { - createNodeError, - determineSpecificType, - ErrorCode, - type MessageFn, - type NodeError, - type NodeErrorConstructor -} from '@flex-development/errnode' - -/** - * Creates an [`ERR_INVALID_ARG_TYPE`][1] message. - * - * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_type - * - * @param {string} name - Name of invalid argument or property - * @param {string} expected - Expected type - * @param {unknown} actual - Value supplied by user - * @return {string} Error message - */ -const msg: MessageFn<[string, string, unknown]> = ( - name: string, - expected: string, - actual: unknown -): string => { - return [ - `The "${name}" argument must be of type ${expected}.`, - `Received ${determineSpecificType(actual)}` - ].join(' ') -} - -/** - * [`ERR_INVALID_ARG_TYPE`][1] model. - * - * Thrown when an argument of the wrong type was passed to a Node.js API. - * - * [1]: https://nodejs.org/api/errors.html#err_invalid_arg_type - * - * @class - * @implements {NodeError} - */ -const ERR_INVALID_ARG_TYPE: NodeErrorConstructor< - TypeErrorConstructor, - typeof msg -> = createNodeError(ErrorCode.ERR_INVALID_ARG_TYPE, TypeError, msg) - -export default ERR_INVALID_ARG_TYPE diff --git a/src/internal/validate-object.ts b/src/internal/validate-object.ts index c614c87c..890edacb 100644 --- a/src/internal/validate-object.ts +++ b/src/internal/validate-object.ts @@ -3,7 +3,7 @@ * @module pathe/internal/validateObject */ -import ERR_INVALID_ARG_TYPE from './err-invalid-arg-type' +import { ERR_INVALID_ARG_TYPE } from '@flex-development/errnode' /** * Checks if `value` is an object. diff --git a/src/internal/validate-string.ts b/src/internal/validate-string.ts index 873fed6d..621148ac 100644 --- a/src/internal/validate-string.ts +++ b/src/internal/validate-string.ts @@ -3,7 +3,7 @@ * @module pathe/internal/validateString */ -import ERR_INVALID_ARG_TYPE from './err-invalid-arg-type' +import { ERR_INVALID_ARG_TYPE } from '@flex-development/errnode' /** * Checks if `value` is a string. diff --git a/yarn.lock b/yarn.lock index 3353d945..dde87af0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -972,13 +972,15 @@ __metadata: languageName: node linkType: hard -"@flex-development/errnode@npm:1.0.1": - version: 1.0.1 - resolution: "@flex-development/errnode@npm:1.0.1::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40flex-development%2Ferrnode%2F1.0.1%2F3314864efc1693b9103051546d4e4e16a21267b2" +"@flex-development/errnode@npm:1.2.0": + version: 1.2.0 + resolution: "@flex-development/errnode@npm:1.2.0::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40flex-development%2Ferrnode%2F1.2.0%2F8e54e66e637d392299cd2d422224da9cf5d16cab" dependencies: "@flex-development/tutils": "npm:6.0.0-alpha.7" node-inspect-extracted: "npm:2.0.0" - checksum: 41af0fa70b37d9c8e53b652f63c96183145134d6caf694d04b85afc18c58693263e05b10c89ef38e6d7093bf83fe5e8b8ca250d247d2ff68ceff2df876336242 + peerDependencies: + "@types/node": ">=14" + checksum: 2a81fe290873db979a83bc0dbe1d645f4d73a88a8f0258412b43d55406a2a47384c13c97e176c5985890912e40ac16a2c3173f314c0a2d3f663d870c63d7d2b8 languageName: node linkType: hard @@ -1039,7 +1041,7 @@ __metadata: "@commitlint/cli": "npm:17.3.0" "@commitlint/config-conventional": "npm:17.3.0" "@faker-js/faker": "npm:7.6.0" - "@flex-development/errnode": "npm:1.0.1" + "@flex-development/errnode": "npm:1.2.0" "@flex-development/mkbuild": "npm:1.0.0-alpha.9" "@flex-development/tutils": "npm:6.0.0-alpha.7" "@graphql-eslint/eslint-plugin": "npm:3.14.3"