base128-ascii 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm i base128-ascii
14
14
  import base128 from "base128-ascii"
15
15
  import fs from 'fs'
16
16
 
17
- const encodedTemplate = base128.encode(Uint8Array.from(fs.readFileSync("example.gz"))).toJSTemplateLiterals()
17
+ const encodedTemplate = base128.encode(fs.readFileSync("example.gz")).toJSTemplateLiterals()
18
18
 
19
19
  const decoded = base128.decode(eval(encodedTemplate))
20
20
  ```
@@ -28,22 +28,22 @@ const decoded = base128.decode(eval(encodedTemplate))
28
28
 
29
29
  #### JS
30
30
  ```js
31
- new Promise(rs => {
32
- Object.defineProperty(self, 'base128', {
31
+ new Promise((rs) => {
32
+ if (self.base128?.EncodeOutput) return rs();
33
+ Object.defineProperty(self, "base128", {
34
+ configurable: true,
35
+ set(value) {
36
+ Object.defineProperty(this, "base128", {
33
37
  configurable: true,
34
- set(value) {
35
- Object.defineProperty(this, 'base128', {
36
- configurable: true,
37
- value
38
- });
39
- rs();
40
- }
41
- });
42
- document.head.appendChild(
43
- document.createElement("script")
44
- ).src = "https://cdn.jsdelivr.net/npm/base128-ascii/dist/browser.min.js";
38
+ value,
39
+ });
40
+ rs();
41
+ },
42
+ });
43
+ document.head.appendChild(document.createElement("script")).src =
44
+ "https://cdn.jsdelivr.net/npm/base128-ascii/dist/browser.min.js";
45
45
  }).then(() => {
46
- console.log("base128 loaded!", base128);
46
+ console.log("base128 loaded!", self.base128);
47
47
  });
48
48
  ```
49
49
 
@@ -1 +1 @@
1
- var base128=(()=>{var c=Object.defineProperty,i=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,y=Object.prototype.hasOwnProperty,g=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},h=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of v(r))!y.call(e,a)&&a!==t&&c(e,a,{get:()=>r[a],enumerable:!(o=i(r,a))||o.enumerable});return e},w=e=>h(c({},"__esModule",{value:!0}),e),l={};g(l,{EncodeOutput:()=>s,decode:()=>_,default:()=>u,encode:()=>d});var s=class{constructor(e){this.uint8Array=e}uint8Array;toString(){return new TextDecoder().decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,e=>e=="\r"?"\\r":e=="<\/script"?"<\\/script":"\\"+e)}\``}};function d(e){const r=new Uint8Array(Math.ceil(e.length/7*8));let t=0,o=0;for(;t<e.length;)r[o++]=e[t]>>1,r[o++]=e[t++]<<6&127|e[t]>>2,r[o++]=e[t++]<<5&127|e[t]>>3,r[o++]=e[t++]<<4&127|e[t]>>4,r[o++]=e[t++]<<3&127|e[t]>>5,r[o++]=e[t++]<<2&127|e[t]>>6,r[o++]=e[t++]<<1&127|e[t]>>7,r[o++]=e[t++]&127;return new s(r)}function _(e){const r=new Uint8Array(Math.floor(e.length/8*7));let t=0,o=0,a;const n=()=>(a=e.charCodeAt(t++))>>7?a=0:a;for(;t<e.length;)r[o++]=n()<<1|n()>>6,r[o++]=a<<2|n()>>5,r[o++]=a<<3|n()>>4,r[o++]=a<<4|n()>>3,r[o++]=a<<5|n()>>2,r[o++]=a<<6|n()>>1,r[o++]=a<<7|n();return r}var O={EncodeOutput:s,encode:d,decode:_},u=O;return w(l)})();
1
+ var base128=(()=>{var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var w=(e,r)=>{for(var o in r)s(e,o,{get:r[o],enumerable:!0})},x=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of d(r))!g.call(e,a)&&a!==o&&s(e,a,{get:()=>r[a],enumerable:!(t=i(r,a))||t.enumerable});return e};var A=e=>x(s({},"__esModule",{value:!0}),e);var S={};w(S,{EncodeOutput:()=>l,decode:()=>n,default:()=>f,encode:()=>h});var l=class{constructor(r){this.uint8Array=r}uint8Array;toString(){return new TextDecoder().decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,r=>r=="\r"?"\\r":r=="<\/script"?"<\\/script":"\\"+r)}\``}};function h(e){for(var r=new Uint8Array(Math.ceil(e.length/7*8)),o=0,t=0;o<e.length;)r[t++]=e[o]>>1,r[t++]=e[o++]<<6&127|e[o]>>2,r[t++]=e[o++]<<5&127|e[o]>>3,r[t++]=e[o++]<<4&127|e[o]>>4,r[t++]=e[o++]<<3&127|e[o]>>5,r[t++]=e[o++]<<2&127|e[o]>>6,r[t++]=e[o++]<<1&127|e[o]>>7,r[t++]=e[o++]&127;return new l(r)}function n(e){for(var r=new Uint8Array(Math.floor(e.length/8*7)),o=0,t=0,a,c=()=>(a=e.charCodeAt(o++))>>7?a=0:a;o<e.length;)r[t++]=c()<<1|c()>>6,r[t++]=a<<2|c()>>5,r[t++]=a<<3|c()>>4,r[t++]=a<<4|c()>>3,r[t++]=a<<5|c()>>2,r[t++]=a<<6|c()>>1,r[t++]=a<<7|c();return r}var y={EncodeOutput:l,encode:h,decode:n},f=y;return A(S);})();
package/dist/index.d.ts CHANGED
@@ -4,8 +4,8 @@ export declare class EncodeOutput {
4
4
  toString(): string;
5
5
  toJSTemplateLiterals(): string;
6
6
  }
