@stdlib/string-ends-with 0.0.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +52 -107
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +7 -3
- package/lib/index.js +2 -2
- package/lib/{ends_with.js → main.js} +3 -25
- package/package.json +8 -24
- package/bin/cli +0 -124
- package/docs/repl.txt +0 -42
- package/docs/types/test.ts +0 -59
- package/docs/usage.txt +0 -10
- package/etc/cli_opts.json +0 -19
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2024 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -18,6 +18,17 @@ limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
-->
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
21
32
|
# endsWith
|
|
22
33
|
|
|
23
34
|
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
@@ -50,7 +61,7 @@ var endsWith = require( '@stdlib/string-ends-with' );
|
|
|
50
61
|
|
|
51
62
|
#### endsWith( str, search\[, len] )
|
|
52
63
|
|
|
53
|
-
Tests if a
|
|
64
|
+
Tests if a string ends with the characters of another string.
|
|
54
65
|
|
|
55
66
|
```javascript
|
|
56
67
|
var str = 'Remember the story I used to tell you when you were a boy?';
|
|
@@ -87,6 +98,27 @@ var bool = endsWith( str, '' );
|
|
|
87
98
|
|
|
88
99
|
<!-- /.usage -->
|
|
89
100
|
|
|
101
|
+
<section class="notes">
|
|
102
|
+
|
|
103
|
+
## Notes
|
|
104
|
+
|
|
105
|
+
- 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,
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
var len = '🏠'.length;
|
|
109
|
+
// returns 2
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- This function differs from [`String.prototype.endsWith`][mdn-string-endswith] in the following ways:
|
|
113
|
+
|
|
114
|
+
- The function requires string values for the first and second arguments and requires that the `len` argument is an integer value.
|
|
115
|
+
- The function does **not** clamp positive `len` values to the end of the input string.
|
|
116
|
+
- Except when provided an empty `search` string, the function **always** returns `false` if `len` resolves to a starting search position which exceeds the bounds of the input string.
|
|
117
|
+
|
|
118
|
+
</section>
|
|
119
|
+
|
|
120
|
+
<!-- /.notes -->
|
|
121
|
+
|
|
90
122
|
<section class="examples">
|
|
91
123
|
|
|
92
124
|
## Examples
|
|
@@ -96,12 +128,9 @@ var bool = endsWith( str, '' );
|
|
|
96
128
|
```javascript
|
|
97
129
|
var endsWith = require( '@stdlib/string-ends-with' );
|
|
98
130
|
|
|
99
|
-
var
|
|
100
|
-
var str;
|
|
101
|
-
|
|
102
|
-
str = 'Fair is foul, and foul is fair, hover through fog and filthy air';
|
|
131
|
+
var str = 'Fair is foul, and foul is fair, hover through fog and filthy air';
|
|
103
132
|
|
|
104
|
-
bool = endsWith( str, 'air' );
|
|
133
|
+
var bool = endsWith( str, 'air' );
|
|
105
134
|
// returns true
|
|
106
135
|
|
|
107
136
|
bool = endsWith( str, 'fair' );
|
|
@@ -118,111 +147,16 @@ bool = endsWith( str, 'fair', -34 );
|
|
|
118
147
|
|
|
119
148
|
<!-- /.examples -->
|
|
120
149
|
|
|
121
|
-
* * *
|
|
122
|
-
|
|
123
|
-
<section class="cli">
|
|
124
|
-
|
|
125
|
-
## CLI
|
|
126
|
-
|
|
127
|
-
<section class="installation">
|
|
128
|
-
|
|
129
|
-
## Installation
|
|
130
|
-
|
|
131
|
-
To use the module as a general utility, install the module globally
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
npm install -g @stdlib/string-ends-with
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
</section>
|
|
138
|
-
|
|
139
|
-
<!-- CLI usage documentation. -->
|
|
140
|
-
|
|
141
|
-
<section class="usage">
|
|
142
|
-
|
|
143
|
-
### Usage
|
|
144
|
-
|
|
145
|
-
```text
|
|
146
|
-
Usage: ends-with [options] --search=<string> [<string>]
|
|
147
|
-
|
|
148
|
-
Options:
|
|
149
|
-
|
|
150
|
-
-h, --help Print this message.
|
|
151
|
-
-V, --version Print the package version.
|
|
152
|
-
--search string Search string.
|
|
153
|
-
--len int Substring length.
|
|
154
|
-
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
</section>
|
|
158
|
-
|
|
159
|
-
<!-- /.usage -->
|
|
160
|
-
|
|
161
|
-
<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
162
|
-
|
|
163
|
-
<section class="notes">
|
|
164
|
-
|
|
165
|
-
### Notes
|
|
166
|
-
|
|
167
|
-
- If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
# Not escaped...
|
|
171
|
-
$ echo -n $'Hello, World!\nBeep Boop Baz' | ends-with --search=Beep --split /\r?\n/
|
|
172
|
-
|
|
173
|
-
# Escaped...
|
|
174
|
-
$ echo -n $'Hello, World!\nBeep Boop Baz' | ends-with --search=Beep --split /\\r?\\n/
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
- The implementation ignores trailing delimiters.
|
|
178
|
-
|
|
179
|
-
</section>
|
|
180
|
-
|
|
181
|
-
</section>
|
|
182
|
-
|
|
183
|
-
<!-- /.notes -->
|
|
184
|
-
|
|
185
|
-
<section class="examples">
|
|
186
|
-
|
|
187
|
-
### Examples
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
$ ends-with --search=ep beep
|
|
191
|
-
true
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
To use as a [standard stream][standard-streams],
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
$ echo -n 'boop' | ends-with --search=ep
|
|
198
|
-
false
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option.
|
|
202
|
-
|
|
203
|
-
```bash
|
|
204
|
-
$ echo -n 'Hello, World!\tBeep Boop' | ends-with --search=Boop --split '\t'
|
|
205
|
-
false
|
|
206
|
-
true
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
</section>
|
|
210
|
-
|
|
211
|
-
<!-- /.examples -->
|
|
212
|
-
|
|
213
|
-
</section>
|
|
214
150
|
|
|
215
|
-
<!-- /.cli -->
|
|
216
151
|
|
|
217
152
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
218
153
|
|
|
219
154
|
<section class="related">
|
|
220
155
|
|
|
221
|
-
* * *
|
|
222
|
-
|
|
223
156
|
## See Also
|
|
224
157
|
|
|
225
|
-
- <span class="package-name">[`@stdlib/string
|
|
158
|
+
- <span class="package-name">[`@stdlib/string-ends-with-cli`][@stdlib/string-ends-with-cli]</span><span class="delimiter">: </span><span class="description">CLI package for use as a command-line utility.</span>
|
|
159
|
+
- <span class="package-name">[`@stdlib/string-starts-with`][@stdlib/string/starts-with]</span><span class="delimiter">: </span><span class="description">test if a string starts with the characters of another string.</span>
|
|
226
160
|
|
|
227
161
|
</section>
|
|
228
162
|
|
|
@@ -254,7 +188,7 @@ See [LICENSE][stdlib-license].
|
|
|
254
188
|
|
|
255
189
|
## Copyright
|
|
256
190
|
|
|
257
|
-
Copyright © 2016-
|
|
191
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
258
192
|
|
|
259
193
|
</section>
|
|
260
194
|
|
|
@@ -264,11 +198,13 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
264
198
|
|
|
265
199
|
<section class="links">
|
|
266
200
|
|
|
201
|
+
[@stdlib/string-ends-with-cli]: https://www.npmjs.com/package/@stdlib/string-ends-with-cli
|
|
202
|
+
|
|
267
203
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/string-ends-with.svg
|
|
268
204
|
[npm-url]: https://npmjs.org/package/@stdlib/string-ends-with
|
|
269
205
|
|
|
270
|
-
[test-image]: https://github.com/stdlib-js/string-ends-with/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
271
|
-
[test-url]: https://github.com/stdlib-js/string-ends-with/actions/workflows/test.yml?query=branch:v0.0
|
|
206
|
+
[test-image]: https://github.com/stdlib-js/string-ends-with/actions/workflows/test.yml/badge.svg?branch=v0.2.0
|
|
207
|
+
[test-url]: https://github.com/stdlib-js/string-ends-with/actions/workflows/test.yml?query=branch:v0.2.0
|
|
272
208
|
|
|
273
209
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-ends-with/main.svg
|
|
274
210
|
[coverage-url]: https://codecov.io/github/stdlib-js/string-ends-with?branch=main
|
|
@@ -281,18 +217,25 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
281
217
|
-->
|
|
282
218
|
|
|
283
219
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
284
|
-
[chat-url]: https://gitter.im
|
|
220
|
+
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
|
|
285
221
|
|
|
286
222
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
287
223
|
|
|
288
224
|
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
289
225
|
|
|
226
|
+
[cli-section]: https://github.com/stdlib-js/string-ends-with#cli
|
|
227
|
+
[cli-url]: https://github.com/stdlib-js/string-ends-with/tree/cli
|
|
228
|
+
[@stdlib/string-ends-with]: https://github.com/stdlib-js/string-ends-with/tree/main
|
|
229
|
+
|
|
290
230
|
[umd]: https://github.com/umdjs/umd
|
|
291
231
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
292
232
|
|
|
293
233
|
[deno-url]: https://github.com/stdlib-js/string-ends-with/tree/deno
|
|
234
|
+
[deno-readme]: https://github.com/stdlib-js/string-ends-with/blob/deno/README.md
|
|
294
235
|
[umd-url]: https://github.com/stdlib-js/string-ends-with/tree/umd
|
|
236
|
+
[umd-readme]: https://github.com/stdlib-js/string-ends-with/blob/umd/README.md
|
|
295
237
|
[esm-url]: https://github.com/stdlib-js/string-ends-with/tree/esm
|
|
238
|
+
[esm-readme]: https://github.com/stdlib-js/string-ends-with/blob/esm/README.md
|
|
296
239
|
[branches-url]: https://github.com/stdlib-js/string-ends-with/blob/main/branches.md
|
|
297
240
|
|
|
298
241
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string-ends-with/main/LICENSE
|
|
@@ -301,6 +244,8 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
301
244
|
|
|
302
245
|
[mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
303
246
|
|
|
247
|
+
[mdn-string-endswith]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
|
|
248
|
+
|
|
304
249
|
<!-- <related-links> -->
|
|
305
250
|
|
|
306
251
|
[@stdlib/string/starts-with]: https://www.npmjs.com/package/@stdlib/string-starts-with
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=s(function(f,a){
|
|
2
|
+
var g=require('@stdlib/assert-is-integer/dist').isPrimitive,n=require('@stdlib/assert-is-string/dist').isPrimitive,t=require('@stdlib/error-tools-fmtprodmsg/dist'),m=require('@stdlib/string-base-ends-with/dist');function o(e,r,i){if(!n(e))throw new TypeError(t('1Od3F',e));if(!n(r))throw new TypeError(t('1Od39',r));if(arguments.length>2){if(!g(i))throw new TypeError(t('1Od2z',i))}else i=e.length;return m(e,r,i)}a.exports=o
|
|
3
|
+
});var v=u();module.exports=v;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-ends-with' );\n\n\n// MAIN //\n\n/**\n* Test if a string ends with the characters of another string.\n*\n* @param {string} str - input string\n* @param {string} search - search string\n* @param {integer} [len=str.length] - substring length\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument must be a string\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating if the input string ends with the search string\n*\n* @example\n* var bool = endsWith( 'Remember the story I used to tell you when you were a boy?', 'boy?' );\n* // returns true\n*\n* @example\n* var bool = endsWith( 'Remember the story I used to tell you when you were a boy?', 'Boy?' );\n* // returns false\n*\n* @example\n* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be' );\n* // returns false\n*\n* @example\n* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be', 19 );\n* // returns true\n*\n* @example\n* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be', -23 );\n* // returns true\n*/\nfunction endsWith( str, search, len ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( !isString( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( len ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', len ) );\n\t\t}\n\t} else {\n\t\tlen = str.length;\n\t}\n\treturn base( str, search, len );\n}\n\n\n// EXPORTS //\n\nmodule.exports = endsWith;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if a string ends with the characters of another string.\n*\n* @module @stdlib/string-ends-with\n*\n* @example\n* var endsWith = require( '@stdlib/string-ends-with' );\n*\n* var str = 'Fair is foul, and foul is fair, hover through fog and filthy air';\n*\n* var bool = endsWith( str, 'air' );\n* // returns true\n*\n* bool = endsWith( str, 'fair' );\n* // returns false\n*\n* bool = endsWith( str, 'fair', 30 );\n* // returns true\n*\n* bool = endsWith( str, 'fair', -34 );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,+BAAgC,EAoCpD,SAASC,EAAUC,EAAKC,EAAQC,EAAM,CACrC,GAAK,CAACN,EAAUI,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAK,CAACJ,EAAUK,CAAO,EACtB,MAAM,IAAI,UAAWJ,EAAQ,mEAAoEI,CAAO,CAAE,EAE3G,GAAK,UAAU,OAAS,GACvB,GAAK,CAACN,EAAWO,CAAI,EACpB,MAAM,IAAI,UAAWL,EAAQ,oEAAqEK,CAAI,CAAE,OAGzGA,EAAMF,EAAI,OAEX,OAAOF,EAAME,EAAKC,EAAQC,CAAI,CAC/B,CAKAR,EAAO,QAAUK,ICpCjB,IAAII,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isInteger", "isString", "format", "base", "endsWith", "str", "search", "len", "main"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -16,10 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
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`.
|
|
23
27
|
*
|
|
24
28
|
* @param str - input string
|
|
25
29
|
* @param search - search string
|
|
@@ -46,7 +50,7 @@
|
|
|
46
50
|
* var bool = endsWith( 'To be, or not to be, that is the question.', 'to be', -23 );
|
|
47
51
|
* // returns true
|
|
48
52
|
*/
|
|
49
|
-
declare function endsWith( str: string, search: string, len?: number ): boolean;
|
|
53
|
+
declare function endsWith( str: string, search: string, len?: number ): boolean;
|
|
50
54
|
|
|
51
55
|
|
|
52
56
|
// EXPORTS //
|
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
|
|
24
24
|
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
25
25
|
var format = require( '@stdlib/string-format' );
|
|
26
|
+
var base = require( '@stdlib/string-base-ends-with' );
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
// MAIN //
|
|
@@ -59,8 +60,6 @@ var format = require( '@stdlib/string-format' );
|
|
|
59
60
|
* // returns true
|
|
60
61
|
*/
|
|
61
62
|
function endsWith( str, search, len ) {
|
|
62
|
-
var idx;
|
|
63
|
-
var i;
|
|
64
63
|
if ( !isString( str ) ) {
|
|
65
64
|
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
|
|
66
65
|
}
|
|
@@ -71,31 +70,10 @@ function endsWith( str, search, len ) {
|
|
|
71
70
|
if ( !isInteger( len ) ) {
|
|
72
71
|
throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', len ) );
|
|
73
72
|
}
|
|
74
|
-
if ( len === 0 ) {
|
|
75
|
-
return ( search.length === 0 );
|
|
76
|
-
}
|
|
77
|
-
if ( len < 0 ) {
|
|
78
|
-
idx = str.length + len;
|
|
79
|
-
} else {
|
|
80
|
-
idx = len;
|
|
81
|
-
}
|
|
82
73
|
} else {
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if ( search.length === 0 ) {
|
|
86
|
-
// Based on the premise that every string can be "surrounded" by empty strings (e.g., "" + "a" + "" + "b" + "" === "ab"):
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
idx -= search.length;
|
|
90
|
-
if ( idx < 0 ) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
for ( i = 0; i < search.length; i++) {
|
|
94
|
-
if ( str.charCodeAt( idx + i ) !== search.charCodeAt( i ) ) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
74
|
+
len = str.length;
|
|
97
75
|
}
|
|
98
|
-
return
|
|
76
|
+
return base( str, search, len );
|
|
99
77
|
}
|
|
100
78
|
|
|
101
79
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/string-ends-with",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Test if a string ends with the characters of another string.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
|
-
"bin": {
|
|
17
|
-
"ends-with": "./bin/cli"
|
|
18
|
-
},
|
|
19
16
|
"main": "./lib",
|
|
20
17
|
"directories": {
|
|
21
18
|
"benchmark": "./benchmark",
|
|
@@ -40,29 +37,16 @@
|
|
|
40
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
41
38
|
},
|
|
42
39
|
"dependencies": {
|
|
43
|
-
"@stdlib/assert-is-integer": "^0.0
|
|
44
|
-
"@stdlib/assert-is-
|
|
45
|
-
"@stdlib/
|
|
46
|
-
"@stdlib/
|
|
47
|
-
"@stdlib/fs-read-file": "^0.0.x",
|
|
48
|
-
"@stdlib/process-read-stdin": "^0.0.x",
|
|
49
|
-
"@stdlib/regexp-eol": "^0.0.x",
|
|
50
|
-
"@stdlib/streams-node-stdin": "^0.0.x",
|
|
51
|
-
"@stdlib/string-format": "^0.0.x",
|
|
52
|
-
"@stdlib/utils-regexp-from-string": "^0.0.x"
|
|
40
|
+
"@stdlib/assert-is-integer": "^0.2.0",
|
|
41
|
+
"@stdlib/assert-is-string": "^0.2.0",
|
|
42
|
+
"@stdlib/string-base-ends-with": "^0.2.0",
|
|
43
|
+
"@stdlib/string-format": "^0.2.0"
|
|
53
44
|
},
|
|
54
45
|
"devDependencies": {
|
|
55
|
-
"@stdlib/assert-is-boolean": "^0.0.x",
|
|
56
|
-
"@stdlib/assert-is-browser": "^0.0.x",
|
|
57
|
-
"@stdlib/assert-is-windows": "^0.0.x",
|
|
58
|
-
"@stdlib/bench": "^0.0.x",
|
|
59
|
-
"@stdlib/process-exec-path": "^0.0.x",
|
|
60
|
-
"@stdlib/string-from-code-point": "^0.0.x",
|
|
61
|
-
"@stdlib/string-replace": "^0.0.x",
|
|
62
46
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
63
47
|
"proxyquire": "^2.0.0",
|
|
64
48
|
"istanbul": "^0.4.1",
|
|
65
|
-
"tap-
|
|
49
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
66
50
|
},
|
|
67
51
|
"engines": {
|
|
68
52
|
"node": ">=0.10.0",
|
|
@@ -95,7 +79,7 @@
|
|
|
95
79
|
"match"
|
|
96
80
|
],
|
|
97
81
|
"funding": {
|
|
98
|
-
"type": "
|
|
99
|
-
"url": "https://
|
|
82
|
+
"type": "opencollective",
|
|
83
|
+
"url": "https://opencollective.com/stdlib"
|
|
100
84
|
}
|
|
101
85
|
}
|
package/bin/cli
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @license Apache-2.0
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2018 The Stdlib Authors.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
// MODULES //
|
|
24
|
-
|
|
25
|
-
var resolve = require( 'path' ).resolve;
|
|
26
|
-
var readFileSync = require( '@stdlib/fs-read-file' ).sync;
|
|
27
|
-
var CLI = require( '@stdlib/cli-ctor' );
|
|
28
|
-
var stdin = require( '@stdlib/process-read-stdin' );
|
|
29
|
-
var stdinStream = require( '@stdlib/streams-node-stdin' );
|
|
30
|
-
var RE_EOL = require( '@stdlib/regexp-eol' ).REGEXP;
|
|
31
|
-
var isRegExpString = require( '@stdlib/assert-is-regexp-string' );
|
|
32
|
-
var reFromString = require( '@stdlib/utils-regexp-from-string' );
|
|
33
|
-
var endsWith = require( './../lib' );
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// MAIN //
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Main execution sequence.
|
|
40
|
-
*
|
|
41
|
-
* @private
|
|
42
|
-
* @returns {void}
|
|
43
|
-
*/
|
|
44
|
-
function main() {
|
|
45
|
-
var split;
|
|
46
|
-
var flags;
|
|
47
|
-
var args;
|
|
48
|
-
var cli;
|
|
49
|
-
var len;
|
|
50
|
-
var str;
|
|
51
|
-
|
|
52
|
-
// Create a command-line interface:
|
|
53
|
-
cli = new CLI({
|
|
54
|
-
'pkg': require( './../package.json' ),
|
|
55
|
-
'options': require( './../etc/cli_opts.json' ),
|
|
56
|
-
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
57
|
-
'encoding': 'utf8'
|
|
58
|
-
})
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Get any provided command-line options:
|
|
62
|
-
flags = cli.flags();
|
|
63
|
-
if ( flags.help || flags.version ) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Get any provided command-line arguments:
|
|
68
|
-
args = cli.args();
|
|
69
|
-
|
|
70
|
-
if ( args.length ) {
|
|
71
|
-
str = args[ 0 ];
|
|
72
|
-
} else {
|
|
73
|
-
// Treat an empty value as an empty string:
|
|
74
|
-
str = '';
|
|
75
|
-
}
|
|
76
|
-
if ( flags.len ) {
|
|
77
|
-
len = parseInt( flags.len, 10 );
|
|
78
|
-
} else {
|
|
79
|
-
len = str.length;
|
|
80
|
-
}
|
|
81
|
-
// Check if we are receiving data from `stdin`...
|
|
82
|
-
if ( !stdinStream.isTTY ) {
|
|
83
|
-
if ( flags.split ) {
|
|
84
|
-
if ( !isRegExpString( flags.split ) ) {
|
|
85
|
-
flags.split = '/'+flags.split+'/';
|
|
86
|
-
}
|
|
87
|
-
split = reFromString( flags.split );
|
|
88
|
-
} else {
|
|
89
|
-
split = RE_EOL;
|
|
90
|
-
}
|
|
91
|
-
return stdin( onRead );
|
|
92
|
-
}
|
|
93
|
-
console.log( endsWith( str, flags.search, len ) ); // eslint-disable-line no-console
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Callback invoked upon reading from `stdin`.
|
|
97
|
-
*
|
|
98
|
-
* @private
|
|
99
|
-
* @param {(Error|null)} error - error object
|
|
100
|
-
* @param {Buffer} data - data
|
|
101
|
-
* @returns {void}
|
|
102
|
-
*/
|
|
103
|
-
function onRead( error, data ) {
|
|
104
|
-
var lines;
|
|
105
|
-
var i;
|
|
106
|
-
if ( error ) {
|
|
107
|
-
return cli.error( error );
|
|
108
|
-
}
|
|
109
|
-
lines = data.toString().split( split );
|
|
110
|
-
|
|
111
|
-
// Remove any trailing separators (e.g., trailing newline)...
|
|
112
|
-
if ( lines[ lines.length-1 ] === '' ) {
|
|
113
|
-
lines.pop();
|
|
114
|
-
}
|
|
115
|
-
for ( i = 0; i < lines.length; i++ ) {
|
|
116
|
-
if ( !len ) {
|
|
117
|
-
len = lines[ i ].length;
|
|
118
|
-
}
|
|
119
|
-
console.log( endsWith( lines[ i ], flags.search, len ) ); // eslint-disable-line no-console
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
main();
|
package/docs/repl.txt
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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 (optional)
|
|
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`. Default: `str.length`.
|
|
20
|
-
|
|
21
|
-
Returns
|
|
22
|
-
-------
|
|
23
|
-
bool: boolean
|
|
24
|
-
Boolean indicating whether a `string` ends with the characters of
|
|
25
|
-
another `string`.
|
|
26
|
-
|
|
27
|
-
Examples
|
|
28
|
-
--------
|
|
29
|
-
> var bool = {{alias}}( 'beep', 'ep' )
|
|
30
|
-
true
|
|
31
|
-
> bool = {{alias}}( 'Beep', 'op' )
|
|
32
|
-
false
|
|
33
|
-
> bool = {{alias}}( 'Beep', 'ee', 3 )
|
|
34
|
-
true
|
|
35
|
-
> bool = {{alias}}( 'Beep', 'ee', -1 )
|
|
36
|
-
true
|
|
37
|
-
> bool = {{alias}}( 'beep', '' )
|
|
38
|
-
true
|
|
39
|
-
|
|
40
|
-
See Also
|
|
41
|
-
--------
|
|
42
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2019 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( 'abd', 'd' ); // $ExpectType boolean
|
|
27
|
-
endsWith( 'To be, or not to be, that is the question.', 'b', 19 ); // $ExpectType boolean
|
|
28
|
-
endsWith( 'abd', 'ab', 2 ); // $ExpectType boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// The function does not compile if provided arguments having invalid types...
|
|
32
|
-
{
|
|
33
|
-
endsWith( true, 'd' ); // $ExpectError
|
|
34
|
-
endsWith( false, 'd' ); // $ExpectError
|
|
35
|
-
endsWith( 3, 'd', 3 ); // $ExpectError
|
|
36
|
-
endsWith( [], 'd', 3 ); // $ExpectError
|
|
37
|
-
endsWith( {}, 'd', 3 ); // $ExpectError
|
|
38
|
-
endsWith( ( x: number ): number => x, 'd', 0 ); // $ExpectError
|
|
39
|
-
|
|
40
|
-
endsWith( 'abd', true ); // $ExpectError
|
|
41
|
-
endsWith( 'abd', false ); // $ExpectError
|
|
42
|
-
endsWith( 'abd', 5 ); // $ExpectError
|
|
43
|
-
endsWith( 'abd', [], 3 ); // $ExpectError
|
|
44
|
-
endsWith( 'abd', {}, 3 ); // $ExpectError
|
|
45
|
-
endsWith( 'abd', ( x: number ): number => x, 0 ); // $ExpectError
|
|
46
|
-
|
|
47
|
-
endsWith( 'abd', 'a', true ); // $ExpectError
|
|
48
|
-
endsWith( 'abd', 'a', false ); // $ExpectError
|
|
49
|
-
endsWith( 'abd', 'a', '5' ); // $ExpectError
|
|
50
|
-
endsWith( 'abd', 'b', [] ); // $ExpectError
|
|
51
|
-
endsWith( 'abd', 'b', {} ); // $ExpectError
|
|
52
|
-
endsWith( 'abd', 'b', /[a-z]/ ); // $ExpectError
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// The function does not compile if provided insufficient arguments...
|
|
56
|
-
{
|
|
57
|
-
endsWith(); // $ExpectError
|
|
58
|
-
endsWith( 'abc' ); // $ExpectError
|
|
59
|
-
}
|
package/docs/usage.txt
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Usage: ends-with [options] --search=<string> [<string>]
|
|
3
|
-
|
|
4
|
-
Options:
|
|
5
|
-
|
|
6
|
-
-h, --help Print this message.
|
|
7
|
-
-V, --version Print the package version.
|
|
8
|
-
--search string Search string.
|
|
9
|
-
--len int Substring length.
|
|
10
|
-
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
|