diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/README.md b/lib/node_modules/@stdlib/plot/base/symbol2alias/README.md new file mode 100644 index 000000000000..3ed1937db568 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/README.md @@ -0,0 +1,124 @@ + + +# symbol2alias + +> Convert a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a canonical [symbol alias][@stdlib/plot/base/symbol-aliases]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var symbol2alias = require( '@stdlib/plot/base/symbol2alias' ); +``` + +#### symbol2alias( value ) + +Converts a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a canonical [symbol alias][@stdlib/plot/base/symbol-aliases]. + +```javascript +var out = symbol2alias( 'o' ); +// returns 'circle' +``` + +For symbols having more than one accepted alias, the function returns the canonical alias. + +```javascript +var out = symbol2alias( 'plus' ); +// returns 'cross' +``` + +If unable to resolve an alias, the function returns `null`. + +```javascript +var out = symbol2alias( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var logEachMap = require( '@stdlib/console/log-each-map' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2alias = require( '@stdlib/plot/base/symbol2alias' ); + +logEachMap( '%s => %s', symbolAliases(), symbol2alias ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/base/symbol2alias/benchmark/benchmark.js new file mode 100644 index 000000000000..11259df56dfa --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var symbol2alias = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'o', + '+', + 'circle', + 'triangle-up' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = symbol2alias( values[ i%values.length ] ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/repl.txt b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/repl.txt new file mode 100644 index 000000000000..97831f4e8e95 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( value ) + Converts a symbol alias or shorthand to a canonical symbol alias. + + If unable to resolve an alias, the function returns `null`. + + Parameters + ---------- + value: string + Symbol alias or shorthand. + + Returns + ------- + out: string|null + Canonical symbol alias. + + Examples + -------- + > var v = {{alias}}( 'o' ) + 'circle' + > v = {{alias}}( 'plus' ) + 'cross' + > v = {{alias}}( 'beep' ) + null + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/index.d.ts new file mode 100644 index 000000000000..fdcc22d4945e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 + +/** +* Converts a symbol alias or shorthand to a canonical symbol alias. +* +* ## Notes +* +* - For symbols having more than one accepted alias (e.g., `cross` and `plus`), the function returns the canonical alias. +* - If unable to resolve an alias, the function returns `null`. +* +* @param value - symbol alias or shorthand +* @returns canonical symbol alias +* +* @example +* var v = symbol2alias( 'o' ); +* // returns 'circle' +* +* v = symbol2alias( 'plus' ); +* // returns 'cross' +* +* v = symbol2alias( 'beep' ); +* // returns null +*/ +declare function symbol2alias( value: string ): string | null; + + +// EXPORTS // + +export = symbol2alias; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/test.ts b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/test.ts new file mode 100644 index 000000000000..f36bed3fe73a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/test.ts @@ -0,0 +1,45 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +import symbol2alias = require( './index' ); + + +// TESTS // + +// The function returns a string or null... +{ + symbol2alias( 'o' ); // $ExpectType string | null +} + +// The compiler throws an error if the function is not provided a string... +{ + symbol2alias( 1 ); // $ExpectError + symbol2alias( true ); // $ExpectError + symbol2alias( false ); // $ExpectError + symbol2alias( null ); // $ExpectError + symbol2alias( undefined ); // $ExpectError + symbol2alias( [] ); // $ExpectError + symbol2alias( {} ); // $ExpectError + symbol2alias( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + symbol2alias(); // $ExpectError + symbol2alias( 'o', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/examples/index.js b/lib/node_modules/@stdlib/plot/base/symbol2alias/examples/index.js new file mode 100644 index 000000000000..2cf3530afc8b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/examples/index.js @@ -0,0 +1,25 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 logEachMap = require( '@stdlib/console/log-each-map' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2alias = require( './../lib' ); + +logEachMap( '%s => %s', symbolAliases(), symbol2alias ); diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/index.js b/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/index.js new file mode 100644 index 000000000000..834813e2b9d9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Convert a symbol alias or shorthand to a canonical symbol alias. +* +* @module @stdlib/plot/base/symbol2alias +* +* @example +* var symbol2alias = require( '@stdlib/plot/base/symbol2alias' ); +* +* var v = symbol2alias( 'o' ); +* // returns 'circle' +* +* v = symbol2alias( 'plus' ); +* // returns 'cross' +* +* v = symbol2alias( 'beep' ); +* // returns null +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/main.js b/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/main.js new file mode 100644 index 000000000000..57d17da501a8 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/lib/main.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// VARIABLES // + +var SYMBOLS = { + 'arrow': 'arrow', + '->': 'arrow', + + 'asterisk': 'asterisk', + '*': 'asterisk', + + 'circle': 'circle', + 'o': 'circle', + + 'cross': 'cross', + 'plus': 'cross', + '+': 'cross', + + 'diamond': 'diamond', + 'd': 'diamond', + + 'dot': 'dot', + '.': 'dot', + + 'hexagram': 'hexagram', + 'h': 'hexagram', + + 'line': 'line', + '|': 'line', + + 'square': 'square', + 's': 'square', + + 'star': 'star', + 'pentagram': 'star', + 'p': 'star', + + 'stroke': 'stroke', + '_': 'stroke', + + 'triangle': 'triangle', + 't': 'triangle', + + 'triangle-down': 'triangle-down', + 'v': 'triangle-down', + + 'triangle-left': 'triangle-left', + '<': 'triangle-left', + + 'triangle-right': 'triangle-right', + '>': 'triangle-right', + + 'triangle-up': 'triangle-up', + '^': 'triangle-up', + + 'wedge': 'wedge', + 'w': 'wedge', + + 'x': 'x' +}; + + +// MAIN // + +/** +* Converts a symbol alias or shorthand to a canonical symbol alias. +* +* ## Notes +* +* - For symbols having more than one accepted alias (e.g., `cross` and `plus`), the function returns the canonical alias. +* - If unable to resolve an alias, the function returns `null`. +* +* @param {string} value - symbol alias or shorthand +* @returns {(string|null)} canonical symbol alias +* +* @example +* var v = symbol2alias( 'o' ); +* // returns 'circle' +* +* v = symbol2alias( 'plus' ); +* // returns 'cross' +* +* v = symbol2alias( 'beep' ); +* // returns null +*/ +function symbol2alias( value ) { + if ( hasOwnProp( SYMBOLS, value ) ) { + return SYMBOLS[ value ]; + } + return null; +} + + +// EXPORTS // + +module.exports = symbol2alias; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/package.json b/lib/node_modules/@stdlib/plot/base/symbol2alias/package.json new file mode 100644 index 000000000000..35cb90d78e28 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/plot/base/symbol2alias", + "version": "0.0.0", + "description": "Convert a symbol alias or shorthand to a canonical symbol alias.", + "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": { + "benchmark": "./benchmark", + "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", + "plot", + "base", + "symbol", + "alias", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/plot/base/symbol2alias/test/test.js b/lib/node_modules/@stdlib/plot/base/symbol2alias/test/test.js new file mode 100644 index 000000000000..27f7028ce01a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2alias/test/test.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var symbolShorthands = require( '@stdlib/plot/base/symbol-shorthands' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2alias = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof symbol2alias, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an alias when provided a symbol alias', function test( t ) { + var values; + var v; + var i; + + values = symbolAliases(); + for ( i = 0; i < values.length; i++ ) { + v = symbol2alias( values[ i ] ); + t.strictEqual( isString( v ), true, 'returns expected value for ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns an alias when provided a symbol shorthand', function test( t ) { + var values; + var v; + var i; + + values = symbolShorthands(); + for ( i = 0; i < values.length; i++ ) { + v = symbol2alias( values[ i ] ); + t.strictEqual( isString( v ), true, 'returns expected value for ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function resolves the same alias for a symbol alias and its corresponding shorthand', function test( t ) { + t.strictEqual( symbol2alias( 'circle' ), 'circle', 'returns expected value' ); + t.strictEqual( symbol2alias( 'o' ), 'circle', 'returns expected value' ); + t.end(); +}); + +tape( 'the function resolves the canonical alias for symbols having more than one accepted alias', function test( t ) { + t.strictEqual( symbol2alias( 'plus' ), 'cross', 'returns expected value' ); + t.strictEqual( symbol2alias( 'pentagram' ), 'star', 'returns expected value' ); + t.end(); +}); + +tape( 'if unable to resolve an alias, the function returns `null`', function test( t ) { + var expected; + var actual; + var values; + var i; + + values = [ + '', + 'beep', + 'boop', + '==', + 'toString', + 'constructor' + ]; + expected = null; + for ( i = 0; i < values.length; i++ ) { + actual = symbol2alias( values[ i ] ); + t.strictEqual( actual, expected, 'returns expected value for ' + values[ i ] ); + } + t.end(); +});