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

8
node_modules/buffer-json/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,8 @@
2.0.0 / 2019-02-25
-------------------
- rewrite to fix edge cases
1.0.0 / 2015-06-18
------------------
- initial release

53
node_modules/buffer-json/README.md generated vendored Normal file
View File

@ -0,0 +1,53 @@
# buffer-json
```
npm install buffer-json
```
```js
const BJSON = require('buffer-json')
const str = BJSON.stringify({ buf: Buffer.from('hello') })
// => '{"buf":{"type":"Buffer","data":"base64:aGVsbG8="}}'
BJSON.parse(str)
// => { buf: <Buffer 68 65 6c 6c 6f> }
```
The [`Buffer`](https://nodejs.org/api/buffer.html#buffer_buffer) class in Node.js is used to represent binary data. JSON does not specify a way to encode binary data, so the Node.js implementation of `JSON.stringify` represents buffers as an object of shape `{ type: "Buffer", data: [<bytes as numbers>] }`. Unfortunately, `JSON.parse` does not turn this structure back into a `Buffer` object:
```
$ node
> JSON.parse(JSON.stringify({ buf: Buffer.from('hello world') }))
{ buf:
{ type: 'Buffer',
data: [ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 ] } }
```
`JSON.stringify` and `JSON.parse` accept arguments called [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) and [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) respectively which allow customizing the parsing/encoding behavior. This module provides a replacer which encodes Buffer data as a base64-encoded string, and a reviver which turns JSON objects which contain buffer-like data (either as arrays of numbers or strings) into `Buffer` instances. All other types of values are parsed/encoded as normal.
## API
### `stringify(value[, space])`
Convenience wrapper for [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) with the `replacer` described below.
### `parse(text)`
Convenience wrapper for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) with the `reviver` described below.
### `replacer(key, value)`
A [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) implementation which turns every value that is a `Buffer` instance into an object of shape `{ type: 'Buffer', data: 'base64:<base64-encoded buffer content>' }`. Empty buffers are encoded as `{ type: 'Buffer', data: '' }`.
### `reviver(key, value)`
A [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) implementation which turns every object of shape `{ type: 'Buffer', data: <array of numbers or string> }` into a `Buffer` instance.
## Related modules
- [`buffer-json-encoding`](https://github.com/lachenmayer/buffer-json-encoding): an [`abstract-encoding`](https://github.com/mafintosh/abstract-encoding) compatible JSON encoder/decoder which uses this module.
## License
MIT

60
node_modules/buffer-json/index.js generated vendored Normal file
View File

@ -0,0 +1,60 @@
function stringify (value, space) {
return JSON.stringify(value, replacer, space)
}
function parse (text) {
return JSON.parse(text, reviver)
}
function replacer (key, value) {
if (isBufferLike(value)) {
if (isArray(value.data)) {
if (value.data.length > 0) {
value.data = 'base64:' + Buffer.from(value.data).toString('base64')
} else {
value.data = ''
}
}
}
return value
}
function reviver (key, value) {
if (isBufferLike(value)) {
if (isArray(value.data)) {
return Buffer.from(value.data)
} else if (isString(value.data)) {
if (value.data.startsWith('base64:')) {
return Buffer.from(value.data.slice('base64:'.length), 'base64')
}
// Assume that the string is UTF-8 encoded (or empty).
return Buffer.from(value.data)
}
}
return value
}
function isBufferLike (x) {
return (
isObject(x) && x.type === 'Buffer' && (isArray(x.data) || isString(x.data))
)
}
function isArray (x) {
return Array.isArray(x)
}
function isString (x) {
return typeof x === 'string'
}
function isObject (x) {
return typeof x === 'object' && x !== null
}
module.exports = {
stringify,
parse,
replacer,
reviver
}

32
node_modules/buffer-json/package.json generated vendored Normal file
View File

@ -0,0 +1,32 @@
{
"name": "buffer-json",
"version": "2.0.0",
"description": "JSON.stringify & JSON.parse which can encode/decode buffers.",
"main": "index.js",
"scripts": {
"test": "standard --fix && node test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jprichardson/buffer-json.git"
},
"keywords": [
"JSON",
"parse",
"stringify",
"buffer",
"reviver",
"replacer",
"base64"
],
"author": "JP Richardson",
"license": "MIT",
"bugs": {
"url": "https://github.com/jprichardson/buffer-json/issues"
},
"homepage": "https://github.com/jprichardson/buffer-json#readme",
"devDependencies": {
"standard": "^12.0.1",
"tape": "^4.10.1"
}
}