Skip to content

Commit

Permalink
Add support for ES modules
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
jonkoops committed Jul 25, 2024
1 parent ceccc98 commit dfcd133
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function byteLength(b64: string): number;
export function toByteArray(b64: string): Uint8Array;
export function fromByteArray(uint8: Uint8Array): string;
12 changes: 3 additions & 9 deletions index.js → index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
'use strict'

exports.byteLength = byteLength
exports.toByteArray = toByteArray
exports.fromByteArray = fromByteArray

var lookup = []
var revLookup = []
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
Expand Down Expand Up @@ -39,7 +33,7 @@ function getLens (b64) {
}

// base64 is 4/3 + up to two characters of the original data
function byteLength (b64) {
export function byteLength (b64) {
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
Expand All @@ -50,7 +44,7 @@ function _byteLength (b64, validLen, placeHoldersLen) {
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}

function toByteArray (b64) {
export function toByteArray (b64) {
var tmp
var lens = getLens(b64)
var validLen = lens[0]
Expand Down Expand Up @@ -116,7 +110,7 @@ function encodeChunk (uint8, start, end) {
return output.join('')
}

function fromByteArray (uint8) {
export function fromByteArray (uint8) {
var tmp
var len = uint8.length
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
Expand Down
24 changes: 19 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,38 @@
"files": [
"base64js.min.js",
"index.d.ts",
"index.js"
"index.d.mts",
"index.js",
"index.mjs"
],
"main": "index.js",
"typings": "index.d.ts",
"exports": {
".": {
"import": {
"types": "./index.d.mts",
"default": "./index.mjs"
},
"require": {
"types": "./index.d.ts",
"default": "./index.js"
}
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/feross/base64-js.git"
},
"scripts": {
"build": "browserify -s base64js -r ./ | minify > base64js.min.js",
"lint": "standard",
"build": "rollup index.mjs --file index.js --format cjs && rollup index.js --file base64js.min.js --format umd --name base64js --plugin terser",
"lint": "standard --ignore index.js --ignore base64js.min.js",
"test": "npm run lint && npm run unit",
"unit": "tape test/*.js"
},
"devDependencies": {
"babel-minify": "^0.5.1",
"@rollup/plugin-terser": "^0.4.4",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"rollup": "^4.19.0",
"standard": "*",
"tape": "^5.4.0"
}
Expand Down

0 comments on commit dfcd133

Please sign in to comment.