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
134 changes: 134 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shorthand/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!--

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

-->

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

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

</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 symbol2shorthand = require( '@stdlib/plot/base/symbol2shorthand' );

logEachMap( '%s => %s', symbolAliases(), symbol2shorthand );
```

</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-aliases]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/base/symbol-aliases

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

</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 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();
});
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 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
--------

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 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;
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 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
}
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 symbol2shorthand = require( './../lib' );

logEachMap( '%s => %s', symbolAliases(), symbol2shorthand );
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shorthand/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 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;
Loading