[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-byte-length
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
+36
View File
@@ -0,0 +1,36 @@
# 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-byte-length/compare/v1.0.1...v1.0.2) - 2024-12-19
### Commits
- [readme] update URLs [`79df46c`](https://github.com/inspect-js/data-view-byte-length/commit/79df46cdf4c551d83059335ace8b8550369710b0)
- [actions] split out node 10-20, and 20+ [`2890929`](https://github.com/inspect-js/data-view-byte-length/commit/289092965343dfa6fcc931c32ecd1c1286f5f2dc)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/object-inspect`, `@types/tape`, `auto-changelog`, `es-value-fixtures`, `object-inspect`, `tape` [`97fac7f`](https://github.com/inspect-js/data-view-byte-length/commit/97fac7fb6c2f3655c9755d9dcf3569cdf6899635)
- [Refactor] use `call-bound` directly [`56f17fa`](https://github.com/inspect-js/data-view-byte-length/commit/56f17fa583a963c2a6d2da5f2db00f7725714533)
- [Deps] update `call-bind`, `is-data-view` [`254a502`](https://github.com/inspect-js/data-view-byte-length/commit/254a5026c0201eb35d20722af2993e0412b2f2ea)
- [Tests] replace `aud` with `npm audit` [`7158679`](https://github.com/inspect-js/data-view-byte-length/commit/7158679d1ef0e15ccf64b6d0169413ed8351f243)
- [Dev Deps] update `@ljharb/tsconfig` [`ed63290`](https://github.com/inspect-js/data-view-byte-length/commit/ed63290bc162fe5a9086412fc6099dd49c70d474)
## [v1.0.1](https://github.com/inspect-js/data-view-byte-length/compare/v1.0.0...v1.0.1) - 2024-03-08
### Commits
- [types] use shared tsconfig [`0d5873c`](https://github.com/inspect-js/data-view-byte-length/commit/0d5873c9fddd413bacbb3a2c32e7e1a7f1f5bd2c)
- [Dev Deps] update `@arethetypeswrong/cli`, `tape` [`13c1eaf`](https://github.com/inspect-js/data-view-byte-length/commit/13c1eafea562993c7d15a450e86d2ee7a1aa8299)
- [patch] fix function name [`a061e7b`](https://github.com/inspect-js/data-view-byte-length/commit/a061e7b457f53bdc39716dacdddbe558ee790745)
- [Deps] update `call-bind` [`6603851`](https://github.com/inspect-js/data-view-byte-length/commit/6603851eef423c5762841221f97abfdc905c8bde)
## v1.0.0 - 2024-03-04
### Commits
- Initial implementation, tests, readme, types [`79ad058`](https://github.com/inspect-js/data-view-byte-length/commit/79ad058a73a4f8425e8ad034211dfc39e643dc86)
- Initial commit [`1a11313`](https://github.com/inspect-js/data-view-byte-length/commit/1a113138783a815f66fd000a9f9c89fdbe8c98fb)
- npm init [`aac0108`](https://github.com/inspect-js/data-view-byte-length/commit/aac010820b20b8604d33e5a74b51591f19f553e2)
- Only apps should have lockfiles [`cdf1a15`](https://github.com/inspect-js/data-view-byte-length/commit/cdf1a15d4c201137982e1e703d56a42582c6d246)
+43
View File
@@ -0,0 +1,43 @@
# data-view-byte-length <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 `byteLength` 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.byteLength` has been deleted after this module has loaded.
## Example
```js
const dataViewByteLength = require('data-view-byte-length');
const assert = require('assert');
const ab = new ArrayBuffer(42);
const dv = new DataView(ab);
assert.equal(dataViewByteLength(dv), 42);
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/data-view-byte-length
[npm-version-svg]: https://versionbadg.es/inspect-js/data-view-byte-length.svg
[deps-svg]: https://david-dm.org/inspect-js/data-view-byte-length.svg
[deps-url]: https://david-dm.org/inspect-js/data-view-byte-length
[dev-deps-svg]: https://david-dm.org/inspect-js/data-view-byte-length/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/data-view-byte-length#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/data-view-byte-length.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/data-view-byte-length.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/data-view-byte-length.svg
[downloads-url]: https://npm-stat.com/charts.html?package=data-view-byte-length
[codecov-image]: https://codecov.io/gh/inspect-js/data-view-byte-length/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/data-view-byte-length/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/data-view-byte-length
[actions-url]: https://github.com/inspect-js/data-view-byte-length/actions
+4
View File
@@ -0,0 +1,4 @@
declare function dataViewByteLength(value: DataView): number;
declare function dataViewByteLength(value: unknown): never;
export = dataViewByteLength;
+92
View File
@@ -0,0 +1,92 @@
{
"name": "data-view-byte-length",
"version": "1.0.2",
"description": "Get the byteLength 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 . && attw -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/inspect-js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/inspect-js/data-view-byte-length.git"
},
"keywords": [
"javascript",
"ecmascript",
"dataview",
"data",
"view",
"byte",
"length",
"byteLength",
"robust"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/data-view-byte-length/issues"
},
"homepage": "https://github.com/inspect-js/data-view-byte-length#readme",
"dependencies": {
"call-bound": "^1.0.3",
"es-errors": "^1.3.0",
"is-data-view": "^1.0.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@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",
"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 dataViewByteLength = require('../');
test('dataViewByteLength', 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 () { dataViewByteLength(nonDV); }, TypeError, inspect(nonDV) + ' is not a DataView');
}
);
t.test('DataView', { skip: typeof DataView !== 'function' }, function (st) {
var ab = new ArrayBuffer(42);
var dv = new DataView(ab);
st.equal(dataViewByteLength(dv), 42, inspect(dv) + ' has the same byteLength as the buffer originally passed to the DataView');
st.equal(dataViewByteLength(dv), dv.buffer.byteLength, inspect(dv) + ' has the same byteLength as the buffers byteLength of its own buffer property');
st.end();
});
t.end();
});
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
},
"exclude": [
"coverage",
],
}