@stdlib/string-ends-with 0.0.4 → 0.0.8
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 +72 -2
- package/bin/cli +19 -3
- package/docs/usage.txt +1 -0
- package/etc/cli_opts.json +2 -1
- package/package.json +5 -4
- package/CHANGELOG.md +0 -5
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2022 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# endsWith
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> Test if a string ends with the characters of another string.
|
|
26
26
|
|
|
@@ -136,6 +136,8 @@ npm install -g @stdlib/string-ends-with
|
|
|
136
136
|
|
|
137
137
|
</section>
|
|
138
138
|
|
|
139
|
+
<!-- CLI usage documentation. -->
|
|
140
|
+
|
|
139
141
|
<section class="usage">
|
|
140
142
|
|
|
141
143
|
### Usage
|
|
@@ -149,12 +151,37 @@ Options:
|
|
|
149
151
|
-V, --version Print the package version.
|
|
150
152
|
--search string Search string.
|
|
151
153
|
--len int Substring length.
|
|
154
|
+
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
|
|
152
155
|
```
|
|
153
156
|
|
|
154
157
|
</section>
|
|
155
158
|
|
|
156
159
|
<!-- /.usage -->
|
|
157
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
|
+
|
|
158
185
|
<section class="examples">
|
|
159
186
|
|
|
160
187
|
### Examples
|
|
@@ -171,6 +198,14 @@ $ echo -n 'boop' | ends-with --search=ep
|
|
|
171
198
|
false
|
|
172
199
|
```
|
|
173
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
|
+
|
|
174
209
|
</section>
|
|
175
210
|
|
|
176
211
|
<!-- /.examples -->
|
|
@@ -179,6 +214,22 @@ false
|
|
|
179
214
|
|
|
180
215
|
<!-- /.cli -->
|
|
181
216
|
|
|
217
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
218
|
+
|
|
219
|
+
<section class="related">
|
|
220
|
+
|
|
221
|
+
* * *
|
|
222
|
+
|
|
223
|
+
## See Also
|
|
224
|
+
|
|
225
|
+
- <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
|
+
|
|
227
|
+
</section>
|
|
228
|
+
|
|
229
|
+
<!-- /.related -->
|
|
230
|
+
|
|
231
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
232
|
+
|
|
182
233
|
|
|
183
234
|
<section class="main-repo" >
|
|
184
235
|
|
|
@@ -203,7 +254,7 @@ See [LICENSE][stdlib-license].
|
|
|
203
254
|
|
|
204
255
|
## Copyright
|
|
205
256
|
|
|
206
|
-
Copyright © 2016-
|
|
257
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
207
258
|
|
|
208
259
|
</section>
|
|
209
260
|
|
|
@@ -222,9 +273,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
222
273
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-ends-with/main.svg
|
|
223
274
|
[coverage-url]: https://codecov.io/github/stdlib-js/string-ends-with?branch=main
|
|
224
275
|
|
|
276
|
+
<!--
|
|
277
|
+
|
|
225
278
|
[dependencies-image]: https://img.shields.io/david/stdlib-js/string-ends-with.svg
|
|
226
279
|
[dependencies-url]: https://david-dm.org/stdlib-js/string-ends-with/main
|
|
227
280
|
|
|
281
|
+
-->
|
|
282
|
+
|
|
283
|
+
[umd]: https://github.com/umdjs/umd
|
|
284
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
285
|
+
|
|
286
|
+
[deno-url]: https://github.com/stdlib-js/string-ends-with/tree/deno
|
|
287
|
+
[umd-url]: https://github.com/stdlib-js/string-ends-with/tree/umd
|
|
288
|
+
[esm-url]: https://github.com/stdlib-js/string-ends-with/tree/esm
|
|
289
|
+
|
|
228
290
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
229
291
|
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
230
292
|
|
|
@@ -236,6 +298,14 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
236
298
|
|
|
237
299
|
[standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
|
|
238
300
|
|
|
301
|
+
[mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
302
|
+
|
|
303
|
+
<!-- <related-links> -->
|
|
304
|
+
|
|
305
|
+
[@stdlib/string/starts-with]: https://www.npmjs.com/package/@stdlib/string-starts-with
|
|
306
|
+
|
|
307
|
+
<!-- </related-links> -->
|
|
308
|
+
|
|
239
309
|
</section>
|
|
240
310
|
|
|
241
311
|
<!-- /.links -->
|
package/bin/cli
CHANGED
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
var resolve = require( 'path' ).resolve;
|
|
26
26
|
var readFileSync = require( '@stdlib/fs-read-file' ).sync;
|
|
27
|
-
var CLI = require( '@stdlib/cli' );
|
|
27
|
+
var CLI = require( '@stdlib/cli-ctor' );
|
|
28
28
|
var stdin = require( '@stdlib/process-read-stdin' );
|
|
29
29
|
var stdinStream = require( '@stdlib/streams-node-stdin' );
|
|
30
|
-
var
|
|
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' );
|
|
31
33
|
var endsWith = require( './../lib' );
|
|
32
34
|
|
|
33
35
|
|
|
@@ -40,6 +42,7 @@ var endsWith = require( './../lib' );
|
|
|
40
42
|
* @returns {void}
|
|
41
43
|
*/
|
|
42
44
|
function main() {
|
|
45
|
+
var split;
|
|
43
46
|
var flags;
|
|
44
47
|
var args;
|
|
45
48
|
var cli;
|
|
@@ -77,6 +80,14 @@ function main() {
|
|
|
77
80
|
}
|
|
78
81
|
// Check if we are receiving data from `stdin`...
|
|
79
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
|
+
}
|
|
80
91
|
return stdin( onRead );
|
|
81
92
|
}
|
|
82
93
|
console.log( endsWith( str, flags.search, len ) ); // eslint-disable-line no-console
|
|
@@ -95,7 +106,12 @@ function main() {
|
|
|
95
106
|
if ( error ) {
|
|
96
107
|
return cli.error( error );
|
|
97
108
|
}
|
|
98
|
-
lines = data.toString().split(
|
|
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
|
+
}
|
|
99
115
|
for ( i = 0; i < lines.length; i++ ) {
|
|
100
116
|
if ( !len ) {
|
|
101
117
|
len = lines[ i ].length;
|
package/docs/usage.txt
CHANGED
package/etc/cli_opts.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/string-ends-with",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Test if a string ends with the characters of another string.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"main": "./lib",
|
|
20
20
|
"directories": {
|
|
21
21
|
"benchmark": "./benchmark",
|
|
22
|
-
"bin": "./bin",
|
|
23
22
|
"doc": "./docs",
|
|
24
23
|
"example": "./examples",
|
|
25
24
|
"lib": "./lib",
|
|
@@ -42,12 +41,14 @@
|
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
43
|
"@stdlib/assert-is-integer": "^0.0.x",
|
|
44
|
+
"@stdlib/assert-is-regexp-string": "^0.0.x",
|
|
45
45
|
"@stdlib/assert-is-string": "^0.0.x",
|
|
46
|
-
"@stdlib/cli": "^0.0.x",
|
|
46
|
+
"@stdlib/cli-ctor": "^0.0.x",
|
|
47
47
|
"@stdlib/fs-read-file": "^0.0.x",
|
|
48
48
|
"@stdlib/process-read-stdin": "^0.0.x",
|
|
49
49
|
"@stdlib/regexp-eol": "^0.0.x",
|
|
50
|
-
"@stdlib/streams-node-stdin": "^0.0.x"
|
|
50
|
+
"@stdlib/streams-node-stdin": "^0.0.x",
|
|
51
|
+
"@stdlib/utils-regexp-from-string": "^0.0.x"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@stdlib/assert-is-boolean": "^0.0.x",
|