-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create reverse base packages and refactor main string package
- Loading branch information
Showing
41 changed files
with
2,123 additions
and
34 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
lib/node_modules/@stdlib/string/base/reverse-code-point/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
56 changes: 56 additions & 0 deletions
56
lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
-------- | ||
|
52 changes: 52 additions & 0 deletions
52
lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
46 changes: 46 additions & 0 deletions
46
lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( 'अनुच्छेद' ) ); | ||
// => 'देछ्चुनअ' |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.