base128-ascii 2.1.1 → 2.1.2
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 +31 -1
- package/dist/browser.js +77 -0
- package/dist/browser.min.js +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +18 -14
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ The project was born for [vite-plugin-singlefile-compression](https://github.com
|
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
7
|
+
### npm
|
|
8
|
+
|
|
7
9
|
```
|
|
8
10
|
npm i base128-ascii
|
|
9
11
|
```
|
|
@@ -17,6 +19,34 @@ const encodedTemplate = base128.encode(Uint8Array.from(fs.readFileSync("example.
|
|
|
17
19
|
const decoded = base128.decode(eval(encodedTemplate))
|
|
18
20
|
```
|
|
19
21
|
|
|
22
|
+
### Browser (jsDelivr CDN)
|
|
23
|
+
|
|
24
|
+
#### HTML
|
|
25
|
+
```html
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/base128-ascii/dist/browser.min.js"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### JS
|
|
30
|
+
```js
|
|
31
|
+
new Promise(rs => {
|
|
32
|
+
Object.defineProperty(self, 'base128', {
|
|
33
|
+
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";
|
|
45
|
+
}).then(() => {
|
|
46
|
+
console.log("base128 loaded!", base128);
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
20
50
|
---
|
|
21
51
|
|
|
22
52
|
## Effect
|
|
@@ -37,4 +67,4 @@ base64:
|
|
|
37
67
|
length: 909448
|
|
38
68
|
```
|
|
39
69
|
|
|
40
|
-

|
|
70
|
+

|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
})();
|
|
@@ -0,0 +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)})();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
1
|
+
export declare class EncodeOutput {
|
|
2
|
+
constructor(out: Uint8Array);
|
|
3
|
+
uint8Array: Uint8Array;
|
|
3
4
|
toString(): string;
|
|
4
5
|
toJSTemplateLiterals(): string;
|
|
5
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare function encode(input: Uint8Array): EncodeOutput;
|
|
6
8
|
export declare function decode(input: string): Uint8Array<ArrayBuffer>;
|
|
7
9
|
declare const base128: {
|
|
10
|
+
EncodeOutput: typeof EncodeOutput;
|
|
8
11
|
encode: typeof encode;
|
|
9
12
|
decode: typeof decode;
|
|
10
13
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export class EncodeOutput {
|
|
2
|
+
constructor(out) {
|
|
3
|
+
this.uint8Array = out;
|
|
4
|
+
}
|
|
5
|
+
uint8Array;
|
|
6
|
+
toString() {
|
|
7
|
+
return new TextDecoder().decode(this.uint8Array);
|
|
8
|
+
}
|
|
9
|
+
toJSTemplateLiterals() {
|
|
10
|
+
return `\`${this.toString().replace(/[\r\\`]|\${|<\/script/g, (match) => (match == '\r'
|
|
11
|
+
? '\\r'
|
|
12
|
+
: match == '</script'
|
|
13
|
+
? '<\\/script'
|
|
14
|
+
: '\\' + match))}\``;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
1
17
|
export function encode(input) {
|
|
2
18
|
const out = new Uint8Array(Math.ceil(input.length / 7 * 8));
|
|
3
19
|
let ii = 0, oi = 0;
|
|
@@ -14,20 +30,7 @@ export function encode(input) {
|
|
|
14
30
|
/* 6 */ out[oi++] = input[ii++] << 1 & 127 | input[ii] >> 7;
|
|
15
31
|
/* 7 */ out[oi++] = input[ii++] & 127;
|
|
16
32
|
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
uint8Array: out,
|
|
20
|
-
toString() {
|
|
21
|
-
return str ??= new TextDecoder().decode(out);
|
|
22
|
-
},
|
|
23
|
-
toJSTemplateLiterals() {
|
|
24
|
-
return jstl ??= `\`${this.toString().replace(/[\r\\`]|\${|<\/script/g, (match) => (match == '\r'
|
|
25
|
-
? '\\r'
|
|
26
|
-
: match == '</script'
|
|
27
|
-
? '<\\/script'
|
|
28
|
-
: '\\' + match))}\``;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
33
|
+
return new EncodeOutput(out);
|
|
31
34
|
}
|
|
32
35
|
export function decode(input) {
|
|
33
36
|
const out = new Uint8Array(Math.floor(input.length / 8 * 7));
|
|
@@ -50,6 +53,7 @@ export function decode(input) {
|
|
|
50
53
|
return out;
|
|
51
54
|
}
|
|
52
55
|
const base128 = {
|
|
56
|
+
EncodeOutput,
|
|
53
57
|
encode,
|
|
54
58
|
decode
|
|
55
59
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "base128-ascii",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"browser": "dist/browser.min.js",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"build": "rimraf dist && tsc",
|
|
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
9
|
"test": "npm run build && node test.js",
|
|
9
10
|
"prepublishOnly": "npm run build"
|
|
10
11
|
},
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
],
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^24.0.3",
|
|
28
|
+
"esbuild": "^0.27.2",
|
|
27
29
|
"rimraf": "^6.0.1",
|
|
28
30
|
"typescript": "^5.7.3"
|
|
29
31
|
}
|