base128-ascii 2.1.6 → 2.1.8

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
@@ -19,32 +19,12 @@ const encodedTemplate = base128.encode(fs.readFileSync("example.gz")).toJSTempla
19
19
  const decoded = base128.decode(eval(encodedTemplate))
20
20
  ```
21
21
 
22
- ### Browser (jsDelivr CDN)
22
+ ### Browser
23
23
 
24
- #### HTML
25
- ```html
26
- <script src="https://cdn.jsdelivr.net/npm/base128-ascii@2.1.6/dist/browser.min.js"></script>
27
- ```
28
-
29
- #### JS
30
- ```js
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", {
37
- configurable: true,
38
- value,
39
- });
40
- rs();
41
- },
42
- });
43
- document.head.appendChild(document.createElement("script")).src =
44
- "https://cdn.jsdelivr.net/npm/base128-ascii@2.1.6/dist/browser.min.js";
45
- }).then(() => {
46
- console.log("base128 loaded!", self.base128);
47
- });
24
+ ```html browser
25
+ <script>
26
+ {class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}self.base128={EncodeOutput,encode(t){"string"==typeof t&&(t=(new TextEncoder).encode(t));for(var e=new Uint8Array(Math.ceil(t.length/7*8)),r=0,n=0;r<t.length;)e[n++]=t[r]>>1,e[n++]=t[r++]<<6&127|t[r]>>2,e[n++]=t[r++]<<5&127|t[r]>>3,e[n++]=t[r++]<<4&127|t[r]>>4,e[n++]=t[r++]<<3&127|t[r]>>5,e[n++]=t[r++]<<2&127|t[r]>>6,e[n++]=t[r++]<<1&127|t[r]>>7,e[n++]=127&t[r++];return new EncodeOutput(e)},decode(t){for(var e,r=new Uint8Array(Math.floor(t.length/8*7)),n=0,o=0,c=()=>(e=t.charCodeAt(n++))>>7?e=0:e;n<t.length;)r[o++]=c()<<1|c()>>6,r[o++]=e<<2|c()>>5,r[o++]=e<<3|c()>>4,r[o++]=e<<4|c()>>3,r[o++]=e<<5|c()>>2,r[o++]=e<<6|c()>>1,r[o++]=e<<7|c();return r}}}
27
+ </script>
48
28
  ```
49
29
 
50
30
  ---
@@ -1 +1 @@
1
- (()=>{var l=class{constructor(r){this.uint8Array=r}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 s(e){for(var r=new Uint8Array(Math.floor(e.length/8*7)),o=0,t=0,c,a=()=>(c=e.charCodeAt(o++))>>7?c=0:c;o<e.length;)r[t++]=a()<<1|a()>>6,r[t++]=c<<2|a()>>5,r[t++]=c<<3|a()>>4,r[t++]=c<<4|a()>>3,r[t++]=c<<5|a()>>2,r[t++]=c<<6|a()>>1,r[t++]=c<<7|a();return r}base128={EncodeOutput:l,encode:h,decode:s};})()
1
+ {class EncodeOutput{constructor(t){this.uint8Array=t}toString(){return(new TextDecoder).decode(this.uint8Array)}toJSTemplateLiterals(){return`\`${this.toString().replace(/[\r\\`]|\${|<\/script/g,t=>"\r"==t?"\\r":"<\/script"==t?"<\\/script":"\\"+t)}\``}}self.base128={EncodeOutput,encode(t){"string"==typeof t&&(t=(new TextEncoder).encode(t));for(var e=new Uint8Array(Math.ceil(t.length/7*8)),r=0,n=0;r<t.length;)e[n++]=t[r]>>1,e[n++]=t[r++]<<6&127|t[r]>>2,e[n++]=t[r++]<<5&127|t[r]>>3,e[n++]=t[r++]<<4&127|t[r]>>4,e[n++]=t[r++]<<3&127|t[r]>>5,e[n++]=t[r++]<<2&127|t[r]>>6,e[n++]=t[r++]<<1&127|t[r]>>7,e[n++]=127&t[r++];return new EncodeOutput(e)},decode(t){for(var e,r=new Uint8Array(Math.floor(t.length/8*7)),n=0,o=0,c=()=>(e=t.charCodeAt(n++))>>7?e=0:e;n<t.length;)r[o++]=c()<<1|c()>>6,r[o++]=e<<2|c()>>5,r[o++]=e<<3|c()>>4,r[o++]=e<<4|c()>>3,r[o++]=e<<5|c()>>2,r[o++]=e<<6|c()>>1,r[o++]=e<<7|c();return r}}}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
+ type Uint8ArrayLike = ArrayLike<number>;
1
2
  export declare class EncodeOutput {
2
3
  constructor(out: Uint8Array);
3
4
  toString(): string;
4
5
  toJSTemplateLiterals(): string;
5
6
  }
6
- type Uint8ArrayLike = ArrayLike<number>;
7
- export declare function encode(input: Uint8ArrayLike): EncodeOutput;
7
+ export declare function encode(input: Uint8ArrayLike | string): EncodeOutput;
8
8
  export declare function decode(input: string): Uint8Array;
9
9
  declare const base128: {
10
10
  EncodeOutput: typeof EncodeOutput;
package/dist/index.js CHANGED
@@ -14,6 +14,8 @@ export class EncodeOutput {
14
14
  }
15
15
  }
16
16
  export function encode(input) {
17
+ if (typeof input == 'string')
18
+ input = new TextEncoder().encode(input);
17
19
  var out = new Uint8Array(Math.ceil(input.length / 7 * 8)), ii = 0, oi = 0;
18
20
  while (ii < input.length) {
19
21
  // 0 1 2 3 4 5 6 7
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "base128-ascii",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "main": "dist/index.js",
5
5
  "browser": "dist/browser.min.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "build": "node scripts/readme-jsdelivr-version.js && rimraf dist && tsc && node scripts/build-for-browser.js",
8
+ "build": "rimraf dist && tsc && node scripts/build-for-browser.js",
9
9
  "test": "npm run build && node scripts/test.js",
10
- "prepublishOnly": "npm run build"
10
+ "prepublishOnly": "npm run test"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -25,8 +25,8 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^24.0.3",
28
- "esbuild": "^0.27.2",
29
28
  "rimraf": "^6.0.1",
29
+ "terser": "^5.44.1",
30
30
  "typescript": "^5.7.3"
31
31
  }
32
32
  }