-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
533 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/dist/ | ||
/lib/ | ||
/es/ | ||
/node_modules/ | ||
/public/ | ||
/config/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,8 @@ dist | |
# TernJS port file | ||
.tern-port | ||
|
||
lib | ||
lib/ | ||
es/ | ||
temp | ||
*.bak | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint@18 --edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { extends: ['@commitlint/config-conventional'] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ export { | |
flattenPreData, | ||
compareTwoList, | ||
} from './parse-list'; | ||
export { splitLongList } from './split'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export function getStrListLength(list: Array<string>) { | ||
return list.reduce((acc, item) => acc + item.length, 0); | ||
} | ||
|
||
export function splitLongList(list: Array<string>, threshold = 3800, max = 3) { | ||
const strLen = getStrListLength(list); | ||
if (strLen <= threshold) { | ||
return [list]; | ||
} | ||
const result = []; | ||
let temp = []; | ||
for (let i = 0; i < list.length;i++) { | ||
const item = list[i]; | ||
temp.push(item); | ||
|
||
const tempLen = getStrListLength(temp); | ||
if (tempLen >= threshold) { | ||
result.push(temp); | ||
temp = []; | ||
|
||
if (result.length >= max - 1) { | ||
temp = list.slice(i + 1); | ||
break; | ||
} | ||
} | ||
} | ||
result.push(temp); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
export const B64RE = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; | ||
export const _fromCC = String.fromCharCode.bind(String); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable */ | ||
import { B64, B64RE, _fromCC } from './config'; | ||
|
||
const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g; | ||
|
||
|
||
const _tidyB64 = function (s: string) { | ||
return s.replace(/[^A-Za-z0-9\+\/]/g, ''); | ||
}; | ||
|
||
const cb_btou = function (cccc: string) { | ||
switch (cccc.length) { | ||
case 4: | ||
var cp = ((0x07 & cccc.charCodeAt(0)) << 18) | ||
| ((0x3f & cccc.charCodeAt(1)) << 12) | ||
| ((0x3f & cccc.charCodeAt(2)) << 6) | ||
| (0x3f & cccc.charCodeAt(3)); var offset = cp - 0x10000; | ||
return (_fromCC((offset >>> 10) + 0xD800) | ||
+ _fromCC((offset & 0x3FF) + 0xDC00)); | ||
case 3: | ||
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12) | ||
| ((0x3f & cccc.charCodeAt(1)) << 6) | ||
| (0x3f & cccc.charCodeAt(2))); | ||
default: | ||
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6) | ||
| (0x3f & cccc.charCodeAt(1))); | ||
} | ||
}; | ||
|
||
const btou = function (b: string) { | ||
return b.replace(re_btou, cb_btou); | ||
}; | ||
|
||
|
||
const _unURI = function (a: string) { | ||
return _tidyB64(a.replace(/[-_]/g, m0 => (m0 == '-' ? '+' : '/'))); | ||
}; | ||
|
||
|
||
export const decode = (str: string) => btou(innerDecode(_unURI(str))); | ||
|
||
|
||
// 小程序版本的atob | ||
export const innerDecode = function (string: string) { | ||
string = String(string).replace(/[\t\n\f\r ]+/g, ''); | ||
if (!B64RE.test(string)) throw new TypeError('Failed to execute \'atob\' on \'Window\': The string to be decoded is not correctly encoded.'); | ||
string += '=='.slice(2 - (string.length & 3)); | ||
let bitmap; let result = ''; | ||
let r1; let r2; let i = 0; | ||
for (; i < string.length;) { | ||
bitmap = B64.indexOf(string.charAt(i++)) << 18 | B64.indexOf(string.charAt(i++)) << 12 | ||
| (r1 = B64.indexOf(string.charAt(i++))) << 6 | (r2 = B64.indexOf(string.charAt(i++))); | ||
|
||
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) | ||
: r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) | ||
: String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable */ | ||
import { B64, _fromCC } from './config'; | ||
const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; | ||
|
||
const utob = function (u: string) { | ||
return u.replace(re_utob, cb_utob); | ||
}; | ||
|
||
|
||
const cb_utob = function (c: string) { | ||
if (c.length < 2) { | ||
var cc: any = c.charCodeAt(0); | ||
return cc < 0x80 ? c | ||
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6)) | ||
+ _fromCC(0x80 | (cc & 0x3f))) | ||
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f)) | ||
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f)) | ||
+ _fromCC(0x80 | (cc & 0x3f))); | ||
} | ||
|
||
var cc: any = 0x10000 | ||
+ (c.charCodeAt(0) - 0xD800) * 0x400 | ||
+ (c.charCodeAt(1) - 0xDC00); | ||
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07)) | ||
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f)) | ||
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f)) | ||
+ _fromCC(0x80 | (cc & 0x3f))); | ||
}; | ||
|
||
export const encode = (str: string) => innerEncode(utob(str)); | ||
|
||
|
||
// 小程序版本的btoa | ||
export const innerEncode = function (string: string) { | ||
string = String(string); | ||
let bitmap; let a; let b; let c; | ||
let result = ''; | ||
let i = 0; | ||
const rest = string.length % 3; | ||
|
||
for (; i < string.length;) { | ||
if ((a = string.charCodeAt(i++)) > 255 | ||
|| (b = string.charCodeAt(i++)) > 255 | ||
|| (c = string.charCodeAt(i++)) > 255) throw new TypeError('Failed to execute \'btoa\' on \'Window\': The string to be encoded contains characters outside of the Latin1 range.'); | ||
|
||
bitmap = (a << 16) | (b << 8) | c; | ||
result += B64.charAt(bitmap >> 18 & 63) + B64.charAt(bitmap >> 12 & 63) | ||
+ B64.charAt(bitmap >> 6 & 63) + B64.charAt(bitmap & 63); | ||
} | ||
|
||
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { encode } from './encode'; | ||
export { decode } from './decode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.