From 4e247b930f0d90d7f07f6c19a0158a87fa026deb Mon Sep 17 00:00:00 2001 From: arjunyel Date: Wed, 17 Jan 2024 16:25:28 -0600 Subject: [PATCH] fix masquerading as CJS error --- Makefile | 5 +- base64.d.mts | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 76 ++++++++++++++++------------- 3 files changed, 179 insertions(+), 37 deletions(-) create mode 100644 base64.d.mts diff --git a/Makefile b/Makefile index 1f3164e..4037078 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,12 @@ ES5=base64.es5.js ES6=base64.es6.js MJS=base64.mjs DTS=base64.d.ts +MDTS=base64.d.mts all: $(MJS) $(JS) $(MJS): $(PJ) $(TS) - -tsc -d --target es6 $(TS) > /dev/null; mv $(JS) $(MJS) + -tsc -d --target es6 $(TS) > /dev/null; mv $(JS) $(MJS); cp $(DTS) $(MDTS) $(ES6): $(MJS) util/makecjs $(MJS) > $(ES6) @@ -24,4 +25,4 @@ test: $(PJ) $(MJS) $(JS) mocha clean: - -rm $(DTS) $(MJS) $(JS) $(ES5) $(ES6) + -rm $(DTS) $(MDTS) $(MJS) $(JS) $(ES5) $(ES6) diff --git a/base64.d.mts b/base64.d.mts new file mode 100644 index 0000000..afd70f4 --- /dev/null +++ b/base64.d.mts @@ -0,0 +1,135 @@ +/** + * base64.ts + * + * Licensed under the BSD 3-Clause License. + * http://opensource.org/licenses/BSD-3-Clause + * + * References: + * http://en.wikipedia.org/wiki/Base64 + * + * @author Dan Kogai (https://github.com/dankogai) + */ +declare const version = "3.7.5"; +/** + * @deprecated use lowercase `version`. + */ +declare const VERSION = "3.7.5"; +/** + * polyfill version of `btoa` + */ +declare const btoaPolyfill: (bin: string) => string; +/** + * does what `window.btoa` of web browsers do. + * @param {String} bin binary string + * @returns {string} Base64-encoded string + */ +declare const _btoa: (bin: string) => string; +/** + * converts a Uint8Array to a Base64 string. + * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5 + * @returns {string} Base64 string + */ +declare const fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string; +/** + * @deprecated should have been internal use only. + * @param {string} src UTF-8 string + * @returns {string} UTF-16 string + */ +declare const utob: (u: string) => string; +/** + * converts a UTF-8-encoded string to a Base64 string. + * @param {boolean} [urlsafe] if `true` make the result URL-safe + * @returns {string} Base64 string + */ +declare const encode: (src: string, urlsafe?: boolean) => string; +/** + * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5. + * @returns {string} Base64 string + */ +declare const encodeURI: (src: string) => string; +/** + * @deprecated should have been internal use only. + * @param {string} src UTF-16 string + * @returns {string} UTF-8 string + */ +declare const btou: (b: string) => string; +/** + * polyfill version of `atob` + */ +declare const atobPolyfill: (asc: string) => string; +/** + * does what `window.atob` of web browsers do. + * @param {String} asc Base64-encoded string + * @returns {string} binary string + */ +declare const _atob: (asc: string) => string; +/** + * converts a Base64 string to a Uint8Array. + */ +declare const toUint8Array: (a: string) => Uint8Array; +/** + * converts a Base64 string to a UTF-8 string. + * @param {String} src Base64 string. Both normal and URL-safe are supported + * @returns {string} UTF-8 string + */ +declare const decode: (src: string) => string; +/** + * check if a value is a valid Base64 string + * @param {String} src a value to check + */ +declare const isValid: (src: any) => boolean; +/** + * extend String.prototype with relevant methods + */ +declare const extendString: () => void; +/** + * extend Uint8Array.prototype with relevant methods + */ +declare const extendUint8Array: () => void; +/** + * extend Builtin prototypes with relevant methods + */ +declare const extendBuiltins: () => void; +declare const gBase64: { + version: string; + VERSION: string; + atob: (asc: string) => string; + atobPolyfill: (asc: string) => string; + btoa: (bin: string) => string; + btoaPolyfill: (bin: string) => string; + fromBase64: (src: string) => string; + toBase64: (src: string, urlsafe?: boolean) => string; + encode: (src: string, urlsafe?: boolean) => string; + encodeURI: (src: string) => string; + encodeURL: (src: string) => string; + utob: (u: string) => string; + btou: (b: string) => string; + decode: (src: string) => string; + isValid: (src: any) => boolean; + fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string; + toUint8Array: (a: string) => Uint8Array; + extendString: () => void; + extendUint8Array: () => void; + extendBuiltins: () => void; +}; +export { version }; +export { VERSION }; +export { _atob as atob }; +export { atobPolyfill }; +export { _btoa as btoa }; +export { btoaPolyfill }; +export { decode as fromBase64 }; +export { encode as toBase64 }; +export { utob }; +export { encode }; +export { encodeURI }; +export { encodeURI as encodeURL }; +export { btou }; +export { decode }; +export { isValid }; +export { fromUint8Array }; +export { toUint8Array }; +export { extendString }; +export { extendUint8Array }; +export { extendBuiltins }; +export { gBase64 as Base64 }; diff --git a/package.json b/package.json index 776d185..130d3d0 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,43 @@ { - "name": "js-base64", - "version": "3.7.5", - "description": "Yet another Base64 transcoder in pure-JS", - "main": "base64.js", - "module": "base64.mjs", - "types": "base64.d.ts", - "sideEffects": false, - "files": [ - "base64.js", - "base64.mjs", - "base64.d.ts" - ], - "exports": { - ".": { - "types": "./base64.d.ts", - "import": "./base64.mjs", - "require": "./base64.js" - }, - "./package.json": "./package.json" - }, - "scripts": { - "test": "make clean && make test" - }, - "devDependencies": { - "@types/node": "^20.9.0", - "mocha": "^10.0.0", - "typescript": "^5.0.0" - }, - "repository": "git+https://github.com/dankogai/js-base64.git", - "keywords": [ - "base64", - "binary" - ], - "author": "Dan Kogai", - "license": "BSD-3-Clause" + "name": "js-base64", + "version": "3.7.5", + "description": "Yet another Base64 transcoder in pure-JS", + "main": "base64.js", + "module": "base64.mjs", + "types": "base64.d.ts", + "sideEffects": false, + "files": [ + "base64.js", + "base64.mjs", + "base64.d.ts", + "base64.d.mts" + ], + "exports": { + ".": { + "import": { + "types": "./base64.d.mts", + "default": "./base64.mjs" + }, + "require": { + "types": "./base64.d.ts", + "default": "./base64.js" + } + }, + "./package.json": "./package.json" + }, + "scripts": { + "test": "make clean && make test" + }, + "devDependencies": { + "@types/node": "^20.11.5", + "mocha": "^10.2.0", + "typescript": "^5.3.3" + }, + "repository": "git+https://github.com/dankogai/js-base64.git", + "keywords": [ + "base64", + "binary" + ], + "author": "Dan Kogai", + "license": "BSD-3-Clause" }