fatsify核心功能示例测试!!!

This commit is contained in:
2025-09-21 14:50:41 +08:00
commit 9145aea047
1958 changed files with 230098 additions and 0 deletions

14
node_modules/fast-querystring/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
type FastQueryString = {
stringify(value: Record<string, any>): string;
parse(value: string): Record<string, any>;
};
declare namespace fastQueryString {
export function stringify(value: Record<string, any>): string;
export function parse(value: string): Record<string, any>;
const fqs: FastQueryString;
export { fqs as default };
}
export = fastQueryString;

20
node_modules/fast-querystring/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
const parse = require("./parse");
const stringify = require("./stringify");
const fastQuerystring = {
parse,
stringify,
};
/**
* Enable TS and JS support
*
* - `const qs = require('fast-querystring')`
* - `import qs from 'fast-querystring'`
*/
module.exports = fastQuerystring;
module.exports.default = fastQuerystring;
module.exports.parse = parse;
module.exports.stringify = stringify;

View File

@@ -0,0 +1,96 @@
// This file is taken from Node.js project.
// Full implementation can be found from https://github.com/nodejs/node/blob/main/lib/internal/querystring.js
const hexTable = Array.from(
{ length: 256 },
(_, i) => "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase(),
);
// These characters do not need escaping when generating query strings:
// ! - . _ ~
// ' ( ) *
// digits
// alpha (uppercase)
// alpha (lowercase)
// rome-ignore format: the array should not be formatted
const noEscape = new Int8Array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 32 - 47
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 80 - 95
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, // 112 - 127
]);
/**
* @param {string} str
* @returns {string}
*/
function encodeString(str) {
const len = str.length;
if (len === 0) return "";
let out = "";
let lastPos = 0;
let i = 0;
outer: for (; i < len; i++) {
let c = str.charCodeAt(i);
// ASCII
while (c < 0x80) {
if (noEscape[c] !== 1) {
if (lastPos < i) out += str.slice(lastPos, i);
lastPos = i + 1;
out += hexTable[c];
}
if (++i === len) break outer;
c = str.charCodeAt(i);
}
if (lastPos < i) out += str.slice(lastPos, i);
// Multi-byte characters ...
if (c < 0x800) {
lastPos = i + 1;
out += hexTable[0xc0 | (c >> 6)] + hexTable[0x80 | (c & 0x3f)];
continue;
}
if (c < 0xd800 || c >= 0xe000) {
lastPos = i + 1;
out +=
hexTable[0xe0 | (c >> 12)] +
hexTable[0x80 | ((c >> 6) & 0x3f)] +
hexTable[0x80 | (c & 0x3f)];
continue;
}
// Surrogate pair
++i;
// This branch should never happen because all URLSearchParams entries
// should already be converted to USVString. But, included for
// completion's sake anyway.
if (i >= len) {
throw new Error("URI malformed");
}
const c2 = str.charCodeAt(i) & 0x3ff;
lastPos = i + 1;
c = 0x10000 + (((c & 0x3ff) << 10) | c2);
out +=
hexTable[0xf0 | (c >> 18)] +
hexTable[0x80 | ((c >> 12) & 0x3f)] +
hexTable[0x80 | ((c >> 6) & 0x3f)] +
hexTable[0x80 | (c & 0x3f)];
}
if (lastPos === 0) return str;
if (lastPos < len) return out + str.slice(lastPos);
return out;
}
module.exports = { encodeString };

