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

Commit

Permalink
Use buffer-from ponyfill to fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Sep 27, 2019
1 parent 9f87a4d commit a507102
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
'@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-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/no-triple-slash-reference': 'error',
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"homepage": "https://github.com/TooTallNate/node-data-uri-to-buffer",
"devDependencies": {
"@types/buffer-from": "^1.1.0",
"@types/es6-promisify": "^5.0.0",
"@types/mocha": "^5.2.7",
"@types/node": "^10.5.3",
Expand All @@ -51,5 +52,8 @@
"eslint-plugin-react": "7.12.4",
"mocha": "^6.2.0",
"typescript": "^3.5.3"
},
"dependencies": {
"buffer-from": "^1.1.1"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import bufferFrom from 'buffer-from';

/**
* Returns a `Buffer` instance from the given data URI `uri`.
*
Expand Down Expand Up @@ -48,9 +50,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
? Buffer.from(data, encoding)
: new Buffer(data, encoding)) as dataUriToBuffer.MimeBuffer;
const buffer = bufferFrom(data, encoding) as dataUriToBuffer.MimeBuffer;

// set `.type` and `.typeFull` properties to MIME type
buffer.type = type;
Expand All @@ -62,7 +62,7 @@ function dataUriToBuffer(uri: string): dataUriToBuffer.MimeBuffer {
return buffer;
}

namespace dataUriToBuffer {
namespace dataUriToBuffer { // eslint-disable-line no-redeclare
export interface MimeBuffer extends Buffer {
type: string;
typeFull: string;
Expand Down

0 comments on commit a507102

Please sign in to comment.