Skip to content

Commit 1c8c20c

Browse files
committed
Auto-generated commit
1 parent b0160e7 commit 1c8c20c

55 files changed

Lines changed: 2252 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@
2323
# Automatically normalize the line endings of any committed text files:
2424
* text=auto
2525

26+
# Override line endings for certain files on checkout:
27+
*.crlf.csv text eol=crlf
28+
29+
# Denote that certain files are binary and should not be modified:
30+
*.png binary
31+
*.jpg binary
32+
*.jpeg binary
33+
*.gif binary
34+
*.ico binary
35+
*.gz binary
36+
*.zip binary
37+
*.7z binary
38+
*.mp3 binary
39+
*.mp4 binary
40+
*.mov binary
41+
2642
# Override what is considered "vendored" by GitHub's linguist:
2743
/deps/** linguist-vendored=false
2844
/lib/node_modules/** linguist-vendored=false linguist-generated=false

base/ends-with/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2022 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# endsWith
22+
23+
> Test if a string ends with the characters of another string.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var endsWith = require( '@stdlib/string/base/ends-with' );
37+
```
38+
39+
#### endsWith( str, search, len )
40+
41+
Tests if a string ends with the characters of another string.
42+
43+
```javascript
44+
var str = 'Remember the story I used to tell you when you were a boy?';
45+
46+
var bool = endsWith( str, 'boy?', str.length );
47+
// returns true
48+
49+
bool = endsWith( str, 'Boy?', str.length );
50+
// returns false
51+
```
52+
53+
To search for a match at the end of a substring, provide a `len` argument. If `len` is positive, the function restricts the search to a substring with length `len`, beginning with the leftmost character. If `len` is negative, `len` indicates to ignore the last `len` characters (equivalent to `str.length + len`).
54+
55+
```javascript
56+
var str = 'To be, or not to be, that is the question.';
57+
58+
var bool = endsWith( str, 'to be', 19 );
59+
// returns true
60+
61+
bool = endsWith( str, 'to be', -23 );
62+
// returns true
63+
```
64+
65+
If provided an empty `search` string, the function **always** returns `true`.
66+
67+
```javascript
68+
var str = 'beep boop';
69+
70+
var bool = endsWith( str, '' );
71+
// returns true
72+
```
73+
74+
</section>
75+
76+
<!-- /.usage -->
77+
78+
<section class="notes">
79+
80+
## Notes
81+
82+
- In general, exercise caution when operating on substrings containing Unicode characters, as the visual character length may not equal the number of code points. For example,
83+
84+
```javascript
85+
var len = '🏠'.length;
86+
// returns 2
87+
```
88+
89+
</section>
90+
91+
<!-- /.notes -->
92+
93+
<section class="examples">
94+
95+
## Examples
96+
97+
<!-- eslint no-undef: "error" -->
98+
99+
```javascript
100+
var endsWith = require( '@stdlib/string/base/ends-with' );
101+
102+
var str = 'Fair is foul, and foul is fair, hover through fog and filthy air';
103+
104+
var bool = endsWith( str, 'air', str.length );
105+
// returns true
106+
107+
bool = endsWith( str, 'fair', str.length );
108+
// returns false
109+
110+
bool = endsWith( str, 'fair', 30 );
111+
// returns true
112+
113+
bool = endsWith( str, 'fair', -34 );
114+
// returns true
115+
```
116+
117+
</section>
118+
119+
<!-- /.examples -->
120+
121+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
122+
123+
<section class="related">
124+
125+
</section>
126+
127+
<!-- /.related -->
128+
129+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
130+
131+
<section class="links">
132+
133+
</section>
134+
135+
<!-- /.links -->
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var endsWith = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var bool;
34+
var str;
35+
var i;
36+
37+
str = 'To be, or not to be, that is the question.';
38+
values = [
39+
'.',
40+
'z',
41+
'questions'
42+
];
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
bool = endsWith( str, values[ i%values.length ], str.length );
47+
if ( typeof bool !== 'boolean' ) {
48+
b.fail( 'should return a boolean' );
49+
}
50+
}
51+
b.toc();
52+
if ( !isBoolean( bool ) ) {
53+
b.fail( 'should return a boolean' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});

base/ends-with/docs/repl.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
{{alias}}( str, search, len )
3+
Tests if a string ends with the characters of another string.
4+
5+
If provided an empty search string, the function always returns `true`.
6+
7+
Parameters
8+
----------
9+
str: string
10+
Input string.
11+
12+
search: string
13+
Search string.
14+
15+
len: integer
16+
Substring length. Restricts the search to a substring within the input
17+
string beginning from the leftmost character. If provided a negative
18+
value, `len` indicates to ignore the last `len` characters, returning
19+
the same output as `str.length + len`.
20+
21+
Returns
22+
-------
23+
bool: boolean
24+
Boolean indicating whether a string ends with the characters of another
25+
string.
26+
27+
Examples
28+
--------
29+
> var bool = {{alias}}( 'beep', 'ep', 4 )
30+
true
31+
> bool = {{alias}}( 'Beep', 'op', 4 )
32+
false
33+
> bool = {{alias}}( 'Beep', 'ee', 3 )
34+
true
35+
> bool = {{alias}}( 'Beep', 'ee', -1 )
36+
true
37+
> bool = {{alias}}( 'beep', '', 4 )
38+
true
39+
40+
See Also
41+
--------
42+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Tests if a string ends with the characters of another string.
23+
*
24+
* ## Notes
25+
*
26+
* - The last parameter restricts the search to a substring within the input string beginning from the leftmost character. If provided a negative value, `len` indicates to ignore the last `len` characters, returning the same output as `str.length + len`.
27+
*
28+
* @param str - input string
29+
* @param search - search string
30+
* @param len - substring length
31+
* @returns boolean indicating if the input string ends with the search string
32+
*
33+
* @example
34+
* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be', 19 );
35+
* // returns true
36+
*
37+
* @example
38+
* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be', -23 );
39+
* // returns true
40+
*/
41+
declare function endsWith( str: string, search: string, len: number ): boolean;
42+
43+
44+
// EXPORTS //
45+
46+
export = endsWith;

