Skip to content

Commit

Permalink
feat: create reverse base packages and refactor main string package
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 committed Aug 12, 2023
1 parent f816a7a commit dda2690
Show file tree
Hide file tree
Showing 41 changed files with 2,123 additions and 34 deletions.
92 changes: 92 additions & 0 deletions lib/node_modules/@stdlib/string/base/reverse-code-point/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--
@license Apache-2.0
Copyright (c) 2023 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.
-->

# reverseCodePoint

> Reverse the Unicode code points of a string.
<section class="usage">

## Usage

```javascript
var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' );
```

#### reverseCodePoint( str )

Reverses the Unicode code points of a string.

```javascript
var out = reverseCodePoint( 'last man standing' );
// returns 'gnidnats nam tsal'

out = reverseCodePoint( 'Hidden Treasures' );
// returns 'serusaerT neddiH'

out = reverseCodePoint( 'foo bar' );
// returns 'rab oof'
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' );

var str = reverseCodePoint( 'presidential election' );
// returns 'noitcele laitnediserp'

str = reverseCodePoint( 'JavaScript' );
// returns 'tpircSavaJ'

str = reverseCodePoint( 'The Last of the Mohicans' );
// returns 'snacihoM eht fo tsaL ehT'

str = reverseCodePoint( 'अनुच्छेद' );
// returns 'देछ्चुनअ'
```

</section>

<!-- /.examples -->

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 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 reverse = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var i;

values = [
'beep boop',
'foo bar',
'xyz abc',
'🐶🐮🐷🐰🐸'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = reverse( values[ i%values.length ], 1 );
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();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

{{alias}}( str )
Reverses the Unicode code points of a string.

Parameters
----------
str: string
Input string.

Returns
-------
out: string
Output string.

Examples
--------
> var out = {{alias}}( 'beep' )
'peeb'
> out = {{alias}}( 'Boop' )
'pooB'
> out = {{alias}}( 'foo bar' )
'rab oof'

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 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: 2.0

/**
* Reverses the Unicode code points of a string.
*
* @param str - input string
* @returns output string
*
* @example
* var out = reverse( 'last man standing' );
* // returns 'gnidnats nam tsal'
*
* @example
* var out = reverse( 'presidential election' );
* // returns 'noitcele laitnediserp'
*
* @example
* var out = reverse( 'JavaScript' );
* // returns 'tpircSavaJ'
*
* @example
* var out = reverse( 'Hidden Treasures' );
* // returns 'serusaerT neddiH'
*
* @example
* var out = reverse( 'foo bar' );
* // returns 'rab oof'
*/
declare function reverse( str: string ): string;


// EXPORTS //

export = reverse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 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 reverse = require( './index' );


// TESTS //

// The function returns a string...
{
reverse( 'abc' ); // $ExpectType string
}

// The compiler throws an error if the function is provided a value other than a string...
{
reverse( true ); // $ExpectError
reverse( false ); // $ExpectError
reverse( null ); // $ExpectError
reverse( undefined ); // $ExpectError
reverse( 5 ); // $ExpectError
reverse( [] ); // $ExpectError
reverse( {} ); // $ExpectError
reverse( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
reverse(); // $ExpectError
reverse( 'abc', 1 ); // $ExpectError
reverse( 'abc', 1, 2 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 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 reverse = require( './../lib' );

console.log( reverse( 'presidential election' ) );
// => 'noitcele laitnediserp'

console.log( reverse( 'JavaScript' ) );
// => 'tpircSavaJ'

console.log( reverse( 'The Last of the Mohicans' ) );
// => 'snacihoM eht fo tsaL ehT'

console.log( reverse( 'अनुच्छेद' ) );
// => 'देछ्चुनअ'
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 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';

/**
* Reverse the Unicode code points of a string.
*
* @module @stdlib/string/base/reverse-code-point
*
* @example
* var reverse = require( '@stdlib/string/base/reverse-code-point' );
*
* var out = reverse( 'last man standing' );
* // returns 'gnidnats nam tsal'
*
* out = reverse( 'Hidden Treasures' );
* // returns 'serusaerT neddiH';
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading

0 comments on commit dda2690

Please sign in to comment.