-
-
Notifications
You must be signed in to change notification settings - Fork 836
feat: add string/base/last-code-point
#1755
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
Planeshifter
merged 10 commits into
stdlib-js:develop
from
adityacodes30:last-code-point
Mar 13, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fc6da73
feat: add readme and package.json
adityacodes30 69f9126
feat: add last-code-point readme and package.json issue #1702
adityacodes30 2c95405
feat: add last-code-point #1702
adityacodes30 fb4d672
Update lib/node_modules/@stdlib/string/base/last-code-point/README.md
adityacodes30 6b124bd
Update lib/node_modules/@stdlib/string/base/last-code-point/README.md
adityacodes30 e8ed848
Update lib/node_modules/@stdlib/string/base/last-code-point/docs/type…
adityacodes30 325844d
feat: add last-code-point requested changes
adityacodes30 bf58f5b
Update lib/node_modules/@stdlib/string/base/last-code-point/lib/main.js
adityacodes30 3bb8cf3
feat: requested changes
adityacodes30 8512bd8
Apply suggestions from code review
Planeshifter 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
107 changes: 107 additions & 0 deletions
107
lib/node_modules/@stdlib/string/base/last-code-point/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,107 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 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. | ||
|
||
--> | ||
|
||
# lastCodePoint | ||
|
||
> Return the last `n` Unicode code points of a string. | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var lastCodePoint = require( '@stdlib/string/base/last-code-point' ); | ||
``` | ||
|
||
#### lastCodePoint( str, n ) | ||
|
||
Returns the last `n` Unicode code points of a string. | ||
|
||
```javascript | ||
var s = lastCodePoint( 'JavaScript', 1 ); | ||
// returns 't' | ||
|
||
s = lastCodePoint( 'Hello World', 5 ); | ||
// returns 'World' | ||
|
||
s = lastCodePoint( 'Good Evening', 9 ); | ||
// returns 'd Evening' | ||
|
||
s = lastCodePoint( 'foo bar', 10 ); | ||
// returns 'foo bar' | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var lastCodePoint = require( '@stdlib/string/base/last-code-point' ); | ||
|
||
var str = lastCodePoint( 'Hello World', 1 ); | ||
// returns 'd' | ||
|
||
str = lastCodePoint( 'JavaScript', 6 ); | ||
// returns 'Script' | ||
|
||
str = lastCodePoint( 'ASCII', 2 ); | ||
// returns 'II' | ||
|
||
str = lastCodePoint( 'index', 10 ); | ||
// returns 'index' | ||
|
||
str = lastCodePoint( 'अनुच्छेद', 1 ); | ||
// returns 'द' | ||
|
||
str = lastCodePoint( '六书/六書', 3 ); | ||
// 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"> | ||
|
||
<!-- <related-links> --> | ||
|
||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
60 changes: 60 additions & 0 deletions
60
lib/node_modules/@stdlib/string/base/last-code-point/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,60 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 last = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var values; | ||
var out; | ||
var i; | ||
|
||
values = [ | ||
'hello world', | ||
'new', | ||
'JavaScript', | ||
'beep boop', | ||
'foo bar', | ||
'xyz abc', | ||
'🐶🐮🐷🐰🐸', | ||
'अनुच्छेद' | ||
]; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = last( 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(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
lib/node_modules/@stdlib/string/base/last-code-point/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,29 @@ | ||
|
||
{{alias}}( str, n ) | ||
Returns the last `n` Unicode code points of a string. | ||
|
||
Parameters | ||
---------- | ||
str: string | ||
Input string. | ||
|
||
n: integer | ||
Number of Unicode code points to return. | ||
|
||
Returns | ||
------- | ||
out: string | ||
Output string. | ||
|
||
Examples | ||
-------- | ||
> var out = {{alias}}( 'hello world', 1 ) | ||
'd' | ||
> out = {{alias}}( 'JavaScript', 6 ) | ||
'Script' | ||
> out = {{alias}}( 'अनुच्छेद', 1 ) | ||
'द' | ||
|
||
See Also | ||
-------- | ||
|
49 changes: 49 additions & 0 deletions
49
lib/node_modules/@stdlib/string/base/last-code-point/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,49 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 | ||
|
||
/** | ||
* Returns the last `n` Unicode code points of a string. | ||
* | ||
* @param str - input string | ||
* @param n - number of code points to return | ||
* @returns output string | ||
* | ||
* @example | ||
* var out = last( 'Hello World', 1 ); | ||
* // returns 'd' | ||
* | ||
* @example | ||
* var out = last( 'JavaScript', 6 ); | ||
* // returns 'Script' | ||
* | ||
* @example | ||
* var out = last( 'New', 5 ); | ||
* // returns 'New' | ||
* | ||
* @example | ||
* var out = last( 'अनुच्छेद', 1 ); | ||
* // returns 'द' | ||
*/ | ||
declare function last( str: string, n: number ): string; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = last; |
57 changes: 57 additions & 0 deletions
57
lib/node_modules/@stdlib/string/base/last-code-point/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,57 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 last = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a string... | ||
{ | ||
last( 'abc', 1 ); // $ExpectType string | ||
} | ||
|
||
// The compiler throws an error if the function is provided a value other than a string... | ||
{ | ||
last( true, 1 ); // $ExpectError | ||
last( false, 1 ); // $ExpectError | ||
last( null, 1 ); // $ExpectError | ||
last( undefined, 1 ); // $ExpectError | ||
last( 5, 1 ); // $ExpectError | ||
last( [], 1 ); // $ExpectError | ||
last( {}, 1 ); // $ExpectError | ||
last( ( x: number ): number => x, 1 ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided a second argument that is not a number... | ||
{ | ||
last( 'abc', true ); // $ExpectError | ||
last( 'abc', false ); // $ExpectError | ||
last( 'abc', null ); // $ExpectError | ||
last( 'abc', 'abc' ); // $ExpectError | ||
last( 'abc', [] ); // $ExpectError | ||
last( 'abc', {} ); // $ExpectError | ||
last( 'abc', ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided an unsupported number of arguments... | ||
{ | ||
last(); // $ExpectError | ||
last( 'abc' ); // $ExpectError | ||
last( 'abc', 1, 2 ); // $ExpectError | ||
} | ||
36 changes: 36 additions & 0 deletions
36
lib/node_modules/@stdlib/string/base/last-code-point/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,36 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 lastCodePoint = require( './../lib' ); | ||
|
||
console.log( lastCodePoint( 'Hello World', 1 ) ); | ||
// => 'd' | ||
|
||
console.log( lastCodePoint( 'JavaScript', 6 ) ); | ||
// => 'Script' | ||
|
||
console.log( lastCodePoint( 'index', 10 ) ); | ||
// => 'index' | ||
|
||
console.log( lastCodePoint( 'अनुच्छेद', 1 ) ); | ||
// => 'द' | ||
|
||
console.log( lastCodePoint( '六书/六書', 3 ) ); | ||
// => '/六書' |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/string/base/last-code-point/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) 2024 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'; | ||
|
||
/** | ||
* Return the last `n` Unicode code points of a string. | ||
* | ||
* @module @stdlib/string/base/last-code-point | ||
* | ||
* @example | ||
* var last = require( '@stdlib/string/base/last-code-point' ); | ||
* | ||
* var out = last( 'Hello World', 1 ); | ||
* // returns 'd' | ||
* | ||
* out = last( 'अनुच्छेद', 1 ); | ||
* // returns 'द'; | ||
*/ | ||
|
||
// 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.