Skip to content

Commit

Permalink
stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Aug 29, 2022
1 parent de7f3bc commit 6d61e0b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
25 changes: 25 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as esbuild from 'esbuild';
import * as fs from 'fs';

const out = esbuild.buildSync({
entryPoints: ['src/polyfill.js'],
bundle: true,
format: 'esm',
banner: {
js: `(function(scope) {'use strict';`,
},
footer: {
js: `}(typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this)));`,
},
platform: 'neutral',
sourcemap: 'external',
outfile: 'text.min.js',
target: 'es5',
minify: true,
});

// confirm it imports
await import('./text.min.js');

const stat = fs.statSync('text.min.js');
console.info(`text.min.js: ${stat.size}`);
5 changes: 3 additions & 2 deletions src/o-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ if (hasBufferFrom) {
}


const errorPrefix = `${failedToString} construct 'TextDecoder': the `;
const ctorString = `construct 'TextDecoder'`;
const errorPrefix = `${failedToString} ${ctorString}: the `;


/**
Expand All @@ -31,7 +32,7 @@ const errorPrefix = `${failedToString} construct 'TextDecoder': the `;
* @param {{fatal: boolean}=} options
*/
export function FastTextDecoder(utfLabel = 'utf-8', options) {
maybeThrowFailedToOption(options && options.fatal, `construct 'TextDecoder'`, 'fatal');
maybeThrowFailedToOption(options && options.fatal, ctorString, 'fatal');

/** @type {boolean} */
let ok;
Expand Down
6 changes: 3 additions & 3 deletions src/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { FastTextEncoder } from './o-encoder.js';
import { FastTextDecoder } from './o-decoder.js';

/** @type {object} */
const scope = typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this);
// /** @type {object} */
// const scope = typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : this);

scope['TextEncoder'] = scope['TextEncoder'] || FastTextEncoder;
scope['TextDecoder'] = scope['TextDecoder'] || FastTextDecoder;

export {};
// export {};
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// both to e.g., "es2017"
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",

// configure as you like: these are my preferred defaults!
"strict": true,
Expand All @@ -20,5 +21,6 @@
"include": [
// include the JS files you'd like to check here
"src/**/*.js",
"*.js",
],
}

0 comments on commit 6d61e0b

Please sign in to comment.