Gathering detailed insights and metrics for @stdlib/utils-constructor-name
Gathering detailed insights and metrics for @stdlib/utils-constructor-name
Determine the name of a value's constructor.
npm install @stdlib/utils-constructor-name
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
92.4
Quality
82.3
Maintenance
100
Vulnerability
88
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
73,665,936
Last Day
84,776
Last Week
416,836
Last Month
1,903,188
Last Year
27,848,189
Apache-2.0 License
2 Stars
70 Commits
3 Watchers
5 Branches
11 Contributors
Updated on Feb 03, 2025
Minified
Minified + Gzipped
Latest Version
0.2.2
Package Id
@stdlib/utils-constructor-name@0.2.2
Unpacked Size
34.35 kB
Size
9.37 kB
File Count
11
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
-2.1%
84,776
Compared to previous day
Last Week
-6.3%
416,836
Compared to previous week
Last Month
46.7%
1,903,188
Compared to previous month
Last Year
-20%
27,848,189
Compared to previous year
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Determine the name of a value's constructor.
1npm install @stdlib/utils-constructor-name
1var constructorName = require( '@stdlib/utils-constructor-name' );
Returns the name of a value's constructor.
1var v = constructorName( 'a' ); 2// returns 'String' 3 4v = constructorName( 5 ); 5// returns 'Number' 6 7function Beep() { 8 return this; 9} 10v = constructorName( new Beep() ); 11// returns 'Beep'
description | value | constructor | notes |
---|---|---|---|
string | 'beep' | 'String' | |
number | 5 | 'Number' | |
NaN | NaN | 'Number' | |
infinity | +infinity /-infinity | 'Number' | |
boolean | true /false | 'Boolean' | |
null | null | 'Null' | |
undefined | undefined | 'Undefined' | |
array | ['beep', 5] | 'Array' | |
object | {'foo': 'bar'} | 'Object' | |
function | function (){} | 'Function' | |
symbol | Symbol() | 'Symbol' | ES2015 |
regexp | /./ | 'RegExp' | Android 4.1+ |
String | new String('beep') | 'String' | |
Number | new Number(5) | 'Number' | |
Boolean | new Boolean(false) | 'Boolean' | |
Object | new Object() | 'Object' | |
Array | new Array() | 'Array' | |
Int8Array | new Int8Array() | 'Int8Array' | |
Uint8Array | new Uint8Array() | 'Uint8Array' | |
Uint8ClampedArray | new Uint8ClampedArray() | 'Uint8ClampedArray' | |
Int16Array | new Int16Array() | 'Int16Array' | |
Uint16Array | new Uint16Array() | 'Uint16Array' | |
Int32Array | new Int32Array() | 'Int32Array' | |
Uint32Array | new Uint32Array() | 'Uint32Array' | |
Float32Array | new Float32Array() | 'Float32Array' | |
Float64Array | new Float64Array() | 'Float64Array' | |
ArrayBuffer | new ArrayBuffer() | 'ArrayBuffer' | |
Buffer | new Buffer() | 'Buffer' | Node.js |
Date | new Date() | 'Date' | |
RegExp | new RegExp('.') | 'RegExp' | Android 4.1+ |
Function | new Function('x', 'return x') | 'Function' | |
Map | new Map() | 'Map' | ES2015 |
WeakMap | new WeakMap() | 'WeakMap' | ES2015 |
Set | new Set() | 'Set' | ES2015 |
WeakSet | new WeakSet() | 'WeakSet' | ES2015 |
Error | new Error() | 'Error' | |
TypeError | new TypeError() | 'TypeError' | |
SyntaxError | new SyntaxError() | 'SyntaxError' | |
ReferenceError | new ReferenceError() | 'ReferenceError' | |
URIError | new URIError() | 'URIError' | |
RangeError | new RangeError() | 'RangeError' | |
EvalError | new EvalError() | 'EvalError' | |
Math | Math | 'Math' | |
JSON | JSON | 'JSON' | IE8+ |
arguments | (function(){return arguments;})() | 'Arguments' | IE9+ |
custom constructor | new Beep() | 'Beep' | |
anonymous constructor | new (function(){})() | '' |
If a value's constructor is an anonymous function
, the implementation returns an empty string
.
1var Beep = function () { 2 return this; 3}; 4 5var v = constructorName( new Beep() ); 6// returns ''
1var Float32Array = require( '@stdlib/array-float32' ); 2var Float64Array = require( '@stdlib/array-float64' ); 3var Int8Array = require( '@stdlib/array-int8' ); 4var Int16Array = require( '@stdlib/array-int16' ); 5var Int32Array = require( '@stdlib/array-int32' ); 6var Uint8Array = require( '@stdlib/array-uint8' ); 7var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); 8var Uint16Array = require( '@stdlib/array-uint16' ); 9var Uint32Array = require( '@stdlib/array-uint32' ); 10var ArrayBuffer = require( '@stdlib/array-buffer' ); 11var Buffer = require( '@stdlib/buffer-ctor' ); 12var Symbol = require( '@stdlib/symbol-ctor' ); 13var constructorName = require( '@stdlib/utils-constructor-name' ); 14 15function noop() { 16 // Do nothing... 17} 18 19var v = constructorName( 'a' ); 20// returns 'String' 21 22v = constructorName( 5 ); 23// returns 'Number' 24 25v = constructorName( NaN ); 26// returns 'Number' 27 28v = constructorName( null ); 29// returns 'Null' 30 31v = constructorName( void 0 ); 32// returns 'Undefined' 33 34v = constructorName( true ); 35// returns 'Boolean' 36 37v = constructorName( false ); 38// returns 'Boolean' 39 40v = constructorName( {} ); 41// returns 'Object' 42 43v = constructorName( [] ); 44// returns 'Array' 45 46v = constructorName( noop ); 47// returns 'Function' 48 49v = constructorName( /./ ); 50// returns 'RegExp' 51 52v = constructorName( new Date() ); 53// returns 'Date' 54 55v = constructorName( new Map() ); 56// returns 'Map' 57 58v = constructorName( new WeakMap() ); 59// returns 'WeakMap' 60 61v = constructorName( new Set() ); 62// returns 'Set' 63 64v = constructorName( new WeakSet() ); 65// returns 'WeakSet' 66 67v = constructorName( Symbol( 'beep' ) ); 68// returns 'Symbol' 69 70v = constructorName( new Error() ); 71// returns 'Error' 72 73v = constructorName( new TypeError() ); 74// returns 'TypeError' 75 76v = constructorName( new SyntaxError() ); 77// returns 'SyntaxError' 78 79v = constructorName( new URIError() ); 80// returns 'URIError' 81 82v = constructorName( new RangeError() ); 83// returns 'RangeError' 84 85v = constructorName( new ReferenceError() ); 86// returns 'ReferenceError' 87 88v = constructorName( new EvalError() ); 89// returns 'EvalError' 90 91v = constructorName( new Int8Array() ); 92// returns 'Int8Array' 93 94v = constructorName( new Uint8Array() ); 95// returns 'Uint8Array' 96 97v = constructorName( new Uint8ClampedArray() ); 98// returns 'Uint8ClampedArray' 99 100v = constructorName( new Int16Array() ); 101// returns 'Int16Array' 102 103v = constructorName( new Uint16Array() ); 104// returns 'Uint16Array' 105 106v = constructorName( new Int32Array() ); 107// returns 'Int32Array' 108 109v = constructorName( new Uint32Array() ); 110// returns 'Uint32Array' 111 112v = constructorName( new Float32Array() ); 113// returns 'Float32Array' 114 115v = constructorName( new Float64Array() ); 116// returns 'Float64Array' 117 118v = constructorName( new ArrayBuffer() ); 119// returns 'ArrayBuffer' 120 121v = constructorName( new Buffer( 'beep' ) ); 122// returns 'Buffer' 123 124v = constructorName( Math ); 125// returns 'Math' 126 127v = constructorName( JSON ); 128// returns 'JSON' 129 130function Person1() { 131 return this; 132} 133v = constructorName( new Person1() ); 134// returns 'Person1' 135 136var Person2 = function () { 137 return this; 138}; 139v = constructorName( new Person2() ); 140// returns ''
@stdlib/utils-function-name
: determine a function's name.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More