Skip to content

Commit

Permalink
[New] add types
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 13, 2024

Verified

This commit was signed with the committer’s verified signature.
dplocki Dawid Płocki
1 parent 574ee8e commit 42e29a8
Showing 6 changed files with 40 additions and 6 deletions.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import whichTypedArray from 'which-typed-array';

declare namespace hasTypedArrays {
type TypedArrayName = whichTypedArray.TypedArrayName;
}

declare function hasTypedArrays(): boolean;

export = hasTypedArrays;
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
var some = require('array.prototype.some');
var whichTypedArray = require('which-typed-array');

/** @type {import('.').TypedArrayName[]} */
var typedArrays = [
'Float32Array',
'Float64Array',
@@ -18,7 +19,7 @@ var typedArrays = [
];

module.exports = function hasTypedArrays() {
return some(typedArrays, function (TA) {
return whichTypedArray(new global[TA]());
return some(typedArrays, /** @param {import('.').TypedArrayName} TA */ function (TA) {
return !!whichTypedArray(new global[TA]());
});
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test:harmony": "nyc node --harmony --es-staging test",
@@ -48,15 +49,19 @@
},
"homepage": "https://github.com/inspect-js/has-typed-arrays#readme",
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/tape": "^5.6.5",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0"
"tape": "^5.9.0",
"typescript": "next"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
@@ -75,7 +80,8 @@
},
"publishConfig": {
"ignore": [
".github/workflows"
".github/workflows",
"types"
]
}
}
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ test('export', function (t) {
});

test('Typed Arrays', function (t) {
var anyExist = some([
var anyExist = some(/** @type {import('..').TypedArrayName[]} */ [
'Float32Array',
'Float64Array',
'Int8Array',
@@ -23,7 +23,7 @@ test('Typed Arrays', function (t) {
'Uint32Array',
'BigInt64Array',
'BigUint64Array'
], function (TA) {
], /** @param {import('..').TypedArrayName} TA */ function (TA) {
return typeof global[TA] === 'function';
});

9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"maxNodeModuleJsDepth": 0,
},
"exclude": [
"coverage"
]
}
9 changes: 9 additions & 0 deletions types/array.prototype.some/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module 'array.prototype.some' {
function some<T>(
arr: T[],
callbackfn: (value: T, index?: number, array?: T[]) => boolean,
thisArg?: unknown,
): boolean;

export = some;
}

0 comments on commit 42e29a8

Please sign in to comment.