126
node_modules/fast-querystring/lib/parse.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
"use strict";
const fastDecode = require("fast-decode-uri-component");
const plusRegex = /\+/g;
const Empty = function () {};
Empty.prototype = Object.create(null);
/**
* @callback parse
* @param {string} input
*/
function parse(input) {
// Optimization: Use new Empty() instead of Object.create(null) for performance
// v8 has a better optimization for initializing functions compared to Object
const result = new Empty();
if (typeof input !== "string") {
return result;
}
let inputLength = input.length;
let key = "";
let value = "";
let startingIndex = -1;
let equalityIndex = -1;
let shouldDecodeKey = false;
let shouldDecodeValue = false;
let keyHasPlus = false;
let valueHasPlus = false;
let hasBothKeyValuePair = false;
let c = 0;
// Have a boundary of input.length + 1 to access last pair inside the loop.
for (let i = 0; i < inputLength + 1; i++) {
c = i !== inputLength ? input.charCodeAt(i) : 38;
// Handle '&' and end of line to pass the current values to result
if (c === 38) {
hasBothKeyValuePair = equalityIndex > startingIndex;
// Optimization: Reuse equality index to store the end of key
if (!hasBothKeyValuePair) {
equalityIndex = i;
}
key = input.slice(startingIndex + 1, equalityIndex);
// Add key/value pair only if the range size is greater than 1; a.k.a. contains at least "="
if (hasBothKeyValuePair || key.length > 0) {
// Optimization: Replace '+' with space
if (keyHasPlus) {
key = key.replace(plusRegex, " ");
}
// Optimization: Do not decode if it's not necessary.
if (shouldDecodeKey) {
key = fastDecode(key) || key;
}
if (hasBothKeyValuePair) {
value = input.slice(equalityIndex + 1, i);
if (valueHasPlus) {
value = value.replace(plusRegex, " ");
}
if (shouldDecodeValue) {
value = fastDecode(value) || value;
}
}
const currentValue = result[key];
if (currentValue === undefined) {
result[key] = value;
} else {
// Optimization: value.pop is faster than Array.isArray(value)
if (currentValue.pop) {
currentValue.push(value);
} else {
result[key] = [currentValue, value];
}
}
}
// Reset reading key value pairs
value = "";
startingIndex = i;
equalityIndex = i;
shouldDecodeKey = false;
shouldDecodeValue = false;
keyHasPlus = false;
valueHasPlus = false;
}
// Check '='
else if (c === 61) {
if (equalityIndex <= startingIndex) {
equalityIndex = i;
}
// If '=' character occurs again, we should decode the input.
else {
shouldDecodeValue = true;
}
}
// Check '+', and remember to replace it with empty space.
else if (c === 43) {
if (equalityIndex > startingIndex) {
valueHasPlus = true;
} else {
keyHasPlus = true;
}
}
// Check '%' character for encoding
else if (c === 37) {
if (equalityIndex > startingIndex) {
shouldDecodeValue = true;
} else {
shouldDecodeKey = true;
}
}
}
return result;
}
module.exports = parse;

69
node_modules/fast-querystring/lib/stringify.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
"use strict";
const { encodeString } = require("./internals/querystring");
function getAsPrimitive(value) {
const type = typeof value;
if (type === "string") {
// Length check is handled inside encodeString function
return encodeString(value);
} else if (type === "bigint") {
return value.toString();
} else if (type === "boolean") {
return value ? "true" : "false";
} else if (type === "number" && Number.isFinite(value)) {
return value < 1e21 ? "" + value : encodeString("" + value);
}
return "";
}
/**
* @param {Record<string, string | number | boolean
* | ReadonlyArray<string | number | boolean> | null>} input
* @returns {string}
*/
function stringify(input) {
let result = "";
if (input === null || typeof input !== "object") {
return result;
}
const separator = "&";
const keys = Object.keys(input);
const keyLength = keys.length;
let valueLength = 0;
for (let i = 0; i < keyLength; i++) {
const key = keys[i];
const value = input[key];
const encodedKey = encodeString(key) + "=";
if (i) {
result += separator;
}
if (Array.isArray(value)) {
valueLength = value.length;
for (let j = 0; j < valueLength; j++) {
if (j) {
result += separator;
}
// Optimization: Dividing into multiple lines improves the performance.
// Since v8 does not need to care about the '+' character if it was one-liner.
result += encodedKey;
result += getAsPrimitive(value[j]);
}
} else {
result += encodedKey;
result += getAsPrimitive(value);
}
}
return result;
}
module.exports = stringify;