strc 2.0.4 → 2.0.5
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/dist/jssc.cjs +115 -114
- package/dist/jssc.js +115 -114
- package/dist/jssc.mjs +115 -114
- package/index.js +115 -114
- package/index.min.js +1 -1
- package/package.json +3 -5
- package/src/freqMap.js +112 -0
- package/src/index.js +12 -164
- package/src/meta.js +2 -0
- package/src/prefix.sh +3 -0
- package/src/prefix.txt +34 -0
- package/src/utils.js +51 -0
package/dist/jssc.cjs
CHANGED
|
@@ -45,9 +45,6 @@ var JUSTC = require('justc');
|
|
|
45
45
|
|
|
46
46
|
const name__ = 'JSSC';
|
|
47
47
|
const prefix = name__+': ';
|
|
48
|
-
if ((String.fromCharCode(65536).charCodeAt(0) === 65536) || !(String.fromCharCode(256).charCodeAt(0) === 256)) {
|
|
49
|
-
throw new Error(prefix+'Supported UTF-16 only!')
|
|
50
|
-
}
|
|
51
48
|
|
|
52
49
|
function stringCodes(str) {
|
|
53
50
|
let output = [];
|
|
@@ -93,6 +90,121 @@ function binToDec(str) {
|
|
|
93
90
|
return parseInt(str, 2);
|
|
94
91
|
}
|
|
95
92
|
|
|
93
|
+
const freqMap = {
|
|
94
|
+
ESCAPE_BYTE: 0xFF,
|
|
95
|
+
TOP_COUNT: 254,
|
|
96
|
+
SPLITTER: " \u200B",
|
|
97
|
+
|
|
98
|
+
compress(text, splitter = this.SPLITTER) {
|
|
99
|
+
const freq = {};
|
|
100
|
+
for (let char of text) {
|
|
101
|
+
freq[char] = (freq[char] || 0) + 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const topChars = Object.entries(freq)
|
|
105
|
+
.sort((a, b) => b[1] - a[1])
|
|
106
|
+
.slice(0, this.TOP_COUNT)
|
|
107
|
+
.map(entry => entry[0]);
|
|
108
|
+
|
|
109
|
+
const charToIndex = new Map(topChars.map((char, i) => [char, i]));
|
|
110
|
+
|
|
111
|
+
let header = String.fromCharCode(topChars.length) + topChars.join('');
|
|
112
|
+
|
|
113
|
+
let bytes = [];
|
|
114
|
+
for (let char of text) {
|
|
115
|
+
if (charToIndex.has(char)) {
|
|
116
|
+
/* frequent */
|
|
117
|
+
bytes.push(charToIndex.get(char));
|
|
118
|
+
} else {
|
|
119
|
+
/* rare */
|
|
120
|
+
bytes.push(this.ESCAPE_BYTE);
|
|
121
|
+
const code = char.charCodeAt(0);
|
|
122
|
+
bytes.push((code >> 8) & 0xFF);
|
|
123
|
+
bytes.push(code & 0xFF);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* to UTF16 */
|
|
128
|
+
let compressedBody = "";
|
|
129
|
+
for (let i = 0; i < bytes.length; i += 2) {
|
|
130
|
+
const b1 = bytes[i];
|
|
131
|
+
const b2 = (i + 1 < bytes.length) ? bytes[i + 1] : 0x00;
|
|
132
|
+
compressedBody += String.fromCharCode((b1 << 8) | b2);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return header + splitter + compressedBody;
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
decompress(compressedText, splitter = this.SPLITTER) {
|
|
139
|
+
const parts = compressedText.split(splitter);
|
|
140
|
+
|
|
141
|
+
if (parts.length < 2) {
|
|
142
|
+
throw new Error(prefix+'Invalid freqMap data: splitter not found');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const headerPart = parts[0];
|
|
146
|
+
const bodyPart = parts.slice(1).join(splitter);
|
|
147
|
+
|
|
148
|
+
const topCount = headerPart.charCodeAt(0);
|
|
149
|
+
const topChars = headerPart.substring(1, topCount + 1);
|
|
150
|
+
|
|
151
|
+
let bytes = [];
|
|
152
|
+
for (let i = 0; i < bodyPart.length; i++) {
|
|
153
|
+
const code = bodyPart.charCodeAt(i);
|
|
154
|
+
bytes.push((code >> 8) & 0xFF);
|
|
155
|
+
bytes.push(code & 0xFF);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let result = "";
|
|
159
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
160
|
+
const b = bytes[i];
|
|
161
|
+
if (b === this.ESCAPE_BYTE) {
|
|
162
|
+
const charCode = (bytes[i + 1] << 8) | bytes[i + 2];
|
|
163
|
+
result += String.fromCharCode(charCode);
|
|
164
|
+
i += 2;
|
|
165
|
+
} else if (b < topCount) {
|
|
166
|
+
result += topChars[b];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 0 = Fail
|
|
174
|
+
* 1 = Success
|
|
175
|
+
* 2 = Remove last character (Success)
|
|
176
|
+
* @param {string} text
|
|
177
|
+
* @param {string?} splitter
|
|
178
|
+
* @returns {number|[number, number, string, string]}
|
|
179
|
+
*/
|
|
180
|
+
test(text, splitter = this.SPLITTER) {
|
|
181
|
+
try {
|
|
182
|
+
if (text.includes(splitter)) return 0;
|
|
183
|
+
const packed = this.compress(text, splitter);
|
|
184
|
+
const unpacked = this.decompress(packed, splitter);
|
|
185
|
+
if (packed.length < text.length) {
|
|
186
|
+
if (unpacked == text) return [1, packed.length, splitter, packed];
|
|
187
|
+
else if (unpacked.slice(0,-1) == text) return [2, packed.length, splitter, packed];
|
|
188
|
+
else return 0;
|
|
189
|
+
}
|
|
190
|
+
return 0;
|
|
191
|
+
} catch (_) {
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const freqMapSplitters = [
|
|
198
|
+
" \u200B","\u0000",
|
|
199
|
+
"\u001F", "\u0001",
|
|
200
|
+
"\uFFFD", "\u2022",
|
|
201
|
+
"|§|", "\uFEFF"
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
if ((String.fromCharCode(65536).charCodeAt(0) === 65536) || !(String.fromCharCode(256).charCodeAt(0) === 256)) {
|
|
205
|
+
throw new Error(prefix+'Supported UTF-16 only!')
|
|
206
|
+
}
|
|
207
|
+
|
|
96
208
|
function charsBase() {
|
|
97
209
|
const charsBase = {};
|
|
98
210
|
function addChar(i) {
|
|
@@ -631,117 +743,6 @@ function decompressSequences(str) {
|
|
|
631
743
|
return result;
|
|
632
744
|
}
|
|
633
745
|
|
|
634
|
-
const freqMap = {
|
|
635
|
-
ESCAPE_BYTE: 0xFF,
|
|
636
|
-
TOP_COUNT: 254,
|
|
637
|
-
SPLITTER: " \u200B",
|
|
638
|
-
|
|
639
|
-
compress(text, splitter = this.SPLITTER) {
|
|
640
|
-
const freq = {};
|
|
641
|
-
for (let char of text) {
|
|
642
|
-
freq[char] = (freq[char] || 0) + 1;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
const topChars = Object.entries(freq)
|
|
646
|
-
.sort((a, b) => b[1] - a[1])
|
|
647
|
-
.slice(0, this.TOP_COUNT)
|
|
648
|
-
.map(entry => entry[0]);
|
|
649
|
-
|
|
650
|
-
const charToIndex = new Map(topChars.map((char, i) => [char, i]));
|
|
651
|
-
|
|
652
|
-
let header = String.fromCharCode(topChars.length) + topChars.join('');
|
|
653
|
-
|
|
654
|
-
let bytes = [];
|
|
655
|
-
for (let char of text) {
|
|
656
|
-
if (charToIndex.has(char)) {
|
|
657
|
-
/* frequent */
|
|
658
|
-
bytes.push(charToIndex.get(char));
|
|
659
|
-
} else {
|
|
660
|
-
/* rare */
|
|
661
|
-
bytes.push(this.ESCAPE_BYTE);
|
|
662
|
-
const code = char.charCodeAt(0);
|
|
663
|
-
bytes.push((code >> 8) & 0xFF);
|
|
664
|
-
bytes.push(code & 0xFF);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/* to UTF16 */
|
|
669
|
-
let compressedBody = "";
|
|
670
|
-
for (let i = 0; i < bytes.length; i += 2) {
|
|
671
|
-
const b1 = bytes[i];
|
|
672
|
-
const b2 = (i + 1 < bytes.length) ? bytes[i + 1] : 0x00;
|
|
673
|
-
compressedBody += String.fromCharCode((b1 << 8) | b2);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
return header + splitter + compressedBody;
|
|
677
|
-
},
|
|
678
|
-
|
|
679
|
-
decompress(compressedText, splitter = this.SPLITTER) {
|
|
680
|
-
const parts = compressedText.split(splitter);
|
|
681
|
-
|
|
682
|
-
if (parts.length < 2) {
|
|
683
|
-
throw new Error(prefix+'Invalid freqMap data: splitter not found');
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
const headerPart = parts[0];
|
|
687
|
-
const bodyPart = parts.slice(1).join(splitter);
|
|
688
|
-
|
|
689
|
-
const topCount = headerPart.charCodeAt(0);
|
|
690
|
-
const topChars = headerPart.substring(1, topCount + 1);
|
|
691
|
-
|
|
692
|
-
let bytes = [];
|
|
693
|
-
for (let i = 0; i < bodyPart.length; i++) {
|
|
694
|
-
const code = bodyPart.charCodeAt(i);
|
|
695
|
-
bytes.push((code >> 8) & 0xFF);
|
|
696
|
-
bytes.push(code & 0xFF);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
let result = "";
|
|
700
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
701
|
-
const b = bytes[i];
|
|
702
|
-
if (b === this.ESCAPE_BYTE) {
|
|
703
|
-
const charCode = (bytes[i + 1] << 8) | bytes[i + 2];
|
|
704
|
-
result += String.fromCharCode(charCode);
|
|
705
|
-
i += 2;
|
|
706
|
-
} else if (b < topCount) {
|
|
707
|
-
result += topChars[b];
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return result;
|
|
711
|
-
},
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* 0 = Fail
|
|
715
|
-
* 1 = Success
|
|
716
|
-
* 2 = Remove last character (Success)
|
|
717
|
-
* @param {string} text
|
|
718
|
-
* @param {string?} splitter
|
|
719
|
-
* @returns {number|[number, number, string, string]}
|
|
720
|
-
*/
|
|
721
|
-
test(text, splitter = this.SPLITTER) {
|
|
722
|
-
try {
|
|
723
|
-
if (text.includes(splitter)) return 0;
|
|
724
|
-
const packed = this.compress(text, splitter);
|
|
725
|
-
const unpacked = this.decompress(packed, splitter);
|
|
726
|
-
if (packed.length < text.length) {
|
|
727
|
-
if (unpacked == text) return [1, packed.length, splitter, packed];
|
|
728
|
-
else if (unpacked.slice(0,-1) == text) return [2, packed.length, splitter, packed];
|
|
729
|
-
else return 0;
|
|
730
|
-
}
|
|
731
|
-
return 0;
|
|
732
|
-
} catch (_) {
|
|
733
|
-
return 0;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
const freqMapSplitters = [
|
|
739
|
-
" \u200B","\u0000",
|
|
740
|
-
"\u001F", "\u0001",
|
|
741
|
-
"\uFFFD", "\u2022",
|
|
742
|
-
"|§|", "\uFEFF"
|
|
743
|
-
];
|
|
744
|
-
|
|
745
746
|
function segments(str) {
|
|
746
747
|
if (typeof str !== 'string' || str.length === 0) return [];
|
|
747
748
|
|
package/dist/jssc.js
CHANGED
|
@@ -45,9 +45,6 @@ SOFTWARE.
|
|
|
45
45
|
|
|
46
46
|
const name__ = 'JSSC';
|
|
47
47
|
const prefix = name__+': ';
|
|
48
|
-
if ((String.fromCharCode(65536).charCodeAt(0) === 65536) || !(String.fromCharCode(256).charCodeAt(0) === 256)) {
|
|
49
|
-
throw new Error(prefix+'Supported UTF-16 only!')
|
|
50
|
-
}
|
|
51
48
|
|
|
52
49
|
function stringCodes(str) {
|
|
53
50
|
let output = [];
|
|
@@ -93,6 +90,121 @@ SOFTWARE.
|
|
|
93
90
|
return parseInt(str, 2);
|
|
94
91
|
}
|
|
95
92
|
|
|
93
|
+
const freqMap = {
|
|
94
|
+
ESCAPE_BYTE: 0xFF,
|
|
95
|
+
TOP_COUNT: 254,
|
|
96
|
+
SPLITTER: " \u200B",
|
|
97
|
+
|
|
98
|
+
compress(text, splitter = this.SPLITTER) {
|
|
99
|
+
const freq = {};
|
|
100
|
+
for (let char of text) {
|
|
101
|
+
freq[char] = (freq[char] || 0) + 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const topChars = Object.entries(freq)
|
|
105
|
+
.sort((a, b) => b[1] - a[1])
|
|
106
|
+
.slice(0, this.TOP_COUNT)
|
|
107
|
+
.map(entry => entry[0]);
|
|
108
|
+
|
|
109
|
+
const charToIndex = new Map(topChars.map((char, i) => [char, i]));
|
|
110
|
+
|
|
111
|
+
let header = String.fromCharCode(topChars.length) + topChars.join('');
|
|
112
|
+
|
|
113
|
+
let bytes = [];
|
|
114
|
+
for (let char of text) {
|
|
115
|
+
if (charToIndex.has(char)) {
|
|
116
|
+
/* frequent */
|
|
117
|
+
bytes.push(charToIndex.get(char));
|
|
118
|
+
} else {
|
|
119
|
+
/* rare */
|
|
120
|
+
bytes.push(this.ESCAPE_BYTE);
|
|
121
|
+
const code = char.charCodeAt(0);
|
|
122
|
+
bytes.push((code >> 8) & 0xFF);
|
|
123
|
+
bytes.push(code & 0xFF);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* to UTF16 */
|
|
128
|
+
let compressedBody = "";
|
|
129
|
+
for (let i = 0; i < bytes.length; i += 2) {
|
|
130
|
+
const b1 = bytes[i];
|
|
131
|
+
const b2 = (i + 1 < bytes.length) ? bytes[i + 1] : 0x00;
|
|
132
|
+
compressedBody += String.fromCharCode((b1 << 8) | b2);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return header + splitter + compressedBody;
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
decompress(compressedText, splitter = this.SPLITTER) {
|
|
139
|
+
const parts = compressedText.split(splitter);
|
|
140
|
+
|
|
141
|
+
if (parts.length < 2) {
|
|
142
|
+
throw new Error(prefix+'Invalid freqMap data: splitter not found');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const headerPart = parts[0];
|
|
146
|
+
const bodyPart = parts.slice(1).join(splitter);
|
|
147
|
+
|
|
148
|
+
const topCount = headerPart.charCodeAt(0);
|
|
149
|
+
const topChars = headerPart.substring(1, topCount + 1);
|
|
150
|
+
|
|
151
|
+
let bytes = [];
|
|
152
|
+
for (let i = 0; i < bodyPart.length; i++) {
|
|
153
|
+
const code = bodyPart.charCodeAt(i);
|
|
154
|
+
bytes.push((code >> 8) & 0xFF);
|
|
155
|
+
bytes.push(code & 0xFF);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let result = "";
|
|
159
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
160
|
+
const b = bytes[i];
|
|
161
|
+
if (b === this.ESCAPE_BYTE) {
|
|
162
|
+
const charCode = (bytes[i + 1] << 8) | bytes[i + 2];
|
|
163
|
+
result += String.fromCharCode(charCode);
|
|
164
|
+
i += 2;
|
|
165
|
+
} else if (b < topCount) {
|
|
166
|
+
result += topChars[b];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 0 = Fail
|
|
174
|
+
* 1 = Success
|
|
175
|
+
* 2 = Remove last character (Success)
|
|
176
|
+
* @param {string} text
|
|
177
|
+
* @param {string?} splitter
|
|
178
|
+
* @returns {number|[number, number, string, string]}
|
|
179
|
+
*/
|
|
180
|
+
test(text, splitter = this.SPLITTER) {
|
|
181
|
+
try {
|
|
182
|
+
if (text.includes(splitter)) return 0;
|
|
183
|
+
const packed = this.compress(text, splitter);
|
|
184
|
+
const unpacked = this.decompress(packed, splitter);
|
|
185
|
+
if (packed.length < text.length) {
|
|
186
|
+
if (unpacked == text) return [1, packed.length, splitter, packed];
|
|
187
|
+
else if (unpacked.slice(0,-1) == text) return [2, packed.length, splitter, packed];
|
|
188
|
+
else return 0;
|
|
189
|
+
}
|
|
190
|
+
return 0;
|
|
191
|
+
} catch (_) {
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const freqMapSplitters = [
|
|
198
|
+
" \u200B","\u0000",
|
|
199
|
+
"\u001F", "\u0001",
|
|
200
|
+
"\uFFFD", "\u2022",
|
|
201
|
+
"|§|", "\uFEFF"
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
if ((String.fromCharCode(65536).charCodeAt(0) === 65536) || !(String.fromCharCode(256).charCodeAt(0) === 256)) {
|
|
205
|
+
throw new Error(prefix+'Supported UTF-16 only!')
|
|
206
|
+
}
|
|
207
|
+
|
|
96
208
|
function charsBase() {
|
|
97
209
|
const charsBase = {};
|
|
98
210
|
function addChar(i) {
|
|
@@ -631,117 +743,6 @@ SOFTWARE.
|
|
|
631
743
|
return result;
|
|
632
744
|
}
|
|
633
745
|
|
|
634
|
-
const freqMap = {
|
|
635
|
-
ESCAPE_BYTE: 0xFF,
|
|
636
|
-
TOP_COUNT: 254,
|
|
637
|
-
SPLITTER: " \u200B",
|
|
638
|
-
|
|
639
|
-
compress(text, splitter = this.SPLITTER) {
|
|
640
|
-
const freq = {};
|
|
641
|
-
for (let char of text) {
|
|
642
|
-
freq[char] = (freq[char] || 0) + 1;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
const topChars = Object.entries(freq)
|
|
646
|
-
.sort((a, b) => b[1] - a[1])
|
|
647
|
-
.slice(0, this.TOP_COUNT)
|
|
648
|
-
.map(entry => entry[0]);
|
|
649
|
-
|
|
650
|
-
const charToIndex = new Map(topChars.map((char, i) => [char, i]));
|
|
651
|
-
|
|
652
|
-
let header = String.fromCharCode(topChars.length) + topChars.join('');
|
|
653
|
-
|
|
654
|
-
let bytes = [];
|
|
655
|
-
for (let char of text) {
|
|
656
|
-
if (charToIndex.has(char)) {
|
|
657
|
-
/* frequent */
|
|
658
|
-
bytes.push(charToIndex.get(char));
|
|
659
|
-
} else {
|
|
660
|
-
/* rare */
|
|
661
|
-
bytes.push(this.ESCAPE_BYTE);
|
|
662
|
-
const code = char.charCodeAt(0);
|
|
663
|
-
bytes.push((code >> 8) & 0xFF);
|
|
664
|
-
bytes.push(code & 0xFF);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/* to UTF16 */
|
|
669
|
-
let compressedBody = "";
|
|
670
|
-
for (let i = 0; i < bytes.length; i += 2) {
|
|
671
|
-
const b1 = bytes[i];
|
|
672
|
-
const b2 = (i + 1 < bytes.length) ? bytes[i + 1] : 0x00;
|
|
673
|
-
compressedBody += String.fromCharCode((b1 << 8) | b2);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
return header + splitter + compressedBody;
|
|
677
|
-
},
|
|
678
|
-
|
|
679
|
-
decompress(compressedText, splitter = this.SPLITTER) {
|
|
680
|
-
const parts = compressedText.split(splitter);
|
|
681
|
-
|
|
682
|
-
if (parts.length < 2) {
|
|
683
|
-
throw new Error(prefix+'Invalid freqMap data: splitter not found');
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
const headerPart = parts[0];
|
|
687
|
-
const bodyPart = parts.slice(1).join(splitter);
|
|
688
|
-
|
|
689
|
-
const topCount = headerPart.charCodeAt(0);
|
|
690
|
-
const topChars = headerPart.substring(1, topCount + 1);
|
|
691
|
-
|
|
692
|
-
let bytes = [];
|
|
693
|
-
for (let i = 0; i < bodyPart.length; i++) {
|
|
694
|
-
const code = bodyPart.charCodeAt(i);
|
|
695
|
-
bytes.push((code >> 8) & 0xFF);
|
|
696
|
-
bytes.push(code & 0xFF);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
let result = "";
|
|
700
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
701
|
-
const b = bytes[i];
|
|
702
|
-
if (b === this.ESCAPE_BYTE) {
|
|
703
|
-
const charCode = (bytes[i + 1] << 8) | bytes[i + 2];
|
|
704
|
-
result += String.fromCharCode(charCode);
|
|
705
|
-
i += 2;
|
|
706
|
-
} else if (b < topCount) {
|
|
707
|
-
result += topChars[b];
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return result;
|
|
711
|
-
},
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* 0 = Fail
|
|
715
|
-
* 1 = Success
|
|
716
|
-
* 2 = Remove last character (Success)
|
|
717
|
-
* @param {string} text
|
|
718
|
-
* @param {string?} splitter
|
|
719
|
-
* @returns {number|[number, number, string, string]}
|
|
720
|
-
*/
|
|
721
|
-
test(text, splitter = this.SPLITTER) {
|
|
722
|
-
try {
|
|
723
|
-
if (text.includes(splitter)) return 0;
|
|
724
|
-
const packed = this.compress(text, splitter);
|
|
725
|
-
const unpacked = this.decompress(packed, splitter);
|
|
726
|
-
if (packed.length < text.length) {
|
|
727
|
-
if (unpacked == text) return [1, packed.length, splitter, packed];
|
|
728
|
-
else if (unpacked.slice(0,-1) == text) return [2, packed.length, splitter, packed];
|
|
729
|
-
else return 0;
|
|
730
|
-
}
|
|
731
|
-
return 0;
|
|
732
|
-
} catch (_) {
|
|
733
|
-
return 0;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
const freqMapSplitters = [
|
|
739
|
-
" \u200B","\u0000",
|
|
740
|
-
"\u001F", "\u0001",
|
|
741
|
-
"\uFFFD", "\u2022",
|
|
742
|
-
"|§|", "\uFEFF"
|
|
743
|
-
];
|
|
744
|
-
|
|
745
746
|
function segments(str) {
|
|
746
747
|
if (typeof str !== 'string' || str.length === 0) return [];
|
|
747
748
|
|