base128-ascii 2.1.2 → 2.1.4
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 +16 -16
- package/dist/browser.js +1 -77
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -7
- package/package.json +3 -3
- package/dist/browser.min.js +0 -1
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(
|
|
17
|
+
const encodedTemplate = base128.encode(fs.readFileSync("example.gz")).toJSTemplateLiterals()
|
|
18
18
|
|
|
19
19
|
const decoded = base128.decode(eval(encodedTemplate))
|
|
20
20
|
```
|
|
@@ -23,27 +23,27 @@ const decoded = base128.decode(eval(encodedTemplate))
|
|
|
23
23
|
|
|
24
24
|
#### HTML
|
|
25
25
|
```html
|
|
26
|
-
<script src="https://cdn.jsdelivr.net/npm/base128-ascii/dist/browser.min.js"></script>
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/base128-ascii@latest/dist/browser.min.js"></script>
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
#### JS
|
|
30
30
|
```js
|
|
31
|
-
new Promise(rs => {
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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@latest/dist/browser.min.js";
|
|
45
45
|
}).then(() => {
|
|
46
|
-
|
|
46
|
+
console.log("base128 loaded!", self.base128);
|
|
47
47
|
});
|
|
48
48
|
```
|
|
49
49
|
|
package/dist/browser.js
CHANGED
|
@@ -1,77 +1 @@
|
|
|
1
|
-
var
|
|
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
|
-
})();
|
|
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};})()
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare class EncodeOutput {
|
|
2
2
|
constructor(out: Uint8Array);
|
|
3
|
-
uint8Array: Uint8Array;
|
|
4
3
|
toString(): string;
|
|
5
4
|
toJSTemplateLiterals(): string;
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
export declare function
|
|
6
|
+
type Uint8ArrayLike = ArrayLike<number>;
|
|
7
|
+
export declare function encode(input: Uint8ArrayLike): 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
|
@@ -2,7 +2,6 @@ export class EncodeOutput {
|
|
|
2
2
|
constructor(out) {
|
|
3
3
|
this.uint8Array = out;
|
|
4
4
|
}
|
|
5
|
-
uint8Array;
|
|
6
5
|
toString() {
|
|
7
6
|
return new TextDecoder().decode(this.uint8Array);
|
|
8
7
|
}
|
|
@@ -15,8 +14,7 @@ export class EncodeOutput {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
export function encode(input) {
|
|
18
|
-
|
|
19
|
-
let ii = 0, oi = 0;
|
|
17
|
+
var out = new Uint8Array(Math.ceil(input.length / 7 * 8)), ii = 0, oi = 0;
|
|
20
18
|
while (ii < input.length) {
|
|
21
19
|
// 0 1 2 3 4 5 6 7
|
|
22
20
|
// in 00000000 11111111 22222222 33333333 44444444 55555555 66666666
|
|
@@ -33,10 +31,8 @@ export function encode(input) {
|
|
|
33
31
|
return new EncodeOutput(out);
|
|
34
32
|
}
|
|
35
33
|
export function decode(input) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const next = () => ((cache = input.charCodeAt(ii++)) >> 7
|
|
39
|
-
? cache = 0 // In HTML, 0 is likely to be converted to 65533
|
|
34
|
+
var out = new Uint8Array(Math.floor(input.length / 8 * 7)), ii = 0, oi = 0, cache, next = () => ((cache = input.charCodeAt(ii++)) >> 7
|
|
35
|
+
? cache = 0 // In HTML, 0 is likely to be converted to 65533 (�)
|
|
40
36
|
: cache);
|
|
41
37
|
while (ii < input.length) {
|
|
42
38
|
// 0 1 2 3 4 5 6 7
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "base128-ascii",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
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 &&
|
|
9
|
-
"test": "npm run build && node test.js",
|
|
8
|
+
"build": "rimraf dist && tsc && node scripts/build-for-browser.js",
|
|
9
|
+
"test": "npm run build && node scripts/test.js",
|
|
10
10
|
"prepublishOnly": "npm run build"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
package/dist/browser.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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)})();
|