first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

2
node_modules/encode-utf8/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
declare function encodeUtf8 (input: string): ArrayBuffer
export = encodeUtf8

55
node_modules/encode-utf8/index.js generated vendored Normal file
View File

@ -0,0 +1,55 @@
'use strict'
module.exports = function encodeUtf8 (input) {
var result = []
var size = input.length
for (var index = 0; index < size; index++) {
var point = input.charCodeAt(index)
if (point >= 0xD800 && point <= 0xDBFF && size > index + 1) {
var second = input.charCodeAt(index + 1)
if (second >= 0xDC00 && second <= 0xDFFF) {
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
point = (point - 0xD800) * 0x400 + second - 0xDC00 + 0x10000
index += 1
}
}
// US-ASCII
if (point < 0x80) {
result.push(point)
continue
}
// 2-byte UTF-8
if (point < 0x800) {
result.push((point >> 6) | 192)
result.push((point & 63) | 128)
continue
}
// 3-byte UTF-8
if (point < 0xD800 || (point >= 0xE000 && point < 0x10000)) {
result.push((point >> 12) | 224)
result.push(((point >> 6) & 63) | 128)
result.push((point & 63) | 128)
continue
}
// 4-byte UTF-8
if (point >= 0x10000 && point <= 0x10FFFF) {
result.push((point >> 18) | 240)
result.push(((point >> 12) & 63) | 128)
result.push(((point >> 6) & 63) | 128)
result.push((point & 63) | 128)
continue
}
// Invalid character
result.push(0xEF, 0xBF, 0xBD)
}
return new Uint8Array(result).buffer
}

13
node_modules/encode-utf8/package.json generated vendored Normal file
View File

@ -0,0 +1,13 @@
{
"name": "encode-utf8",
"version": "1.0.3",
"license": "MIT",
"repository": "LinusU/encode-utf8",
"scripts": {
"test": "standard && mocha"
},
"devDependencies": {
"mocha": "^6.2.2",
"standard": "^14.3.1"
}
}

27
node_modules/encode-utf8/readme.md generated vendored Normal file
View File

@ -0,0 +1,27 @@
# Encode UTF8
Turn a string into an ArrayBuffer by using the UTF8 encoding.
## Installation
```js
npm install --save encode-uf8
```
## Usage
```js
const encodeUtf8 = require('encode-utf8')
console.log(encodeUtf8('Hello, World!'))
//=> ArrayBuffer { byteLength: 13 }
console.log(encodeUtf8('🐵 🙈 🙉 🙊'))
//=> ArrayBuffer { byteLength: 19 }
```
## API
### `encodeUtf8(input: string): ArrayBuffer`
Returns an ArrayBuffer with the string represented as UTF8 encoded data.

74
node_modules/encode-utf8/test.js generated vendored Normal file
View File

@ -0,0 +1,74 @@
/* eslint-env mocha */
'use strict'
const assert = require('assert')
const encodeUtf8 = require('./')
const testCases = [
'゚・✿ヾ╲(。◕‿◕。)╱✿・゚',
'𝌆',
'🐵 🙈 🙉 🙊',
'💩',
'åß∂ƒ©˙∆˚¬…æ',
'Hello, World!',
'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗',
'𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌',
'사회과학원 어학연구소'
]
const badStrings = [
{
input: 'abc123',
expected: [0x61, 0x62, 0x63, 0x31, 0x32, 0x33],
name: 'Sanity check'
},
{
input: '\uD800',
expected: [0xef, 0xbf, 0xbd],
name: 'Surrogate half (low)'
},
{
input: '\uDC00',
expected: [0xef, 0xbf, 0xbd],
name: 'Surrogate half (high)'
},
{
input: 'abc\uD800123',
expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
name: 'Surrogate half (low), in a string'
},
{
input: 'abc\uDC00123',
expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
name: 'Surrogate half (high), in a string'
},
{
input: '\uDC00\uD800',
expected: [0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd],
name: 'Wrong order'
}
]
describe('encode-utf8', () => {
describe('test strings', () => {
for (const input of testCases) {
it(`should encode "${input}"`, () => {
const actual = Buffer.from(encodeUtf8(input))
const expected = Buffer.from(input, 'utf8')
assert.ok(actual.equals(expected))
})
}
})
describe('web platform test', () => {
for (const testCase of badStrings) {
it(testCase.name, () => {
const actual = Array.from(new Uint8Array(encodeUtf8(testCase.input)))
assert.deepStrictEqual(actual, testCase.expected)
})
}
})
})