Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Output as ESM (#16)
Browse files Browse the repository at this point in the history
* Output as ESM

* Test Node 12, 14, and 16

* Require Node >= 12
  • Loading branch information
TooTallNate committed Sep 27, 2021
1 parent e39ad28 commit f15dd9b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 126 deletions.
86 changes: 0 additions & 86 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -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
Expand Down
43 changes: 25 additions & 18 deletions package.json
Expand Up @@ -2,23 +2,24 @@
"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": {
"type": "git",
"url": "git://github.com/TooTallNate/node-data-uri-to-buffer.git"
},
"engines": {
"node": ">= 6"
"node": ">= 12"
},
"keywords": [
"data",
Expand All @@ -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": [
"<rootDir>/test/**/*.test.ts"
]
}
}
23 changes: 10 additions & 13 deletions 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:")'
Expand Down Expand Up @@ -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;
Expand All @@ -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;
4 changes: 0 additions & 4 deletions test/test.ts → test/data-uri-to-buffer.test.ts
@@ -1,7 +1,3 @@
/**
* Module dependencies.
*/

import assert from 'assert';
import dataUriToBuffer from '../src';

Expand Down
4 changes: 4 additions & 0 deletions test/tsconfig.json
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"]
}
8 changes: 4 additions & 4 deletions 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"
Expand Down

0 comments on commit f15dd9b

Please sign in to comment.