[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/is-typed-array
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 up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+35
View File
@@ -0,0 +1,35 @@
# 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/is-data-view/compare/v1.0.1...v1.0.2) - 2024-12-11
### Commits
- [types] use shared config [`3a80072`](https://github.com/inspect-js/is-data-view/commit/3a800720dd322ea4656f29d28f1d28117fb94537)
- [actions] split out node 10-20, and 20+ [`e2f37fd`](https://github.com/inspect-js/is-data-view/commit/e2f37fdf421c4629730406c2b61d5481dce4e448)
- [Dev Deps] update `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/node`, `@types/object-inspect`, `@types/tape`, `auto-changelog`, `es-value-fixtures`, `object-inspect`, `tape` [`6f8e9dd`](https://github.com/inspect-js/is-data-view/commit/6f8e9dda376e421d30dd94e891bea3fbae7967ee)
- [Dev Deps] update `@types/node`, `available-typed-arrays`, `tape` [`37be591`](https://github.com/inspect-js/is-data-view/commit/37be59163c8df9abb016bbb4c7d76f3af549f1d2)
- [Fix] add missing dependencies; use `call-bound` directly [`34de4b5`](https://github.com/inspect-js/is-data-view/commit/34de4b5f5448ca1bb95c34686c51b5351904a317)
- [Tests] replace `aud` with `npm audit` [`aa7060a`](https://github.com/inspect-js/is-data-view/commit/aa7060ad77c9ba2d500b124b73662c3b069fc721)
- [Dev Deps] add missing peer dep [`3d302d7`](https://github.com/inspect-js/is-data-view/commit/3d302d7dbf99d75fcf4a3de14687e423ec88728f)
## [v1.0.1](https://github.com/inspect-js/is-data-view/compare/v1.0.0...v1.0.1) - 2024-02-02
### Commits
- [patch] add types [`c2728ef`](https://github.com/inspect-js/is-data-view/commit/c2728ef20064bba2588eed503a0c2e36985b638a)
- [Dev Deps] update `aud`, `available-typed-arrays`, `has-tostringtag`, `npmignore`, `object-inspect`, `tape` [`e7f9ebc`](https://github.com/inspect-js/is-data-view/commit/e7f9ebccf9aacdc112dd4f665271c96417ddfa64)
- [Deps] update `is-typed-array` [`2ca9333`](https://github.com/inspect-js/is-data-view/commit/2ca9333516afac321431ddae02d6791d50e8d5c2)
## v1.0.0 - 2024-01-31
### Commits
- Initial implementation, tests, readme [`6f7e424`](https://github.com/inspect-js/is-data-view/commit/6f7e4244ae9d766309b8f050c0b786e9c0692825)
- Initial commit [`4b7ea57`](https://github.com/inspect-js/is-data-view/commit/4b7ea57d6942dd268bcda990a96b8cd663b19eb8)
- npm init [`25130e2`](https://github.com/inspect-js/is-data-view/commit/25130e2dbecc91d398cf74c39878aa89f5e604ab)
- Only apps should have lockfiles [`18cde47`](https://github.com/inspect-js/is-data-view/commit/18cde474201a292ebdaa704d232127c814cb1d0e)
+69
View File
@@ -0,0 +1,69 @@
# is-data-view <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]
Is this value a JS DataView? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and despite ES6 Symbol.toStringTag.
## Example
```js
var isDataView = require('is-data-view');
var assert = require('assert');
assert.equal(false, isDataView(undefined));
assert.equal(false, isDataView(null));
assert.equal(false, isDataView(false));
assert.equal(false, isDataView(true));
assert.equal(false, isDataView([]));
assert.equal(false, isDataView({}));
assert.equal(false, isDataView(/a/g));
assert.equal(false, isDataView(new RegExp('a', 'g')));
assert.equal(false, isDataView(new Date()));
assert.equal(false, isDataView(42));
assert.equal(false, isDataView(NaN));
assert.equal(false, isDataView(Infinity));
assert.equal(false, isDataView(new Number(42)));
assert.equal(false, isDataView('foo'));
assert.equal(false, isDataView(Object('foo')));
assert.equal(false, isDataView(function () {}));
assert.equal(false, isDataView(function* () {}));
assert.equal(false, isDataView(x => x * x));
assert.equal(false, isDataView([]));
assert.equal(false, isDataView(new Int8Array()));
assert.equal(false, isDataView(new Uint8Array()));
assert.equal(false, isDataView(new Uint8ClampedArray()));
assert.equal(false, isDataView(new Int16Array()));
assert.equal(false, isDataView(new Uint16Array()));
assert.equal(false, isDataView(new Int32Array()));
assert.equal(false, isDataView(new Uint32Array()));
assert.equal(false, isDataView(new Float32Array()));
assert.equal(false, isDataView(new Float64Array()));
assert.equal(false, isDataView(new BigInt64Array()));
assert.equal(false, isDataView(new BigUint64Array()));
assert.ok(isDataView(new DataView(new ArrayBuffer(0))));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/is-data-view
[npm-version-svg]: https://versionbadg.es/inspect-js/is-data-view.svg
[deps-svg]: https://david-dm.org/inspect-js/is-data-view.svg
[deps-url]: https://david-dm.org/inspect-js/is-data-view
[dev-deps-svg]: https://david-dm.org/inspect-js/is-data-view/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/is-data-view#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/is-data-view.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/is-data-view.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/is-data-view.svg
[downloads-url]: https://npm-stat.com/charts.html?package=is-data-view
[codecov-image]: https://codecov.io/gh/inspect-js/is-data-view/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-data-view/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-data-view
[actions-url]: https://github.com/inspect-js/is-data-view/actions
+3
View File
@@ -0,0 +1,3 @@
declare function isDataView(value: unknown): value is DataView;
export = isDataView;
+100
View File
@@ -0,0 +1,100 @@
{
"name": "is-data-view",
"version": "1.0.2",
"description": "Is this value a JS DataView? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and despite ES6 Symbol.toStringTag.",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"types": "./index.d.ts",
"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/is-data-view.git"
},
"keywords": [
"javascript",
"ecmascript",
"dataview",
"data",
"view",
"typedarray",
"typedarrays"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/is-data-view/issues"
},
"homepage": "https://github.com/inspect-js/is-data-view#readme",
"dependencies": {
"call-bound": "^1.0.2",
"get-intrinsic": "^1.2.6",
"is-typed-array": "^1.1.13"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/call-bind": "^1.0.5",
"@types/es-value-fixtures": "^1.4.4",
"@types/for-each": "^0.3.3",
"@types/make-arrow-function": "^1.2.2",
"@types/make-generator-function": "^2.0.3",
"@types/node": "^20.17.10",
"@types/object-inspect": "^1.13.0",
"@types/tape": "^5.6.5",
"auto-changelog": "^2.5.0",
"available-typed-arrays": "^1.0.7",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"has-tostringtag": "^1.0.2",
"in-publish": "^2.0.1",
"make-arrow-function": "^1.2.0",
"make-generator-function": "^2.0.0",
"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"
},
"testling": {
"files": "test/index.js"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
+60
View File
@@ -0,0 +1,60 @@
'use strict';
var test = require('tape');
var isDataView = require('../');
var hasToStringTag = require('has-tostringtag/shams')();
var generators = require('make-generator-function')();
var arrowFns = require('make-arrow-function').list();
var forEach = require('for-each');
var v = require('es-value-fixtures');
var inspect = require('object-inspect');
var availableTypedArrays = require('available-typed-arrays')();
test('not DataViews', function (t) {
forEach([].concat(
// @ts-expect-error TS sucks at [].concat
v.primitives,
v.objects,
function () {},
generators,
arrowFns,
[]
), /** @type {(nonDV: unknown) => void} */ function (nonDV) {
t.equal(
isDataView(nonDV),
false,
inspect(nonDV) + ' is not a DataView'
);
});
forEach(availableTypedArrays, function (typedArray) {
var TA = global[typedArray];
var ta = new TA(8);
t.equal(isDataView(ta), false, inspect(ta) + ' is not a DataView');
});
t.end();
});
test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
forEach(availableTypedArrays, function (typedArray) {
// @ts-expect-error
var fakeTypedArray = [];
// @ts-expect-error
fakeTypedArray[Symbol.toStringTag] = typedArray;
// @ts-expect-error
t.notOk(isDataView(fakeTypedArray), 'faked ' + typedArray + ' is not typed array');
});
t.end();
});
test('Data Views', { skip: typeof DataView !== 'function' }, function (t) {
var ab = new ArrayBuffer(1);
var dv = new DataView(ab);
t.equal(isDataView(dv), true, inspect(dv) + ' is a DataView');
t.end();
});
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2021",
},
"exclude": [
"coverage",
],
}