From 75633a9f4244a5599aaffcf8ce7e85749b0dcee4 Mon Sep 17 00:00:00 2001 From: Yit E Date: Sat, 25 Jul 2026 01:33:16 -0700 Subject: [PATCH] feat: add `symbol/to-string-tag` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/symbol/docs/types/index.d.ts | 11 ++ lib/node_modules/@stdlib/symbol/lib/index.js | 9 ++ .../@stdlib/symbol/to-string-tag/README.md | 103 ++++++++++++++++++ .../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 | 32 ++++++ .../@stdlib/symbol/to-string-tag/lib/index.js | 40 +++++++ .../@stdlib/symbol/to-string-tag/lib/main.js | 46 ++++++++ .../@stdlib/symbol/to-string-tag/package.json | 59 ++++++++++ .../@stdlib/symbol/to-string-tag/test/test.js | 53 +++++++++ 11 files changed, 431 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/docs/types/index.d.ts b/lib/node_modules/@stdlib/symbol/docs/types/index.d.ts index 14c9a9e4e15f..52bb742d5290 100644 --- a/lib/node_modules/@stdlib/symbol/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/symbol/docs/types/index.d.ts @@ -27,6 +27,7 @@ import IsConcatSpreadableSymbol = require( '@stdlib/symbol/is-concat-spreadable' import IteratorSymbol = require( '@stdlib/symbol/iterator' ); import ReplaceSymbol = require( '@stdlib/symbol/replace' ); import ToPrimitiveSymbol = require( '@stdlib/symbol/to-primitive' ); +import ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); /** * Interface describing the `symbol` namespace. @@ -103,6 +104,16 @@ interface Namespace { * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`. */ ToPrimitiveSymbol: typeof ToPrimitiveSymbol; + + /** + * To string tag symbol. + * + * ## Notes + * + * - This symbol is used to customize the default string description of an object. + * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`. + */ + ToStringTagSymbol: typeof ToStringTagSymbol; } /** diff --git a/lib/node_modules/@stdlib/symbol/lib/index.js b/lib/node_modules/@stdlib/symbol/lib/index.js index 699064d0d783..8a835c81d8e0 100644 --- a/lib/node_modules/@stdlib/symbol/lib/index.js +++ b/lib/node_modules/@stdlib/symbol/lib/index.js @@ -99,6 +99,15 @@ setReadOnly( ns, 'ReplaceSymbol', require( '@stdlib/symbol/replace' ) ); */ setReadOnly( ns, 'ToPrimitiveSymbol', require( '@stdlib/symbol/to-primitive' ) ); +/** +* @name ToStringTagSymbol +* @memberof ns +* @readonly +* @type {(symbol|null)} +* @see {@link module:@stdlib/symbol/to-string-tag} +*/ +setReadOnly( ns, 'ToStringTagSymbol', require( '@stdlib/symbol/to-string-tag' ) ); + // EXPORTS // 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..f1281a3454ba --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/README.md @@ -0,0 +1,103 @@ + + +# ToStringTagSymbol + +> To string tag [symbol][mdn-symbol] which is used to customize the default string description of an object. + +
+ +
+ + + +
+ +## Usage + +```javascript +var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); +``` + +#### ToStringTagSymbol + +To string tag [`symbol`][mdn-symbol] which is used to customize the default 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`. +- When an object has a property keyed by `[ToStringTagSymbol]` whose value is a string, that string is used as the "tag" in the object's default string description; e.g., `Object.prototype.toString.call( obj )` returns `'[object ]'`. + +
+ + + +
+ +## Examples + + + +```javascript +var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); + +var obj = {}; + +obj[ ToStringTagSymbol ] = 'MyObject'; + +var str = Object.prototype.toString.call( obj ); +console.log( str ); +// => '[object MyObject]' +``` + +
+ + + +
+ +
+ + + + + + + + + + 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..b0fc7835d0fb --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/docs/repl.txt @@ -0,0 +1,18 @@ + +{{alias}} + To string tag symbol. + + This symbol is used to customize the default string description of an + object, as returned by `Object.prototype.toString`. + + 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..777130ee4691 --- /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 // + +/** +* To string tag symbol. +* +* ## Notes +* +* - This symbol is used to customize the default string description of an object. +* - 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..5ff973fdbcfe --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 ToStringTagSymbol = require( './../lib' ); + +// Create an object: +var obj = {}; + +// Assign a custom string tag: +obj[ ToStringTagSymbol ] = 'MyObject'; + +// Retrieve the object's default string description: +var str = Object.prototype.toString.call( obj ); +console.log( str ); +// => '[object MyObject]' 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..47e5ca3e876b --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/index.js @@ -0,0 +1,40 @@ +/** +* @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 customize the default string description of an object. +* +* @module @stdlib/symbol/to-string-tag +* +* @example +* var ToStringTagSymbol = require( '@stdlib/symbol/to-string-tag' ); +* +* var o = {}; +* o[ ToStringTagSymbol ] = 'Foo'; +*/ + +// 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..a59612688b0a --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/lib/main.js @@ -0,0 +1,46 @@ +/** +* @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 hasToStringTagSupport = require( '@stdlib/assert/has-tostringtag-support' ); +var Symbol = require( '@stdlib/symbol/ctor' ); + + +// MAIN // + +/** +* To string tag symbol. +* +* @name ToStringTagSymbol +* @constant +* @type {(symbol|null)} +* +* @example +* var o = {}; +* +* o[ ToStringTagSymbol ] = 'Foo'; +*/ +var ToStringTagSymbol = ( hasToStringTagSupport() ) ? Symbol.toStringTag : null; + + +// 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..8e43b516ab40 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/package.json @@ -0,0 +1,59 @@ +{ + "name": "@stdlib/symbol/to-string-tag", + "version": "0.0.0", + "description": "To string tag 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", + "tostringtag", + "tag", + "class", + "type" + ] +} 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..face635405d2 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/to-string-tag/test/test.js @@ -0,0 +1,53 @@ +/** +* @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 hasToStringTagSupport = require( '@stdlib/assert/has-tostringtag-support' ); +var isSymbol = require( '@stdlib/assert/is-symbol' ); +var Symbol = require( '@stdlib/symbol/ctor' ); +var Sym = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasToStringTagSupport() +}; + + +// 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(); +});