diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/README.md b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md new file mode 100644 index 000000000000..d08f380037a5 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md @@ -0,0 +1,130 @@ + + +# ToStringTagSymbol + +> To string tag [symbol][mdn-symbol-tostringtag] which is used to customize the string description of an object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); +``` + +#### ToStringTagSymbol + +To string tag [`symbol`][mdn-symbol-tostringtag] which is used to customize the string description of an object. + +```javascript +var s = typeof ToStringTagSymbol; +// e.g., returns 'symbol' +``` + +
+ + + + + +
+ +## Notes + +- The [symbol][mdn-symbol] is only supported in environments which support [symbols][mdn-symbol]. In non-supporting environments, the value is `null`. +- The `Object.prototype.toString` method uses the `Symbol.toStringTag` property, if present, as the tag in the string representation. For example, an object with `obj[Symbol.toStringTag] = 'Custom'` will return `'[object Custom]'` when `Object.prototype.toString.call(obj)` is invoked. + +
+ + + + + +
+ +## Examples + + + +```javascript +var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); + +function valueOfCustom() { + return 'custom'; +} + +var obj = {}; +obj.valueOf = valueOfCustom; + +obj[ ToStringTagSymbol ] = 'Custom'; + +console.log( Object.prototype.toString.call( obj ) ); +// => '[object Custom]' + +var arr = []; +console.log( Object.prototype.toString.call( arr ) ); +// => '[object Array]' + +arr[ ToStringTagSymbol ] = 'MyArray'; +console.log( Object.prototype.toString.call( arr ) ); +// => '[object MyArray]' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/docs/repl.txt b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/repl.txt new file mode 100644 index 000000000000..0176e3b11ec8 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/repl.txt @@ -0,0 +1,18 @@ + +{{alias}} + To string tag. + + This symbol is used to determine whether a constructor object recognizes an + object as its instance. + + The symbol is only supported in ES6/ES2015+ environments. For non-supporting + environments, the value is `null`. + + Examples + -------- + > var s = {{alias}} + e.g., + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/index.d.ts b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/index.d.ts new file mode 100644 index 000000000000..d8b64d2da1cf --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/index.d.ts @@ -0,0 +1,31 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +// EXPORTS // + +/** +* Has instance symbol. +* +* ## Notes +* +* - This symbol is used to determine whether a constructor object recognizes an object as its instance. +* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`. +*/ +export = Symbol.toStringTag; diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/test.ts b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/test.ts new file mode 100644 index 000000000000..17890f6f7a3f --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/test.ts @@ -0,0 +1,29 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import ToStringTag = require( './index' ); + + +// TESTS // + +// The exported value is the `toStringTag` symbol... +{ + ToStringTag; +} diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/examples/index.js b/lib/node_modules/@stdlib/symbol/to-string-tag/examples/index.js new file mode 100644 index 000000000000..3453892fd398 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/examples/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var isArray = require( '@stdlib/assert/is-array' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var defineProperty = require( '@stdlib/utils/define-property' ); +var ToStringTagSymbol = require( './../lib' ); + +function ArrayLike() { + return { + 'length': 3, + '0': 4, + '1': 5, + '2': 6 + }; +} + +function toStringTag( instance ) { + return isArray( instance ); +} + +var x = [ 1, 2, 3 ]; + +defineProperty( ArrayLike, ToStringTagSymbol, { + 'configurable': true, + 'value': null +}); +console.log( instanceOf( x, ArrayLike ) ); + +defineProperty( ArrayLike, ToStringTagSymbol, { + 'configurable': true, + 'value': toStringTag +}); +console.log( instanceOf( x, ArrayLike ) ); diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/lib/index.js b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/index.js new file mode 100644 index 000000000000..b490accbe9de --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Symbol used to determine if a constructor object recognizes an object as its instance. +* +* @module @stdlib/symbol/to-string-tag +* +* @example +* var isArray = require( '@stdlib/assert/is-array' ); +* var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); +* +* function ArrayLike() { +* return { +* 'length': 3, +* '0': 1, +* '1': 2, +* '2': 3 +* }; +* }; +* +* ArrayLike[ ToStringTagSymbol ] = isArray; +*/ + +// MAIN // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/lib/main.js b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/main.js new file mode 100644 index 000000000000..f7fcbc42bbe4 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/main.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasToStringTagSymbolSupport = require( '@stdlib/assert/has-tostringtag-support' ); // eslint-disable-line id-length + + +// MAIN // + +/** +* Has instance symbol. +* +* @name ToStringTagSymbol +* @constant +* @type {(symbol|null)} +* +* @example +* var isArray = require( '@stdlib/assert/is-array' ); +* +* function ArrayLike() { +* return { +* 'length': 3, +* '0': 1, +* '1': 2, +* '2': 3 +* }; +* }; +* +* ArrayLike[ ToStringTagSymbol ] = isArray; +*/ +var ToStringTagSymbol = ( hasToStringTagSymbolSupport() ) ? Symbol.toStringTag : null; // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = ToStringTagSymbol; diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/package.json b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json new file mode 100644 index 000000000000..9e0f7b00b44c --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json @@ -0,0 +1,58 @@ +{ + "name": "@stdlib/symbol/to-string-tag", + "version": "0.0.0", + "description": "Has `Symbol.toStringTag` symbol.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "symbol", + "sym", + "to-string-tag", + "tostringtag", + "tag" + ] +} diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/test/test.js b/lib/node_modules/@stdlib/symbol/to-string-tag/test/test.js new file mode 100644 index 000000000000..85fe06c2b99e --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/test/test.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasToStringTagSymbolSupport = require( '@stdlib/assert/has-tostringtag-support' ); // eslint-disable-line id-length +var isSymbol = require( '@stdlib/assert/is-symbol' ); +var Sym = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasToStringTagSymbolSupport() +}; + + +// TESTS // + +tape( 'main export is a symbol in supporting environments (ES6/2015+) or otherwise null', function test( t ) { + t.ok( true, __filename ); + if ( opts.skip ) { + t.strictEqual( Sym, null, 'main export is null' ); + } else { + t.strictEqual( typeof Sym, 'symbol', 'main export is a symbol' ); + t.strictEqual( isSymbol( Sym ), true, 'main export is a symbol' ); + } + t.end(); +}); + +tape( 'the main export is an alias for `Symbol.toStringTag`', opts, function test( t ) { + t.strictEqual( Sym, Symbol.toStringTag, 'returns expected value' ); + t.end(); +});