Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2alias/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--

@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.

-->

# 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].

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## 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
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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 );
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/plot/base/symbol-shorthands]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/base/symbol-shorthands

[@stdlib/plot/base/symbol-aliases]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/base/symbol-aliases

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -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();
});
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2alias/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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
--------

Original file line number Diff line number Diff line change
@@ -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;
45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2alias/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2alias/examples/index.js
Original file line number Diff line number Diff line change
@@ -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 );
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2alias/lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
Loading