base/ends-with/docs/types/test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import endsWith = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
endsWith( 'To be, or not to be, that is the question.', 'b', 19 ); // $ExpectType boolean
27+
endsWith( 'abd', 'ab', 2 ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided arguments having invalid types...
31+
{
32+
endsWith( true, 'd', 2 ); // $ExpectError
33+
endsWith( false, 'd', 2 ); // $ExpectError
34+
endsWith( 3, 'd', 3 ); // $ExpectError
35+
endsWith( [], 'd', 3 ); // $ExpectError
36+
endsWith( {}, 'd', 3 ); // $ExpectError
37+
endsWith( ( x: number ): number => x, 'd', 0 ); // $ExpectError
38+
39+
endsWith( 'abd', true, 2 ); // $ExpectError
40+
endsWith( 'abd', false, 2 ); // $ExpectError
41+
endsWith( 'abd', 5, 2 ); // $ExpectError
42+
endsWith( 'abd', [], 3 ); // $ExpectError
43+
endsWith( 'abd', {}, 3 ); // $ExpectError
44+
endsWith( 'abd', ( x: number ): number => x, 0 ); // $ExpectError
45+
46+
endsWith( 'abd', 'a', true ); // $ExpectError
47+
endsWith( 'abd', 'a', false ); // $ExpectError
48+
endsWith( 'abd', 'a', '5' ); // $ExpectError
49+
endsWith( 'abd', 'b', [] ); // $ExpectError
50+
endsWith( 'abd', 'b', {} ); // $ExpectError
51+
endsWith( 'abd', 'b', /[a-z]/ ); // $ExpectError
52+
}
53+
54+
// The compiler throws an error if the function is provided insufficient arguments...
55+
{
56+
endsWith(); // $ExpectError
57+
endsWith( 'abc' ); // $ExpectError
58+
endsWith( 'abc', 'a' ); // $ExpectError
59+
}

0 commit comments

Comments
 (0)