pax_global_header 0000666 0000000 0000000 00000000064 14726762417 0014532 g ustar 00root root 0000000 0000000 52 comment=fccdad16413f7a2f2eae328f304d0044edb9a11b
inspect-js-which-builtin-type-ff871de/ 0000775 0000000 0000000 00000000000 14726762417 0020042 5 ustar 00root root 0000000 0000000 inspect-js-which-builtin-type-ff871de/.eslintrc 0000664 0000000 0000000 00000000321 14726762417 0021662 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"complexity": 0,
"eqeqeq": [2, "allow-null"],
"func-name-matching": 0,
"id-length": 0,
"max-lines-per-function": 0,
"max-statements": 0,
},
}
inspect-js-which-builtin-type-ff871de/.github/ 0000775 0000000 0000000 00000000000 14726762417 0021402 5 ustar 00root root 0000000 0000000 inspect-js-which-builtin-type-ff871de/.github/workflows/ 0000775 0000000 0000000 00000000000 14726762417 0023437 5 ustar 00root root 0000000 0000000 inspect-js-which-builtin-type-ff871de/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000516 14726762417 0026217 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
node:
name: 'node < 10'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
inspect-js-which-builtin-type-ff871de/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 14726762417 0026571 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
inspect-js-which-builtin-type-ff871de/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000547 14726762417 0026064 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js 10 - 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10 < 20'
type: minors
command: npm run tests-only
node:
name: 'node 10 - 20'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
inspect-js-which-builtin-type-ff871de/.github/workflows/node-twenties.yml 0000664 0000000 0000000 00000000536 14726762417 0026753 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 20'
type: minors
command: npm run tests-only
node:
name: 'node >= 20'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
inspect-js-which-builtin-type-ff871de/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14726762417 0025427 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
inspect-js-which-builtin-type-ff871de/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14726762417 0030054 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
inspect-js-which-builtin-type-ff871de/.gitignore 0000664 0000000 0000000 00000003251 14726762417 0022033 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
inspect-js-which-builtin-type-ff871de/.npmrc 0000664 0000000 0000000 00000000067 14726762417 0021165 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
inspect-js-which-builtin-type-ff871de/.nycrc 0000664 0000000 0000000 00000000213 14726762417 0021155 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
inspect-js-which-builtin-type-ff871de/CHANGELOG.md 0000664 0000000 0000000 00000026404 14726762417 0021661 0 ustar 00root root 0000000 0000000 # 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.2.1](https://github.com/inspect-js/which-builtin-type/compare/v1.2.0...v1.2.1) - 2024-12-12
### Commits
- [meta] sort package.json [`8305bf9`](https://github.com/inspect-js/which-builtin-type/commit/8305bf9a47674564c84dde5856829444ac59e379)
- [actions] re-add finishers [`67140db`](https://github.com/inspect-js/which-builtin-type/commit/67140dba99e8f204c6f1abce315711fae4239032)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/tsconfig`, `@types/function.prototype.name`, `@types/tape`, `has-symbols` [`5adff02`](https://github.com/inspect-js/which-builtin-type/commit/5adff02870f00eafe144250b0ea2181f59b0d337)
- [Deps] update `call-bind`, `is-date-object`, `is-regex`, `which-boxed-primitive` [`87922d3`](https://github.com/inspect-js/which-builtin-type/commit/87922d3a0a21ee2b0991d9f3832123f5ff149eed)
- [Refactor] use `call-bound` directly [`8f633bc`](https://github.com/inspect-js/which-builtin-type/commit/8f633bc7587f481877f3965fdf0c74885753d824)
- [Deps] update `is-regex`, `which-typed-array` [`a912742`](https://github.com/inspect-js/which-builtin-type/commit/a9127421b702943a57927bf3e4d867cdc5862419)
## [v1.2.0](https://github.com/inspect-js/which-builtin-type/compare/v1.1.4...v1.2.0) - 2024-11-23
### Commits
- [New] add types [`d4aa2db`](https://github.com/inspect-js/which-builtin-type/commit/d4aa2db289a8d97c6917c0edb1edcb32001488a8)
- [actions] split out node 10-20, and 20+ [`7b3d28b`](https://github.com/inspect-js/which-builtin-type/commit/7b3d28bcb1258cdfd5a7df5606622351596fb442)
- [Refactor] use `callBound` to cache Promise#then [`a000377`](https://github.com/inspect-js/which-builtin-type/commit/a0003772dabdd5fd4b84c2ed8e139df008a437e8)
- [Dev Deps] update `auto-changelog`, `object-inspect`, `tape` [`37062d2`](https://github.com/inspect-js/which-builtin-type/commit/37062d280a8c36c1bd96b6cfbe053f10cf8d71b6)
- [Tests] replace `aud` with `npm audit` [`337aac1`](https://github.com/inspect-js/which-builtin-type/commit/337aac1d88fc63d935bd15a97926e9b0b462a735)
- [Deps] update `is-finalizationregistry` [`4ef8763`](https://github.com/inspect-js/which-builtin-type/commit/4ef8763a19709df7ad50d790bd2b724f531a65d9)
- [Dev Deps] add missing peer dep [`1cb2842`](https://github.com/inspect-js/which-builtin-type/commit/1cb28421438eb4ee8f0f284b535f1cfc6b9c9757)
## [v1.1.4](https://github.com/inspect-js/which-builtin-type/compare/v1.1.3...v1.1.4) - 2024-07-29
### Commits
- [readme] fix URLs [`f26fc22`](https://github.com/inspect-js/which-builtin-type/commit/f26fc2243220277874e36ace85f48f87ec8ab502)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `available-typed-arrays`, `npmignore`, `object-inspect`, `object.assign`, `tape` [`f724135`](https://github.com/inspect-js/which-builtin-type/commit/f724135d44efd74ee067102c8c499566d73b849c)
- [Deps] update `function.prototype.name`, `has-tostringtag`, `which-collection`, `which-typed-array` [`831119b`](https://github.com/inspect-js/which-builtin-type/commit/831119b76ce79004c368deab141e8a9bd680950c)
## [v1.1.3](https://github.com/inspect-js/which-builtin-type/compare/v1.1.2...v1.1.3) - 2022-11-02
### Commits
- [meta] use `npmignore` to autogenerate an npmignore file [`0ccf168`](https://github.com/inspect-js/which-builtin-type/commit/0ccf168604ddaab1d40de8fde5140f5dca942c5b)
- [Dev Deps] update `aud`, `has-bigints`, `has-symbols`, `in-publish`, `object-inspect`, `object.assign`, `tape` [`2c87b2e`](https://github.com/inspect-js/which-builtin-type/commit/2c87b2ed58c397a26953dbe2cb2aae452e32ee21)
- [actions] update rebase action to use reusable workflow [`ab27caf`](https://github.com/inspect-js/which-builtin-type/commit/ab27caf0d6cd1fccc5738fda4cebee7bf47eca14)
- [meta] simplify `exports` [`680d056`](https://github.com/inspect-js/which-builtin-type/commit/680d05674f979c1a02ae7c6b9f885114e962324e)
- [Deps] update `which-typed-array` [`3ca0216`](https://github.com/inspect-js/which-builtin-type/commit/3ca02166585c6e7350fe0bc7518fccce269fc5ac)
- [meta] add `sideEffects` flag [`caa2221`](https://github.com/inspect-js/which-builtin-type/commit/caa22214c751674f1959944a0ece81b032141e3b)
## [v1.1.2](https://github.com/inspect-js/which-builtin-type/compare/v1.1.1...v1.1.2) - 2022-04-12
### Commits
- [actions] reuse common workflows [`b1b60aa`](https://github.com/inspect-js/which-builtin-type/commit/b1b60aa01b20f613a97b456c3062412f0aba67dd)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `safe-publish-latest`, `tape` [`8115a20`](https://github.com/inspect-js/which-builtin-type/commit/8115a20941ca702c1a927a0aea08ffa0b37821c0)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`86b3c3b`](https://github.com/inspect-js/which-builtin-type/commit/86b3c3ba155a2a292a69d507be85ede12896163d)
- [actions] update codecov uploader [`de30f4b`](https://github.com/inspect-js/which-builtin-type/commit/de30f4bdd613b36a11270085974013c1e0025b74)
- [Deps] update `function.prototype.name`, `is-finalizationregistry`, `which-typed-array` [`0ba20f5`](https://github.com/inspect-js/which-builtin-type/commit/0ba20f53824455b2fcdd90027a64bc34f09bec6b)
- [Refactor] use `is-async-function` [`6f36d89`](https://github.com/inspect-js/which-builtin-type/commit/6f36d8942a158cc41f486ba9e29d08f75a6d1406)
- [Deps] update `is-weakref` [`d775476`](https://github.com/inspect-js/which-builtin-type/commit/d775476f5f0dccab56b13c839ce6ada377b67ca0)
## [v1.1.1](https://github.com/inspect-js/which-builtin-type/compare/v1.1.0...v1.1.1) - 2021-08-06
### Commits
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `available-typed-arrays`, `object-inspect`, `tape` [`8adae7d`](https://github.com/inspect-js/which-builtin-type/commit/8adae7d7ba4a49309f87e990d9787589f8c978a1)
- [Deps] update `is-date-object`, `is-generator-function`, `is-regex`, `which-typed-array` [`805b158`](https://github.com/inspect-js/which-builtin-type/commit/805b158f86d258983868b45ceb4a3a9417fed08e)
- [Refactor] use `has-tostringtag` to behave correctly in the presence of symbol shams [`9ec250a`](https://github.com/inspect-js/which-builtin-type/commit/9ec250a652c6607053d63c3e662547cf36c8cb9b)
- [readme] add github actions/codecov badges [`75b51b4`](https://github.com/inspect-js/which-builtin-type/commit/75b51b4c96280a05014c97efba6b8291b18af5cb)
## [v1.1.0](https://github.com/inspect-js/which-builtin-type/compare/v1.0.1...v1.1.0) - 2021-04-18
### Commits
- [Fix] prevent constructor or Symbol.toStringTag from lying about builtins [`7638412`](https://github.com/inspect-js/which-builtin-type/commit/7638412d9b6cca9af3999b4bf45d3a630f84409e)
- [actions] use `node/install` instead of `node/run`; use `codecov` action [`6a06770`](https://github.com/inspect-js/which-builtin-type/commit/6a06770548aec6948ab0aaa28babc0423f0fe745)
- [New] recognize Promise [`0d79e3a`](https://github.com/inspect-js/which-builtin-type/commit/0d79e3a0916438e1c808f83d8928af29914de08a)
- [New] recognize WeakRef and FinalizationRegistry [`020de6a`](https://github.com/inspect-js/which-builtin-type/commit/020de6a84242e12a5cd956b74f4457a8d3cba6fb)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `has-symbols`, `object-inspect`, `tape` [`71e47f5`](https://github.com/inspect-js/which-builtin-type/commit/71e47f50c534e2e37ba654bdc2851f9fb8b9f435)
- [Deps] update `function.prototype.name`, `is-regex` [`f2d56b9`](https://github.com/inspect-js/which-builtin-type/commit/f2d56b9ba12962f6432d869e14a73c43b0bfaeb0)
- [meta] use `prepublishOnly` script for npm 7+ [`daae0a0`](https://github.com/inspect-js/which-builtin-type/commit/daae0a018594cef507a0d5bc3304ec950db15925)
- [Tests] increase coverage [`bd406f2`](https://github.com/inspect-js/which-builtin-type/commit/bd406f212ac79af48c0ca11fb36c770fe106bf5f)
## [v1.0.1](https://github.com/inspect-js/which-builtin-type/compare/v1.0.0...v1.0.1) - 2020-12-14
### Commits
- [Tests] migrate tests to Github Actions [`165a1b5`](https://github.com/inspect-js/which-builtin-type/commit/165a1b5924c242db86749e9691bb310fce3e2b05)
- [meta] do not publish github action workflow files [`851f508`](https://github.com/inspect-js/which-builtin-type/commit/851f508ad644248621ca2d465ba440913e865d4e)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `has-bigints`, `object-inspect`, `object.assign`, `tape` [`5b0906c`](https://github.com/inspect-js/which-builtin-type/commit/5b0906cf115aa7b77073262a3fb34134c214c444)
- [Tests] run `nyc` on all tests; use `tape` runner [`85924cd`](https://github.com/inspect-js/which-builtin-type/commit/85924cd70d665f79fd8f1a439706412d7e8e6455)
- [readme] fix repo URLs, remove defunct badges [`8fb4bb5`](https://github.com/inspect-js/which-builtin-type/commit/8fb4bb51219e956916583ba9a34a9a2d0228716e)
- [Dev Deps] update `@ljharb/eslint-config`, `available-typed-arrays`, `make-arrow-function`, `make-generator-function` [`9d65291`](https://github.com/inspect-js/which-builtin-type/commit/9d652910fc84589669f9bfe7accc0272df911a0f)
- [Deps] update `function.prototype.name`, `is-generator-function`, `is-regex`, `which-boxed-primitive`, `which-collection`, `which-typed-array` [`7900c10`](https://github.com/inspect-js/which-builtin-type/commit/7900c10e8113fb9b087103f313bda71f4204a935)
- [actions] add "Allow Edits" workflow [`f9f04f5`](https://github.com/inspect-js/which-builtin-type/commit/f9f04f5999f564b921b9678792a3db8ad4268709)
- [actions] switch Automatic Rebase workflow to `pull_request_target` event [`4452dee`](https://github.com/inspect-js/which-builtin-type/commit/4452dee4fe2bc3cdb29470f25a184031b1c267ee)
## v1.0.0 - 2020-01-24
### Commits
- Tests [`d65924f`](https://github.com/inspect-js/which-builtin-type/commit/d65924fea79cd13609d3155b018f9db12f995b71)
- Initial commit [`a6208ff`](https://github.com/inspect-js/which-builtin-type/commit/a6208ff57dfbf9b6368adc5a22ca5d2db2c123e5)
- Implementation [`0d1c341`](https://github.com/inspect-js/which-builtin-type/commit/0d1c341b71de6b475db6f8cb430cace4be54c93b)
- readme [`23ecfb6`](https://github.com/inspect-js/which-builtin-type/commit/23ecfb6b5c5e30cbae73148f3d01adbb6229d064)
- npm init [`cce1b17`](https://github.com/inspect-js/which-builtin-type/commit/cce1b17caa4d56bae6980d898e8ad223da073fcc)
- [meta] add `auto-changelog` [`f903f62`](https://github.com/inspect-js/which-builtin-type/commit/f903f629cf70d725a2d0c1fd0e76112c39b88b70)
- [actions] add automatic rebasing / merge commit blocking [`71f9295`](https://github.com/inspect-js/which-builtin-type/commit/71f92950bdbcd1eb79d8ce8c3b7584bd4db45733)
- [Tests] use shared travis-ci configs [`2d7a1f4`](https://github.com/inspect-js/which-builtin-type/commit/2d7a1f4105de53def9b1652e53e900debb2a99a5)
- [Tests] add `npm run lint` [`a6372e2`](https://github.com/inspect-js/which-builtin-type/commit/a6372e203dbdb4ad42da15af7927cd21e0f94618)
- Only apps should have lockfiles [`d6bd083`](https://github.com/inspect-js/which-builtin-type/commit/d6bd083310cd713e6e1e3f16fcd35277194663e7)
- [meta] add `funding` field [`377f67a`](https://github.com/inspect-js/which-builtin-type/commit/377f67a24bef750dca957c8ccde62c3e8af6932b)
- [meta] add `safe-publish-latest` [`99295e9`](https://github.com/inspect-js/which-builtin-type/commit/99295e921f5cb898a62081b6719c30cf537f58f9)
inspect-js-which-builtin-type-ff871de/LICENSE 0000664 0000000 0000000 00000002061 14726762417 0021046 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2020 ECMAScript Shims
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
inspect-js-which-builtin-type-ff871de/README.md 0000664 0000000 0000000 00000006663 14726762417 0021334 0 ustar 00root root 0000000 0000000 # which-builtin-type [![Version Badge][npm-version-svg]][package-url]
[![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]
What is the type of this builtin JavaScript value? Works cross-realm, without `instanceof`, and can not be fooled by a `constructor` property.
## Example
```js
var whichBuiltinType = require('which-builtin-type');
var assert = require('assert');
assert.equal(undefined, whichBuiltinType(undefined));
assert.equal(null, whichBuiltinType(null));
assert.equal('Boolean', whichBuiltinType(false));
assert.equal('Boolean', whichBuiltinType(true));
assert.equal('Array', whichBuiltinType([]));
assert.equal('Object', whichBuiltinType({}));
assert.equal('RegExp', whichBuiltinType(/a/g));
assert.equal('RegExp', whichBuiltinType(new RegExp('a', 'g')));
assert.equal('Date', whichBuiltinType(new Date()));
assert.equal('Number', whichBuiltinType(42));
assert.equal('Number', whichBuiltinType(NaN));
assert.equal('Number', whichBuiltinType(Infinity));
assert.equal('Number', whichBuiltinType(new Number(42)));
assert.equal('String', whichBuiltinType('foo'));
assert.equal('String', whichBuiltinType(Object('foo')));
assert.equal('Function', whichBuiltinType(function () {}));
assert.equal('GeneratorFunction', whichBuiltinType(function* () {}));
assert.equal('Function', whichBuiltinType(x => x * x));
assert.equal('Array', whichBuiltinType([]));
assert.equal('Int8Array', whichBuiltinType(new Int8Array()));
assert.equal('Uint8Array', whichBuiltinType(new Uint8Array()));
assert.equal('Uint8ClampedArray', whichBuiltinType(new Uint8ClampedArray()));
assert.equal('Int16Array', whichBuiltinType(new Int16Array()));
assert.equal('Uint16Array', whichBuiltinType(new Uint16Array()));
assert.equal('Int32Array', whichBuiltinType(new Int32Array()));
assert.equal('Uint32Array', whichBuiltinType(new Uint32Array()));
assert.equal('Float32Array', whichBuiltinType(new Float32Array()));
assert.equal('Float64Array', whichBuiltinType(new Float64Array()));
assert.equal('BigInt64Array', whichBuiltinType(new BigInt64Array()));
assert.equal('BigUint64Array', whichBuiltinType(new BigUint64Array()));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/which-builtin-type
[npm-version-svg]: https://versionbadg.es/inspect-js/which-builtin-type.svg
[deps-svg]: https://david-dm.org/inspect-js/which-builtin-type.svg
[deps-url]: https://david-dm.org/inspect-js/which-builtin-type
[dev-deps-svg]: https://david-dm.org/inspect-js/which-builtin-type/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/which-builtin-type#info=devDependencies
[npm-badge-png]: https://which-builtin-type/which-builtin-type.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/which-builtin-type.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/which-builtin-type.svg
[downloads-url]: https://npm-stat.com/charts.html?package=which-builtin-type
[codecov-image]: https://codecov.io/gh/inspect-js/which-builtin-type/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/which-builtin-type/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/which-builtin-type
[actions-url]: https://github.com/inspect-js/which-builtin-type/actions
inspect-js-which-builtin-type-ff871de/index.d.ts 0000664 0000000 0000000 00000002441 14726762417 0021744 0 ustar 00root root 0000000 0000000 import whichBoxedPrimitive from 'which-boxed-primitive';
import whichCollection from 'which-collection';
import whichTypedArray from 'which-typed-array';
type AsyncFunction = (...args: unknown[]) => Promise;
declare function whichBuiltinType(value: Parameters[0]): ReturnType;
declare function whichBuiltinType(value: Parameters[0]): ReturnType;
declare function whichBuiltinType(value: ReadonlyArray): 'Array';
declare function whichBuiltinType(value: Date): 'Date';
declare function whichBuiltinType(value: RegExp): 'RegExp';
declare function whichBuiltinType(value: T extends object ? WeakRef : never): 'WeakRef';
declare function whichBuiltinType(value: FinalizationRegistry): 'FinalizationRegistry';
declare function whichBuiltinType(value: GeneratorFunction): 'GeneratorFunction';
declare function whichBuiltinType(value: AsyncFunction): 'AsyncFunction';
declare function whichBuiltinType(value: Function): 'Function';
declare function whichBuiltinType(value: Promise): 'Promise';
declare function whichBuiltinType(value: T): 'Object' | Exclude, null | undefined> | string;
export = whichBuiltinType;
inspect-js-which-builtin-type-ff871de/index.js 0000664 0000000 0000000 00000007560 14726762417 0021517 0 ustar 00root root 0000000 0000000 'use strict';
var whichBoxedPrimitive = require('which-boxed-primitive');
var whichCollection = require('which-collection');
var whichTypedArray = require('which-typed-array');
var isArray = require('isarray');
var isDate = require('is-date-object');
var isRegex = require('is-regex');
var isWeakRef = require('is-weakref');
var isFinalizationRegistry = require('is-finalizationregistry');
var name = require('function.prototype.name');
var isGeneratorFunction = require('is-generator-function');
var isAsyncFunction = require('is-async-function');
var callBound = require('call-bound');
var hasToStringTag = require('has-tostringtag/shams')();
var toStringTag = hasToStringTag && Symbol.toStringTag;
var $Object = Object;
/** @type {undefined | ((value: ThisParameterType, ...args: Parameters) => ReturnType)} */
var promiseThen = callBound('Promise.prototype.then', true);
/** @type {(value: unknown) => value is Promise} */
var isPromise = function isPromise(value) {
if (!value || typeof value !== 'object' || !promiseThen) {
return false;
}
try {
promiseThen(value, null, function () {});
return true;
} catch (e) {}
return false;
};
/** @type {(builtinName: unknown) => boolean} */
var isKnownBuiltin = function isKnownBuiltin(builtinName) {
return !!builtinName
// primitives
&& builtinName !== 'BigInt'
&& builtinName !== 'Boolean'
&& builtinName !== 'Null'
&& builtinName !== 'Number'
&& builtinName !== 'String'
&& builtinName !== 'Symbol'
&& builtinName !== 'Undefined'
// namespaces
&& builtinName !== 'Math'
&& builtinName !== 'JSON'
&& builtinName !== 'Reflect'
&& builtinName !== 'Atomics'
// collections
&& builtinName !== 'Map'
&& builtinName !== 'Set'
&& builtinName !== 'WeakMap'
&& builtinName !== 'WeakSet'
// typed arrays
&& builtinName !== 'BigInt64Array'
&& builtinName !== 'BigUint64Array'
&& builtinName !== 'Float32Array'
&& builtinName !== 'Float64Array'
&& builtinName !== 'Int16Array'
&& builtinName !== 'Int32Array'
&& builtinName !== 'Int8Array'
&& builtinName !== 'Uint16Array'
&& builtinName !== 'Uint32Array'
&& builtinName !== 'Uint8Array'
&& builtinName !== 'Uint8ClampedArray'
// checked explicitly
&& builtinName !== 'Array'
&& builtinName !== 'Date'
&& builtinName !== 'FinalizationRegistry'
&& builtinName !== 'Promise'
&& builtinName !== 'RegExp'
&& builtinName !== 'WeakRef'
// functions
&& builtinName !== 'Function'
&& builtinName !== 'GeneratorFunction'
&& builtinName !== 'AsyncFunction';
};
/** @type {import('.')} */
module.exports = function whichBuiltinType(value) {
if (value == null) {
return value;
}
// covers: primitives, {,Weak}Map/Set, typed arrays
var which = whichBoxedPrimitive($Object(value)) || whichCollection(value) || whichTypedArray(value);
if (which) {
return which;
}
if (isArray(value)) {
return 'Array';
}
if (isDate(value)) {
return 'Date';
}
if (isRegex(value)) {
return 'RegExp';
}
if (isWeakRef(value)) {
return 'WeakRef';
}
if (isFinalizationRegistry(value)) {
return 'FinalizationRegistry';
}
if (typeof value === 'function') {
if (isGeneratorFunction(value)) {
return 'GeneratorFunction';
}
if (isAsyncFunction(value)) {
return 'AsyncFunction';
}
return 'Function';
}
if (isPromise(value)) {
return 'Promise';
}
// @ts-expect-error TS can't figure out that `value` is an `object` after the `which` check above
if (toStringTag && toStringTag in value) {
var tag = value[toStringTag];
if (isKnownBuiltin(tag)) {
return tag;
}
}
if (typeof value.constructor === 'function') {
// eslint-disable-next-line no-extra-parens
var constructorName = name(/** @type {Parameters[0]} */ (value.constructor));
if (isKnownBuiltin(constructorName)) {
return constructorName;
}
}
return 'Object';
};
inspect-js-which-builtin-type-ff871de/package.json 0000664 0000000 0000000 00000006227 14726762417 0022337 0 ustar 00root root 0000000 0000000 {
"name": "which-builtin-type",
"version": "1.2.1",
"description": "What is the type of this builtin JS value?",
"main": "index.js",
"types": "index.d.ts",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"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)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/inspect-js/which-builtin-type.git"
},
"keywords": [
"type",
"builtin",
"ecmascript"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/which-builtin-type/issues"
},
"homepage": "https://github.com/inspect-js/which-builtin-type#readme",
"dependencies": {
"call-bound": "^1.0.2",
"function.prototype.name": "^1.1.6",
"has-tostringtag": "^1.0.2",
"is-async-function": "^2.0.0",
"is-date-object": "^1.1.0",
"is-finalizationregistry": "^1.1.0",
"is-generator-function": "^1.0.10",
"is-regex": "^1.2.1",
"is-weakref": "^1.0.2",
"isarray": "^2.0.5",
"which-boxed-primitive": "^1.1.0",
"which-collection": "^1.0.2",
"which-typed-array": "^1.1.16"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/for-each": "^0.3.3",
"@types/function.prototype.name": "^1.1.4",
"@types/is-async-function": "^2.0.3",
"@types/is-date-object": "^1.0.4",
"@types/is-generator-function": "^1.0.3",
"@types/is-weakref": "^1.0.0",
"@types/make-arrow-function": "^1.2.2",
"@types/make-async-function": "^1.0.2",
"@types/object-inspect": "^1.13.0",
"@types/object.assign": "^4.1.0",
"@types/tape": "^5.6.5",
"@types/which-boxed-primitive": "^1.0.3",
"auto-changelog": "^2.5.0",
"available-typed-arrays": "^1.0.7",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"has-bigints": "^1.0.2",
"has-symbols": "^1.1.0",
"in-publish": "^2.0.1",
"make-arrow-function": "^1.2.0",
"make-async-function": "^1.0.0",
"make-generator-function": "^2.0.0",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.3",
"object.assign": "^4.1.5",
"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"
]
}
}
inspect-js-which-builtin-type-ff871de/test/ 0000775 0000000 0000000 00000000000 14726762417 0021021 5 ustar 00root root 0000000 0000000 inspect-js-which-builtin-type-ff871de/test/index.js 0000664 0000000 0000000 00000011562 14726762417 0022473 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var inspect = require('object-inspect');
var assign = require('object.assign');
var forEach = require('for-each');
var arrows = require('make-arrow-function').list();
var generators = require('make-generator-function')();
var asyncs = require('make-async-function').list();
var hasSymbols = require('has-symbols')();
var hasToStringTag = require('has-tostringtag/shams')();
var hasBigInts = require('has-bigints')();
var availableTypedArrays = require('available-typed-arrays');
var which = require('../');
if (typeof process !== 'undefined') {
process.on('unhandledRejection', function () {});
}
test('nullish', function (t) {
t.equal(which(null), null, 'null is null');
t.equal(which(undefined), undefined, 'undefined is undefined');
// @ts-expect-error
t.equal(which(), undefined, 'absent is undefined');
t.end();
});
test('non-nullish', function (t) {
/** @constructor */
var F = function Foo() {};
var tests = {
Number: [
0,
-0,
42,
Infinity,
-Infinity,
NaN,
0.5
],
Boolean: [
true,
false
],
String: [
'',
'foo'
],
Date: [
new Date(),
new Date(NaN),
assign(new Date(), { constructor: Object })
],
RegExp: [
/(?:)/,
/a/g,
assign(/constructor/, { constructor: Object })
],
Array: [
[],
[42],
assign([], { constructor: Object })
],
Function: [
function () {},
function f() {},
assign(function constructor() {}, { constructor: Object })
].concat(arrows),
GeneratorFunction: generators,
AsyncFunction: asyncs,
// eslint-disable-next-line no-extra-parens
Object: /** @type {object[]} */ ([
{},
{ constructor: null },
Math
]),
Symbol: hasSymbols ? [
Symbol.iterator,
Symbol(),
Symbol('foo'),
Symbol['for'] ? Symbol['for']('bar') : Symbol('no "for" support') // eslint-disable-line no-restricted-properties
] : [],
BigInt: hasBigInts ? [
BigInt(0),
BigInt(42)
] : [],
Foo: [
new F()
],
Map: typeof Map === 'function' ? [
new Map(),
new Map([[1, 2], [3, 4]]),
assign(new Map(), { constructor: Object })
] : [],
WeakMap: typeof WeakMap === 'function' ? [
new WeakMap(),
assign(new WeakMap(), { constructor: Object })
] : [],
Set: typeof Set === 'function' ? [
new Set(),
new Set([1, 2, 3, 4]),
assign(new Set(), { constructor: Object })
] : [],
WeakSet: typeof WeakSet === 'function' ? [
new WeakSet(),
assign(new WeakSet(), { constructor: Object })
] : [],
WeakRef: typeof WeakRef === 'function' ? [
new WeakRef({}),
assign(new WeakRef({}), { constructor: Object })
] : [],
FinalizationRegistry: typeof FinalizationRegistry === 'function' ? [
new FinalizationRegistry(function () {}),
assign(new FinalizationRegistry(function () {}), { constructor: Object })
] : [],
Promise: typeof Promise === 'function' ? [
Promise.resolve(42),
Promise.reject(NaN),
new Promise(function () {})
] : []
};
forEach(availableTypedArrays(), function (TypedArray) {
// @ts-expect-error not sure how to infer this as being spreaded into the above object literal
tests[TypedArray] = [
new global[TypedArray](0),
new global[TypedArray](2)
];
});
forEach(tests, function (values, expected) {
forEach(values, function (value) {
t.equal(which(value), expected, inspect(value) + ' is ' + inspect(expected));
var obj = Object(value);
if (value !== obj) {
t.equal(which(obj), expected, inspect(obj) + ' is ' + inspect(expected));
}
if (
expected !== 'Object' // the fallback can't fall back
&& expected !== 'Foo' // not a builtin
) {
if (hasToStringTag) {
/** @type {{ [k in typeof Symbol.toStringTag]?: string }} */
var fakerTag = {};
fakerTag[Symbol.toStringTag] = expected;
t.equal(
which(fakerTag),
'Object',
inspect(fakerTag) + ' lies and claims it is a ' + expected + ', but instead it is Object'
);
}
/** @typedef {Exclude} GlobalKey */
var fakerConstructor = {
// eslint-disable-next-line no-extra-parens
constructor: global[/** @type {GlobalKey} */ (expected)] || tests[expected]
};
t.equal(
which(fakerConstructor),
'Object',
inspect(fakerConstructor) + ' lies and claims it is a ' + expected + ', but instead it is Object'
);
if (hasToStringTag) {
/** @type {{ constructor: Function } & { [k in typeof Symbol.toStringTag]?: string }} */
var fakerConstructorTag = {
// eslint-disable-next-line no-extra-parens
constructor: global[/** @type {GlobalKey} */ (expected)] || tests[expected]
};
fakerConstructorTag[Symbol.toStringTag] = expected;
t.equal(
which(fakerConstructorTag),
'Object',
inspect(fakerConstructorTag) + ' lies with a tag and claims it is a ' + expected + ', but instead it is Object'
);
}
}
});
});
t.end();
});
inspect-js-which-builtin-type-ff871de/tsconfig.json 0000664 0000000 0000000 00000000173 14726762417 0022552 0 ustar 00root root 0000000 0000000 {
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2021",
},
"exclude": [
"coverage"
]
}