diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 4daa18f..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,86 +0,0 @@ -module.exports = { - 'extends': [ - 'airbnb', - 'prettier' - ], - 'parser': '@typescript-eslint/parser', - 'parserOptions': { - 'ecmaVersion': 2018, - 'sourceType': 'module', - 'modules': true - }, - 'plugins': [ - '@typescript-eslint' - ], - 'settings': { - 'import/resolver': { - 'typescript': { - } - } - }, - 'rules': { - 'quotes': [ - 2, - 'single', - { - 'allowTemplateLiterals': true - } - ], - 'class-methods-use-this': 0, - 'consistent-return': 0, - 'func-names': 0, - 'global-require': 0, - 'guard-for-in': 0, - 'import/no-duplicates': 0, - 'import/no-dynamic-require': 0, - 'import/no-extraneous-dependencies': 0, - 'import/prefer-default-export': 0, - 'lines-between-class-members': 0, - 'no-await-in-loop': 0, - 'no-bitwise': 0, - 'no-console': 0, - 'no-continue': 0, - 'no-control-regex': 0, - 'no-empty': 0, - 'no-loop-func': 0, - 'no-nested-ternary': 0, - 'no-param-reassign': 0, - 'no-plusplus': 0, - 'no-restricted-globals': 0, - 'no-restricted-syntax': 0, - 'no-shadow': 0, - 'no-underscore-dangle': 0, - 'no-use-before-define': 0, - 'prefer-const': 0, - 'prefer-destructuring': 0, - 'camelcase': 0, - 'no-unused-vars': 0, // in favor of '@typescript-eslint/no-unused-vars' - // 'indent': 0 // in favor of '@typescript-eslint/indent' - '@typescript-eslint/no-unused-vars': 'warn', - // '@typescript-eslint/indent': ['error', 2] // this might conflict with a lot ongoing changes - '@typescript-eslint/no-array-constructor': 'error', - '@typescript-eslint/adjacent-overload-signatures': 'error', - '@typescript-eslint/class-name-casing': 'error', - '@typescript-eslint/interface-name-prefix': 'error', - '@typescript-eslint/no-empty-interface': 'error', - '@typescript-eslint/no-inferrable-types': 'error', - '@typescript-eslint/no-misused-new': 'error', - // '@typescript-eslint/no-namespace': 'error', - '@typescript-eslint/no-non-null-assertion': 'error', - '@typescript-eslint/no-parameter-properties': 'error', - '@typescript-eslint/no-triple-slash-reference': 'error', - '@typescript-eslint/prefer-namespace-keyword': 'error', - '@typescript-eslint/type-annotation-spacing': 'error', - // '@typescript-eslint/array-type': 'error', - // '@typescript-eslint/ban-types': 'error', - // '@typescript-eslint/explicit-function-return-type': 'warn', - // '@typescript-eslint/explicit-member-accessibility': 'error', - // '@typescript-eslint/member-delimiter-style': 'error', - // '@typescript-eslint/no-angle-bracket-type-assertion': 'error', - // '@typescript-eslint/no-explicit-any': 'warn', - // '@typescript-eslint/no-object-literal-type-assertion': 'error', - // '@typescript-eslint/no-use-before-define': 'error', - // '@typescript-eslint/no-var-requires': 'error', - // '@typescript-eslint/prefer-interface': 'error' - } -} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b64cb9f..7e2e4d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [6.x, 8.x, 10.x, 12.x] + node-version: [12.x, 14.x, 16.x] steps: - uses: actions/checkout@v1 diff --git a/package.json b/package.json index c864768..c1c6f33 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,16 @@ "name": "data-uri-to-buffer", "version": "3.0.1", "description": "Generate a Buffer instance from a Data URI string", - "main": "dist/src/index.js", - "types": "dist/src/index.d.ts", + "type": "module", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "dist/src" + "dist", + "src" ], "scripts": { "build": "tsc", - "test": "mocha --reporter spec dist/test/*.js", - "test-lint": "eslint src --ext .js,.ts", + "test": "jest", "prepublishOnly": "npm run build" }, "repository": { @@ -18,7 +19,7 @@ "url": "git://github.com/TooTallNate/node-data-uri-to-buffer.git" }, "engines": { - "node": ">= 6" + "node": ">= 12" }, "keywords": [ "data", @@ -38,18 +39,24 @@ "homepage": "https://github.com/TooTallNate/node-data-uri-to-buffer", "devDependencies": { "@types/es6-promisify": "^5.0.0", - "@types/mocha": "^5.2.7", + "@types/mocha": "^9.0.0", "@types/node": "^10.5.3", - "@typescript-eslint/eslint-plugin": "1.6.0", - "@typescript-eslint/parser": "1.1.0", - "eslint": "5.16.0", - "eslint-config-airbnb": "17.1.0", - "eslint-config-prettier": "4.1.0", - "eslint-import-resolver-typescript": "1.1.1", - "eslint-plugin-import": "2.16.0", - "eslint-plugin-jsx-a11y": "6.2.1", - "eslint-plugin-react": "7.12.4", - "mocha": "^6.2.0", - "typescript": "^3.5.3" + "jest": "^27.2.2", + "ts-jest": "^27.0.5", + "typescript": "^4.4.3" + }, + "jest": { + "preset": "ts-jest", + "globals": { + "ts-jest": { + "diagnostics": false, + "isolatedModules": true + } + }, + "verbose": false, + "testEnvironment": "node", + "testMatch": [ + "/test/**/*.test.ts" + ] } } diff --git a/src/index.ts b/src/index.ts index 4c2255a..00e4446 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,17 @@ +export interface MimeBuffer extends Buffer { + type: string; + typeFull: string; + charset: string; +} + /** * Returns a `Buffer` instance from the given data URI `uri`. * * @param {String} uri Data URI to turn into a Buffer instance - * @return {Buffer} Buffer instance from Data URI + * @returns {Buffer} Buffer instance from Data URI * @api public */ - -function dataUriToBuffer(uri: string): dataUriToBuffer.MimeBuffer { +export function dataUriToBuffer(uri: string): MimeBuffer { if (!/^data:/i.test(uri)) { throw new TypeError( '`uri` does not appear to be a Data URI (must begin with "data:")' @@ -48,7 +53,7 @@ function dataUriToBuffer(uri: string): dataUriToBuffer.MimeBuffer { // get the encoded data portion and decode URI-encoded chars const encoding = base64 ? 'base64' : 'ascii'; const data = unescape(uri.substring(firstComma + 1)); - const buffer = Buffer.from(data, encoding) as dataUriToBuffer.MimeBuffer; + const buffer = Buffer.from(data, encoding) as MimeBuffer; // set `.type` and `.typeFull` properties to MIME type buffer.type = type; @@ -60,12 +65,4 @@ function dataUriToBuffer(uri: string): dataUriToBuffer.MimeBuffer { return buffer; } -namespace dataUriToBuffer { // eslint-disable-line no-redeclare - export interface MimeBuffer extends Buffer { - type: string; - typeFull: string; - charset: string; - } -} - -export = dataUriToBuffer; +export default dataUriToBuffer; diff --git a/test/test.ts b/test/data-uri-to-buffer.test.ts similarity index 99% rename from test/test.ts rename to test/data-uri-to-buffer.test.ts index 534106d..09ace17 100644 --- a/test/test.ts +++ b/test/data-uri-to-buffer.test.ts @@ -1,7 +1,3 @@ -/** - * Module dependencies. - */ - import assert from 'assert'; import dataUriToBuffer from '../src'; diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000..e516b7f --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.json", + "include": ["**/*.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index 679c8ec..d88d5e6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,17 @@ { "compilerOptions": { "strict": true, - "module": "CommonJS", - "target": "es2015", + "module": "es2020", + "target": "es2019", "esModuleInterop": true, + "moduleResolution": "node", "lib": ["esnext"], "outDir": "dist", "sourceMap": true, "declaration": true }, "include": [ - "src/**/*", - "test/**/*" + "src/**/*.ts", ], "exclude": [ "node_modules"