7
- export declare function encode(input: Uint8Array): EncodeOutput;
8
- export declare function decode(input: string): Uint8Array<ArrayBuffer>;
7
+ export declare function encode(input: ArrayLike<number>): EncodeOutput;
8
+ export declare function decode(input: string): Uint8Array;
9
9
  declare const base128: {
10
10
  EncodeOutput: typeof EncodeOutput;
11
11
  encode: typeof encode;
package/dist/index.js CHANGED
@@ -15,8 +15,7 @@ export class EncodeOutput {
15
15
  }
16
16
  }
17
17
  export function encode(input) {
18
- const out = new Uint8Array(Math.ceil(input.length / 7 * 8));
19
- let ii = 0, oi = 0;
18
+ var out = new Uint8Array(Math.ceil(input.length / 7 * 8)), ii = 0, oi = 0;
20
19
  while (ii < input.length) {
21
20
  // 0 1 2 3 4 5 6 7
22
21
  // in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
@@ -33,10 +32,8 @@ export function encode(input) {
33
32
  return new EncodeOutput(out);
34
33
  }
35
34
  export function decode(input) {
36
- const out = new Uint8Array(Math.floor(input.length / 8 * 7));
37
- let ii = 0, oi = 0, cache;
38
- const next = () => ((cache = input.charCodeAt(ii++)) >> 7
39
- ? cache = 0 // In HTML, 0 is likely to be converted to 65533
35
+ var out = new Uint8Array(Math.floor(input.length / 8 * 7)), ii = 0, oi = 0, cache, next = () => ((cache = input.charCodeAt(ii++)) >> 7
36
+ ? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
40
37
  : cache);
41
38
  while (ii < input.length) {
42
39
  // 0 1 2 3 4 5 6 7
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "base128-ascii",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "main": "dist/index.js",
5
5
  "browser": "dist/browser.min.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "build": "rimraf dist && tsc && esbuild dist/index.js --bundle --global-name=base128 --outfile=dist/browser.js && esbuild dist/browser.js --minify --outfile=dist/browser.min.js",
8
+ "build": "rimraf dist && tsc && esbuild dist/index.js --bundle --global-name=base128 --minify --outfile=dist/browser.min.js",
9
9
  "test": "npm run build && node test.js",
10
10
  "prepublishOnly": "npm run build"
11
11
  },
package/dist/browser.js DELETED
@@ -1,77 +0,0 @@
1
- var base128 = (() => {
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // dist/index.js
21
- var index_exports = {};
22
- __export(index_exports, {
23
- EncodeOutput: () => EncodeOutput,
24
- decode: () => decode,
25
- default: () => index_default,
26
- encode: () => encode
27
- });
28
- var EncodeOutput = class {
29
- constructor(out) {
30
- this.uint8Array = out;
31
- }
32
- uint8Array;
33
- toString() {
34
- return new TextDecoder().decode(this.uint8Array);
35
- }
36
- toJSTemplateLiterals() {
37
- return `\`${this.toString().replace(/[\r\\`]|\${|<\/script/g, (match) => match == "\r" ? "\\r" : match == "<\/script" ? "<\\/script" : "\\" + match)}\``;
38
- }
39
- };
40
- function encode(input) {
41
- const out = new Uint8Array(Math.ceil(input.length / 7 * 8));
42
- let ii = 0, oi = 0;
43
- while (ii < input.length) {
44
- out[oi++] = input[ii] >> 1;
45
- out[oi++] = input[ii++] << 6 & 127 | input[ii] >> 2;
46
- out[oi++] = input[ii++] << 5 & 127 | input[ii] >> 3;
47
- out[oi++] = input[ii++] << 4 & 127 | input[ii] >> 4;
48
- out[oi++] = input[ii++] << 3 & 127 | input[ii] >> 5;
49
- out[oi++] = input[ii++] << 2 & 127 | input[ii] >> 6;
50
- out[oi++] = input[ii++] << 1 & 127 | input[ii] >> 7;
51
- out[oi++] = input[ii++] & 127;
52
- }
53
- return new EncodeOutput(out);
54
- }
55
- function decode(input) {
56
- const out = new Uint8Array(Math.floor(input.length / 8 * 7));
57
- let ii = 0, oi = 0, cache;
58
- const next = () => (cache = input.charCodeAt(ii++)) >> 7 ? cache = 0 : cache;
59
- while (ii < input.length) {
60
- out[oi++] = next() << 1 | next() >> 6;
61
- out[oi++] = cache << 2 | next() >> 5;
62
- out[oi++] = cache << 3 | next() >> 4;
63
- out[oi++] = cache << 4 | next() >> 3;
64
- out[oi++] = cache << 5 | next() >> 2;
65
- out[oi++] = cache << 6 | next() >> 1;
66
- out[oi++] = cache << 7 | next();
67
- }
68
- return out;
69
- }
70
- var base128 = {
71
- EncodeOutput,
72
- encode,
73
- decode
74
- };
75
- var index_default = base128;
76
- return __toCommonJS(index_exports);
77
- })();