[backend] fix: 修复异常处理和类型转换问题

This commit is contained in:
xsl
2026-01-26 11:53:40 +08:00
parent 7ccc2a6ac6
commit 83e05bf85f
28639 changed files with 2506458 additions and 93 deletions
+12
View File
@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/data-view-buffer
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with a single custom sponsorship URL
+38
View File
@@ -0,0 +1,38 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.2](https://github.com/inspect-js/data-view-buffer/compare/v1.0.1...v1.0.2) - 2024-12-19
### Commits
- [actions] split out node 10-20, and 20+ [`f99dc3f`](https://github.com/inspect-js/data-view-buffer/commit/f99dc3f4c0edc7ffa3cc96302b1c0c96663d0a48)
- [types] use shared tsconfig [`9ad8630`](https://github.com/inspect-js/data-view-buffer/commit/9ad86303de5ccef0daf248177b50f33316d1b3d5)
- [readme] update URLs [`d3c66fb`](https://github.com/inspect-js/data-view-buffer/commit/d3c66fb4426b8d57834dea4842a06ef4ad7c4695)
- [Dev Deps] update `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/object-inspect`, `@types/tape`, `auto-changelog`, `es-value-fixtures`, `object-inspect`, `tape` [`7dda732`](https://github.com/inspect-js/data-view-buffer/commit/7dda732235b65fe23608ac8a0a55207c53236a20)
- [Refactor] use `call-bound` directly [`5e124f9`](https://github.com/inspect-js/data-view-buffer/commit/5e124f92ef654f32c67d9eb12d19ecf1b42d8e6f)
- [Deps] update `call-bind`, `is-data-view` [`73fb1a4`](https://github.com/inspect-js/data-view-buffer/commit/73fb1a47dba2f1be13101770fc5dcae8e79a67fa)
- [Tests] replace `aud` with `npm audit` [`64563a3`](https://github.com/inspect-js/data-view-buffer/commit/64563a3cb83ee6ddc969de8fadf9379300933187)
- [Dev Deps] update `@ljharb/tsconfig` [`b842ce8`](https://github.com/inspect-js/data-view-buffer/commit/b842ce8adf17cf59158a3906a092d1dc5e6c10f9)
- [Deps] update `call-bind` [`bc89873`](https://github.com/inspect-js/data-view-buffer/commit/bc89873b8b4d657284a731f53cec9e69fe35057d)
- [Dev Deps] update `tape` [`b6ed8cb`](https://github.com/inspect-js/data-view-buffer/commit/b6ed8cb5804237d6f4e6bb2e3c1418c7ac3acc9b)
- [Dev Deps] add missing peer dep [`ba96a94`](https://github.com/inspect-js/data-view-buffer/commit/ba96a94c8d1afda58f302a4fc294a2633462b18a)
## [v1.0.1](https://github.com/inspect-js/data-view-buffer/compare/v1.0.0...v1.0.1) - 2024-02-06
### Commits
- [Refactor] use `es-errors`, so things that only need those do not need `get-intrinsic` [`675f588`](https://github.com/inspect-js/data-view-buffer/commit/675f588236e489268de9f7a0adf33ef8295a3c71)
- [Deps] update `call-bind`, `get-intrinsic` [`e6eb209`](https://github.com/inspect-js/data-view-buffer/commit/e6eb209578556ade150f0c3945cdeec9ffc582e2)
## v1.0.0 - 2024-02-02
### Commits
- Initial implementation, tests, readme, types [`2e1382b`](https://github.com/inspect-js/data-view-buffer/commit/2e1382b26a98acc6f2ade4a061e1cd829e3043b8)
- Initial commit [`1eb7dc4`](https://github.com/inspect-js/data-view-buffer/commit/1eb7dc4a0369d8320406bd7f9366c7887888790e)
- npm init [`d9e3d47`](https://github.com/inspect-js/data-view-buffer/commit/d9e3d4707b54bf77de30565ea5c6c0fcdf4a0ecc)
- Only apps should have lockfiles [`116b60b`](https://github.com/inspect-js/data-view-buffer/commit/116b60b9054de3331cd3c1599280466405c0d128)
+43
View File
@@ -0,0 +1,43 @@
# data-view-buffer <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Get the ArrayBuffer out of a DataView, robustly.
This will work in node <= 0.10 and < 0.11.4, where there's no prototype accessor, only a nonconfigurable own property.
It will also work in modern engines where `DataView.prototype.buffer` has been deleted after this module has loaded.
## Example
```js
const dataViewBuffer = require('data-view-buffer');
const assert = require('assert');
const ab = new ArrayBuffer(0);
const dv = new DataView(ab);
assert.equal(dataViewBuffer(dv), ab);
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/data-view-buffer
[npm-version-svg]: https://versionbadg.es/inspect-js/data-view-buffer.svg
[deps-svg]: https://david-dm.org/inspect-js/data-view-buffer.svg
[deps-url]: https://david-dm.org/inspect-js/data-view-buffer
[dev-deps-svg]: https://david-dm.org/inspect-js/data-view-buffer/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/data-view-buffer#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/data-view-buffer.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/data-view-buffer.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/data-view-buffer.svg
[downloads-url]: https://npm-stat.com/charts.html?package=data-view-buffer
[codecov-image]: https://codecov.io/gh/inspect-js/data-view-buffer/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/data-view-buffer/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/data-view-buffer
[actions-url]: https://github.com/inspect-js/data-view-buffer/actions
+4
View File
@@ -0,0 +1,4 @@
declare function dataViewBuffer(value: DataView): ArrayBuffer;
declare function dataViewBuffer(value: unknown): never;
export = dataViewBuffer;
+88
View File
@@ -0,0 +1,88 @@
{
"name": "data-view-buffer",
"version": "1.0.2",
"description": "Get the ArrayBuffer out of a DataView, robustly.",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"types": "./index.d.ts",
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc -p .",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "npx npm@'>= 10.2' audit --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"repository": {
"type": "git",
"url": "git+https://github.com/inspect-js/data-view-buffer.git"
},
"keywords": [
"javascript",
"ecmascript",
"dataview",
"buffer",
"robust"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/data-view-buffer/issues"
},
"homepage": "https://github.com/inspect-js/data-view-buffer#readme",
"dependencies": {
"call-bound": "^1.0.3",
"es-errors": "^1.3.0",
"is-data-view": "^1.0.2"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/es-value-fixtures": "^1.4.4",
"@types/for-each": "^0.3.3",
"@types/object-inspect": "^1.13.0",
"@types/tape": "^5.8.0",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
+31
View File
@@ -0,0 +1,31 @@
'use strict';
var test = require('tape');
var forEach = require('for-each');
var v = require('es-value-fixtures');
var inspect = require('object-inspect');
var dataViewBuffer = require('../');
test('dataViewBuffer', function (t) {
forEach(
// @ts-expect-error TS sucks at [].concat
// eslint-disable-next-line no-extra-parens
/** @type {[...typeof v.primitives, ...typeof v.objects]} */ ([].concat(v.primitives, v.objects)),
function (nonDV) {
t['throws'](function () { dataViewBuffer(nonDV); }, TypeError, inspect(nonDV) + ' is not a DataView');
}
);
t.test('DataView', { skip: typeof DataView !== 'function' }, function (st) {
var ab = new ArrayBuffer(1);
var dv = new DataView(ab);
st.equal(dataViewBuffer(dv), ab, inspect(dv) + ' has the same buffer originally passed to the DataView');
st.equal(dataViewBuffer(dv), dv.buffer, inspect(dv) + ' has the same buffer as its own buffer property');
st.end();
});
t.end();
});
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
},
"exclude": [
"coverage",
"test/list-exports"
],
}