From 44f0dc786bbc8c11709e6e289a168f3ffab56ca2 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Mon, 10 Nov 2025 15:18:25 +0530 Subject: [PATCH 1/7] feat: add symbol/to-string-tag package --- .../@stdlib/symbol/to-string-tag/README.md | 146 ++++++++++++++++++ .../symbol/to-string-tag/docs/repl.txt | 18 +++ .../to-string-tag/docs/types/index.d.ts | 31 ++++ .../symbol/to-string-tag/docs/types/test.ts | 29 ++++ .../symbol/to-string-tag/examples/index.js | 51 ++++++ .../@stdlib/symbol/to-string-tag/lib/index.js | 49 ++++++ .../@stdlib/symbol/to-string-tag/lib/main.js | 54 +++++++ .../@stdlib/symbol/to-string-tag/package.json | 60 +++++++ .../@stdlib/symbol/to-string-tag/test/test.js | 52 +++++++ 9 files changed, 490 insertions(+) create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/README.md create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/examples/index.js create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/lib/index.js create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/lib/main.js create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/package.json create mode 100644 lib/node_modules/@stdlib/symbol/to-string-tag/test/test.js 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..39ed92ef9101 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md @@ -0,0 +1,146 @@ + + +# 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' ); + +var obj = { + 'valueOf': function set() { + return 'custom'; + } +}; + +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..b3f28ce344f5 --- /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-to-string-tag-symbol-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..27126cd49a36 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json @@ -0,0 +1,60 @@ +{ + "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", + "symbol", + "tag", + "stdlib" + ] +} 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..b3607c00c354 --- /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-to-string-tag-symbol-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(); +}); From 4015695820cbc8b4d01b400bbecf49e28da40823 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Mon, 10 Nov 2025 15:26:19 +0530 Subject: [PATCH 2/7] feat: add symbol/to-string-tag package --- .../@stdlib/symbol/to-string-tag/README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/README.md b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md index 39ed92ef9101..a6838c6530e8 100644 --- a/lib/node_modules/@stdlib/symbol/to-string-tag/README.md +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md @@ -4,22 +4,6 @@ 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 - ```javascript -var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); - -var obj = { - valueOf() { - return 'custom'; - } -}; - -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]' +var isArray = require( '@stdlib/assert/is-array' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var defineProperty = require( '@stdlib/utils/define-property' ); +var ToStringTag = require( '@stdlib/symbol/to-string-tag' ); + +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 ) ); ``` From 3feaf220dace922d7ba7d43be4ec64a0ab5a5910 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Mon, 10 Nov 2025 15:48:17 +0530 Subject: [PATCH 6/7] feat: add symbol/to-string-tag package --- .../@stdlib/symbol/to-string-tag/README.md | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/README.md b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md index 2e9243c5d0a7..d08f380037a5 100644 --- a/lib/node_modules/@stdlib/symbol/to-string-tag/README.md +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md @@ -75,37 +75,27 @@ var s = typeof ToStringTagSymbol; ```javascript -var isArray = require( '@stdlib/assert/is-array' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var ToStringTag = require( '@stdlib/symbol/to-string-tag' ); - -function ArrayLike() { - return { - 'length': 3, - '0': 4, - '1': 5, - '2': 6 - }; -} +var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); -function ToStringTag( instance ) { - return isArray( instance ); +function valueOfCustom() { + return 'custom'; } -var x = [ 1, 2, 3 ]; +var obj = {}; +obj.valueOf = valueOfCustom; + +obj[ ToStringTagSymbol ] = 'Custom'; + +console.log( Object.prototype.toString.call( obj ) ); +// => '[object Custom]' -defineProperty( ArrayLike, ToStringTagSymbol, { - 'configurable': true, - 'value': null -}); -console.log( instanceOf( x, ArrayLike ) ); +var arr = []; +console.log( Object.prototype.toString.call( arr ) ); +// => '[object Array]' -defineProperty( ArrayLike, ToStringTagSymbol, { - 'configurable': true, - 'value': ToStringTag -}); -console.log( instanceOf( x, ArrayLike ) ); +arr[ ToStringTagSymbol ] = 'MyArray'; +console.log( Object.prototype.toString.call( arr ) ); +// => '[object MyArray]' ``` From 49fda6966db739ae02004a6798692d5e96992827 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Mon, 10 Nov 2025 15:51:53 +0530 Subject: [PATCH 7/7] feat: add symbol/to-string-tag package --- lib/node_modules/@stdlib/symbol/to-string-tag/package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/symbol/to-string-tag/package.json b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json index 27126cd49a36..9e0f7b00b44c 100644 --- a/lib/node_modules/@stdlib/symbol/to-string-tag/package.json +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json @@ -52,9 +52,7 @@ "symbol", "sym", "to-string-tag", - "toStringTag", - "symbol", - "tag", - "stdlib" + "tostringtag", + "tag" ] }