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
119 changes: 119 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbols2shorthands/README.md
Original file line number Diff line number Diff line change
@@ -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.

-->

# symbols2shorthands

> Convert an array of symbol [aliases][@stdlib/plot/base/symbol-aliases] and/or [shorthands][@stdlib/plot/base/symbol-shorthands] to [symbol shorthands][@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 symbols2shorthands = require( '@stdlib/plot/base/symbols2shorthands' );
```

#### symbols2shorthands( symbols )

Converts an array of symbol [aliases][@stdlib/plot/base/symbol-aliases] and/or [shorthands][@stdlib/plot/base/symbol-shorthands] to [symbol shorthands][@stdlib/plot/base/symbol-shorthands].

```javascript
var out = symbols2shorthands( [ 'circle', 'square' ] );
// returns [ 'o', 's' ]
```

If unable to resolve a shorthand for an element of the input array, the corresponding element in the output array is `null`.

```javascript
var out = symbols2shorthands( [ 'circle', 'beep' ] );
// returns [ 'o', 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 logEach = require( '@stdlib/console/log-each' );
var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' );
var symbols2shorthands = require( '@stdlib/plot/base/symbols2shorthands' );

var symbols = symbolAliases();

logEach( '%s => %s', symbols, symbols2shorthands( symbols ) );
```

</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,54 @@
/**
* @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 isArray = require( '@stdlib/assert/is-array' );
var pkg = require( './../package.json' ).name;
var symbols2shorthands = 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 = symbols2shorthands( values[ i%values.length ] );
if ( out.length !== 2 ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( !isArray( out ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

{{alias}}( symbols )
Converts an array of symbol aliases and/or shorthands to symbol shorthands.

If unable to resolve a shorthand for an element of the input array, the
corresponding element in the output array is `null`.

Parameters
----------
symbols: Array<string>
Symbol aliases and/or shorthands.

Returns
-------
out: Array
Symbol shorthands.

Examples
--------
> var v = {{alias}}( [ 'circle', 'square' ] )
[ 'o', 's' ]
> v = {{alias}}( [ 'circle', 'beep' ] )
[ 'o', 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

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';

/**
* Converts an array of symbol aliases and/or shorthands to symbol shorthands.
*
* ## Notes
*
* - If unable to resolve a shorthand for an element of the input array, the corresponding element in the output array is `null`.
*
* @param symbols - symbol aliases and/or shorthands
* @returns symbol shorthands
*
* @example
* var v = symbols2shorthands( [ 'circle', 'square' ] );
* // returns [ 'o', 's' ]
*
* v = symbols2shorthands( [ 'circle', 'beep' ] );
* // returns [ 'o', null ]
*/
declare function symbols2shorthands( symbols: Collection<string> ): Array<string | null>;


// EXPORTS //

export = symbols2shorthands;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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 symbols2shorthands = require( './index' );


// TESTS //

// The function returns an array...
{
symbols2shorthands( [ 'o', '+' ] ); // $ExpectType (string | null)[]
}

// The compiler throws an error if the function is not provided a collection of strings...
{
symbols2shorthands( 1 ); // $ExpectError
symbols2shorthands( true ); // $ExpectError
symbols2shorthands( false ); // $ExpectError
symbols2shorthands( null ); // $ExpectError
symbols2shorthands( undefined ); // $ExpectError
symbols2shorthands( {} ); // $ExpectError
symbols2shorthands( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
symbols2shorthands(); // $ExpectError
symbols2shorthands( [ 'o' ], {} ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @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 logEach = require( '@stdlib/console/log-each' );
var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' );
var symbols2shorthands = require( './../lib' );

var symbols = symbolAliases();

logEach( '%s => %s', symbols, symbols2shorthands( symbols ) );
43 changes: 43 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbols2shorthands/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @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 an array of symbol aliases and/or shorthands to symbol shorthands.
*
* @module @stdlib/plot/base/symbols2shorthands
*
* @example
* var symbols2shorthands = require( '@stdlib/plot/base/symbols2shorthands' );
*
* var v = symbols2shorthands( [ 'circle', 'square' ] );
* // returns [ 'o', 's' ]
*
* v = symbols2shorthands( [ 'circle', 'beep' ] );
* // returns [ 'o', null ]
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading
Loading