-
-
Notifications
You must be signed in to change notification settings - Fork 831
feat: refactor string package reverse #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dda2690
feat: create reverse base packages and refactor main string package
steff456 df8f433
fix: fix bug and add tests
steff456 9c3ea43
fix: add more tests to fix code coverage
steff456 6dee165
fix: rename packages to use plural context
steff456 0901c7f
Apply suggestions from code review
kgryte 6bad9fd
Apply suggestions from code review
kgryte a02dc34
Apply suggestions from code review
kgryte 6a05b25
fix: use nextGraphemeCluster in implementation, fix tests and docstrings
steff456 a7e4835
Apply suggestions from code review
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
lib/node_modules/@stdlib/string/base/reverse-code-points/README.md
This file contains hidden or 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. | ||
|
||
--> | ||
|
||
# reverseCodePoints | ||
|
||
> Reverse the Unicode code points of a string. | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var reverseCodePoints = require( '@stdlib/string/base/reverse-code-points' ); | ||
``` | ||
|
||
#### reverseCodePoints( str ) | ||
|
||
Reverses the Unicode code points of a string. | ||
|
||
```javascript | ||
var out = reverseCodePoints( 'last man standing' ); | ||
// returns 'gnidnats nam tsal' | ||
|
||
out = reverseCodePoints( 'Hidden Treasures' ); | ||
// returns 'serusaerT neddiH' | ||
|
||
out = reverseCodePoints( 'foo bar' ); | ||
// returns 'rab oof' | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var reverseCodePoints = require( '@stdlib/string/base/reverse-code-points' ); | ||
|
||
var str = reverseCodePoints( 'presidential election' ); | ||
// returns 'noitcele laitnediserp' | ||
|
||
str = reverseCodePoints( 'JavaScript' ); | ||
// returns 'tpircSavaJ' | ||
|
||
str = reverseCodePoints( 'The Last of the Mohicans' ); | ||
// returns 'snacihoM eht fo tsaL ehT' | ||
|
||
str = reverseCodePoints( 'अनुच्छेद' ); | ||
// 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-points/benchmark/benchmark.js
This file contains hidden or 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-points/docs/repl.txt
This file contains hidden or 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-points/docs/types/index.d.ts
This file contains hidden or 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-points/docs/types/test.ts
This file contains hidden or 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-points/examples/index.js
This file contains hidden or 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( 'अनुच्छेद' ) ); | ||
// => 'देछ्चुनअ' | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/string/base/reverse-code-points/lib/index.js
This file contains hidden or 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-points | ||
* | ||
* @example | ||
* var reverse = require( '@stdlib/string/base/reverse-code-points' ); | ||
* | ||
* 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.