diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/README.md b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/README.md new file mode 100644 index 000000000000..5a96d9cd62ef --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/README.md @@ -0,0 +1,134 @@ + + +# symbol2shorthand + +> Convert a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a canonical [symbol shorthand][@stdlib/plot/base/symbol-shorthands]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var symbol2shorthand = require( '@stdlib/plot/base/symbol2shorthand' ); +``` + +#### symbol2shorthand( value ) + +Converts a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a canonical [symbol shorthand][@stdlib/plot/base/symbol-shorthands]. + +```javascript +var out = symbol2shorthand( 'circle' ); +// returns 'o' +``` + +If provided a shorthand, the function returns the provided shorthand. + +```javascript +var out = symbol2shorthand( 'o' ); +// returns 'o' +``` + +For symbols having more than one accepted alias, the function returns the same shorthand. + +```javascript +var out = symbol2shorthand( 'plus' ); +// returns '+' + +out = symbol2shorthand( 'cross' ); +// returns '+' +``` + +If unable to resolve a shorthand, the function returns `null`. + +```javascript +var out = symbol2shorthand( 'beep' ); +// returns null +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var logEachMap = require( '@stdlib/console/log-each-map' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2shorthand = require( '@stdlib/plot/base/symbol2shorthand' ); + +logEachMap( '%s => %s', symbolAliases(), symbol2shorthand ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/benchmark/benchmark.js new file mode 100644 index 000000000000..f2b71ec2834c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 symbol2shorthand = 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 = symbol2shorthand( 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/symbol2shorthand/docs/repl.txt b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/repl.txt new file mode 100644 index 000000000000..b39b92bf5d0a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( value ) + Converts a symbol alias or shorthand to a symbol shorthand. + + If unable to resolve a shorthand, the function returns `null`. + + Parameters + ---------- + value: string + Symbol alias or shorthand. + + Returns + ------- + out: string|null + Symbol shorthand. + + Examples + -------- + > var v = {{alias}}( 'circle' ) + 'o' + > v = {{alias}}( 'o' ) + 'o' + > v = {{alias}}( 'beep' ) + null + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/types/index.d.ts new file mode 100644 index 000000000000..8c24ec255991 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 symbol shorthand. +* +* ## Notes +* +* - If provided a shorthand, the function returns the provided shorthand. +* - If unable to resolve a shorthand, the function returns `null`. +* +* @param value - symbol alias or shorthand +* @returns symbol shorthand +* +* @example +* var v = symbol2shorthand( 'circle' ); +* // returns 'o' +* +* v = symbol2shorthand( 'o' ); +* // returns 'o' +* +* v = symbol2shorthand( 'beep' ); +* // returns null +*/ +declare function symbol2shorthand( value: string ): string | null; + + +// EXPORTS // + +export = symbol2shorthand; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/types/test.ts b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/docs/types/test.ts new file mode 100644 index 000000000000..a6548344a7b8 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 symbol2shorthand = require( './index' ); + + +// TESTS // + +// The function returns a string or null... +{ + symbol2shorthand( 'o' ); // $ExpectType string | null +} + +// The compiler throws an error if the function is not provided a string... +{ + symbol2shorthand( 1 ); // $ExpectError + symbol2shorthand( true ); // $ExpectError + symbol2shorthand( false ); // $ExpectError + symbol2shorthand( null ); // $ExpectError + symbol2shorthand( undefined ); // $ExpectError + symbol2shorthand( [] ); // $ExpectError + symbol2shorthand( {} ); // $ExpectError + symbol2shorthand( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + symbol2shorthand(); // $ExpectError + symbol2shorthand( 'o', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/examples/index.js b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/examples/index.js new file mode 100644 index 000000000000..664d434114ba --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 symbol2shorthand = require( './../lib' ); + +logEachMap( '%s => %s', symbolAliases(), symbol2shorthand ); diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/lib/index.js b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/lib/index.js new file mode 100644 index 000000000000..50b0b336781a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 symbol shorthand. +* +* @module @stdlib/plot/base/symbol2shorthand +* +* @example +* var symbol2shorthand = require( '@stdlib/plot/base/symbol2shorthand' ); +* +* var v = symbol2shorthand( 'circle' ); +* // returns 'o' +* +* v = symbol2shorthand( 'o' ); +* // returns 'o' +* +* v = symbol2shorthand( 'beep' ); +* // returns null +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/lib/main.js b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/lib/main.js new file mode 100644 index 000000000000..fe06417dce56 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/lib/main.js @@ -0,0 +1,88 @@ +/** +* @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' ); +var isSymbolShorthand = require( '@stdlib/plot/base/assert/is-symbol-shorthand' ); + + +// VARIABLES // + +var SYMBOLS = { + 'arrow': '->', + 'asterisk': '*', + 'circle': 'o', + 'cross': '+', + 'plus': '+', + 'diamond': 'd', + 'dot': '.', + 'hexagram': 'h', + 'line': '|', + 'square': 's', + 'star': 'p', + 'pentagram': 'p', + 'stroke': '_', + 'triangle': 't', + 'triangle-down': 'v', + 'triangle-left': '<', + 'triangle-right': '>', + 'triangle-up': '^', + 'wedge': 'w' +}; + + +// MAIN // + +/** +* Converts a symbol alias or shorthand to a symbol shorthand. +* +* ## Notes +* +* - If provided a shorthand, the function returns the provided shorthand. +* - If unable to resolve a shorthand, the function returns `null`. +* +* @param {string} value - symbol alias or shorthand +* @returns {(string|null)} symbol shorthand +* +* @example +* var v = symbol2shorthand( 'circle' ); +* // returns 'o' +* +* v = symbol2shorthand( 'o' ); +* // returns 'o' +* +* v = symbol2shorthand( 'beep' ); +* // returns null +*/ +function symbol2shorthand( value ) { + if ( isSymbolShorthand( value ) ) { + return value; + } + if ( hasOwnProp( SYMBOLS, value ) ) { + return SYMBOLS[ value ]; + } + return null; +} + + +// EXPORTS // + +module.exports = symbol2shorthand; diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/package.json b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/package.json new file mode 100644 index 000000000000..b7306c35df6a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/plot/base/symbol2shorthand", + "version": "0.0.0", + "description": "Convert a symbol alias or shorthand to a symbol shorthand.", + "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", + "shorthand", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/plot/base/symbol2shorthand/test/test.js b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/test/test.js new file mode 100644 index 000000000000..48d531e3a15d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 isSymbolShorthand = require( '@stdlib/plot/base/assert/is-symbol-shorthand' ); +var symbolShorthands = require( '@stdlib/plot/base/symbol-shorthands' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2shorthand = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof symbol2shorthand, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a shorthand when provided a symbol alias', function test( t ) { + var values; + var v; + var i; + + values = symbolAliases(); + for ( i = 0; i < values.length; i++ ) { + v = symbol2shorthand( values[ i ] ); + t.strictEqual( isSymbolShorthand( v ), true, 'returns expected value for ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns the provided shorthand when provided a symbol shorthand', function test( t ) { + var values; + var v; + var i; + + values = symbolShorthands(); + for ( i = 0; i < values.length; i++ ) { + v = symbol2shorthand( values[ i ] ); + t.strictEqual( v, values[ i ], 'returns expected value for ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function resolves the same shorthand for a symbol alias and its corresponding shorthand', function test( t ) { + t.strictEqual( symbol2shorthand( 'circle' ), 'o', 'returns expected value' ); + t.strictEqual( symbol2shorthand( 'o' ), 'o', 'returns expected value' ); + t.end(); +}); + +tape( 'the function resolves the same shorthand for each accepted alias of a symbol', function test( t ) { + t.strictEqual( symbol2shorthand( 'plus' ), symbol2shorthand( 'cross' ), 'returns expected value' ); + t.strictEqual( symbol2shorthand( 'pentagram' ), symbol2shorthand( 'star' ), 'returns expected value' ); + t.end(); +}); + +tape( 'if unable to resolve a shorthand, 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 = symbol2shorthand( values[ i ] ); + t.strictEqual( actual, expected, 'returns expected value for ' + values[ i ] ); + } + t.end(); +});