@stdlib/string-kebabcase 0.0.2 → 0.0.3

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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2021 The Stdlib Authors.
1
+ Copyright (c) 2016-2022 The Stdlib Authors.
package/README.md CHANGED
@@ -20,7 +20,7 @@ limitations under the License.
20
20
 
21
21
  # kebabcase
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
  > Convert a string to kebab case.
26
26
 
@@ -63,7 +63,6 @@ str = kebabcase( 'Hello World!' );
63
63
 
64
64
  <!-- /.usage -->
65
65
 
66
-
67
66
  <!-- Package usage examples. -->
68
67
 
69
68
  <section class="examples">
@@ -102,7 +101,6 @@ out = kebabcase( str );
102
101
 
103
102
  <!-- /.examples -->
104
103
 
105
-
106
104
  * * *
107
105
 
108
106
  <section class="cli">
@@ -121,6 +119,8 @@ npm install -g @stdlib/string-kebabcase
121
119
 
122
120
  </section>
123
121
 
122
+ <!-- CLI usage documentation. -->
123
+
124
124
  <section class="usage">
125
125
 
126
126
  ### Usage
@@ -132,12 +132,35 @@ Options:
132
132
 
133
133
  -h, --help Print this message.
134
134
  -V, --version Print the package version.
135
+ --split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
135
136
  ```
136
137
 
137
138
  </section>
138
139
 
139
140
  <!-- /.usage -->
140
141
 
142
+ <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
143
+
144
+ <section class="notes">
145
+
146
+ ### Notes
147
+
148
+ - If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
149
+
150
+ ```bash
151
+ # Not escaped...
152
+ $ echo -n $'beEp booP\nisMobile' | kebabcase --split /\r?\n/
153
+
154
+ # Escaped...
155
+ $ echo -n $'beEp booP\nisMobile' | kebabcase --split /\\r?\\n/
156
+ ```
157
+
158
+ - The implementation ignores trailing delimiters.
159
+
160
+ </section>
161
+
162
+ <!-- /.notes -->
163
+
141
164
  <section class="examples">
142
165
 
143
166
  ### Examples
@@ -154,6 +177,14 @@ $ echo -n 'beEp booP' | kebabcase
154
177
  beep-boop
155
178
  ```
156
179
 
180
+ 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.
181
+
182
+ ```bash
183
+ $ echo -n 'beep_boop\tisMobile' | kebabcase --split '\t'
184
+ beep-boop
185
+ is-mobile
186
+ ```
187
+
157
188
  </section>
158
189
 
159
190
  <!-- /.examples -->
@@ -162,6 +193,25 @@ beep-boop
162
193
 
163
194
  <!-- /.cli -->
164
195
 
196
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
197
+
198
+ <section class="related">
199
+
200
+ * * *
201
+
202
+ ## See Also
203
+
204
+ - <span class="package-name">[`@stdlib/string/camelcase`][@stdlib/string/camelcase]</span><span class="delimiter">: </span><span class="description">convert a string to camel case.</span>
205
+ - <span class="package-name">[`@stdlib/string/constantcase`][@stdlib/string/constantcase]</span><span class="delimiter">: </span><span class="description">convert a string to constant case.</span>
206
+ - <span class="package-name">[`@stdlib/string/pascalcase`][@stdlib/string/pascalcase]</span><span class="delimiter">: </span><span class="description">convert a string to Pascal case.</span>
207
+ - <span class="package-name">[`@stdlib/string/snakecase`][@stdlib/string/snakecase]</span><span class="delimiter">: </span><span class="description">convert a string to snake case.</span>
208
+
209
+ </section>
210
+
211
+ <!-- /.related -->
212
+
213
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
214
+
165
215
 
166
216
  <section class="main-repo" >
167
217
 
@@ -186,7 +236,7 @@ See [LICENSE][stdlib-license].
186
236
 
187
237
  ## Copyright
188
238
 
189
- Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
239
+ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
190
240
 
191
241
  </section>
192
242
 
@@ -205,9 +255,20 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
205
255
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-kebabcase/main.svg
206
256
  [coverage-url]: https://codecov.io/github/stdlib-js/string-kebabcase?branch=main
207
257
 
258
+ <!--
259
+
208
260
  [dependencies-image]: https://img.shields.io/david/stdlib-js/string-kebabcase.svg
209
261
  [dependencies-url]: https://david-dm.org/stdlib-js/string-kebabcase/main
210
262
 
263
+ -->
264
+
265
+ [umd]: https://github.com/umdjs/umd
266
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
267
+
268
+ [deno-url]: https://github.com/stdlib-js/string-kebabcase/tree/deno
269
+ [umd-url]: https://github.com/stdlib-js/string-kebabcase/tree/umd
270
+ [esm-url]: https://github.com/stdlib-js/string-kebabcase/tree/esm
271
+
211
272
  [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
212
273
  [chat-url]: https://gitter.im/stdlib-js/stdlib/
213
274
 
@@ -219,6 +280,20 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
219
280
 
220
281
  [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
221
282
 
283
+ [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
284
+
285
+ <!-- <related-links> -->
286
+
287
+ [@stdlib/string/camelcase]: https://www.npmjs.com/package/@stdlib/string-camelcase
288
+
289
+ [@stdlib/string/constantcase]: https://www.npmjs.com/package/@stdlib/string-constantcase
290
+
291
+ [@stdlib/string/pascalcase]: https://www.npmjs.com/package/@stdlib/string-pascalcase
292
+
293
+ [@stdlib/string/snakecase]: https://www.npmjs.com/package/@stdlib/string-snakecase
294
+
295
+ <!-- </related-links> -->
296
+
222
297
  </section>
223
298
 
224
299
  <!-- /.links -->
package/bin/cli CHANGED
@@ -27,7 +27,9 @@ var readFileSync = require( '@stdlib/fs-read-file' ).sync;
27
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 reEOL = require( '@stdlib/regexp-eol' );
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 kebabcase = require( './../lib' );
32
34
 
33
35
 
@@ -40,6 +42,7 @@ var kebabcase = 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;
@@ -64,6 +67,14 @@ function main() {
64
67
 
65
68
  // Check if we are receiving data from `stdin`...
66
69
  if ( !stdinStream.isTTY ) {
70
+ if ( flags.split ) {
71
+ if ( !isRegExpString( flags.split ) ) {
72
+ flags.split = '/'+flags.split+'/';
73
+ }
74
+ split = reFromString( flags.split );
75
+ } else {
76
+ split = RE_EOL;
77
+ }
67
78
  return stdin( onRead );
68
79
  }
69
80
  console.log( kebabcase( args[ 0 ] ) ); // eslint-disable-line no-console
@@ -82,7 +93,12 @@ function main() {
82
93
  if ( error ) {
83
94
  return cli.error( error );
84
95
  }
85
- lines = data.toString().split( reEOL.REGEXP );
96
+ lines = data.toString().split( split );
97
+
98
+ // Remove any trailing separators (e.g., trailing newline)...
99
+ if ( lines[ lines.length-1 ] === '' ) {
100
+ lines.pop();
101
+ }
86
102
  for ( i = 0; i < lines.length; i++ ) {
87
103
  console.log( kebabcase( lines[ i ] ) ); // eslint-disable-line no-console
88
104
  }
package/docs/usage.txt CHANGED
@@ -5,3 +5,4 @@ Options:
5
5
 
6
6
  -h, --help Print this message.
7
7
  -V, --version Print the package version.
8
+ --split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
package/etc/cli_opts.json CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
+ "string": [
3
+ "split"
4
+ ],
2
5
  "boolean": [
3
6
  "help",
4
7
  "version"
package/lib/main.js CHANGED
@@ -76,4 +76,4 @@ function kebabCase( str ) {
76
76
 
77
77
  // EXPORTS //
78
78
 
79
- module.exports= kebabCase;
79
+ module.exports = kebabCase;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/string-kebabcase",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Convert a string to kebab case.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -40,6 +40,7 @@
40
40
  "url": "https://github.com/stdlib-js/stdlib/issues"
41
41
  },
42
42
  "dependencies": {
43
+ "@stdlib/assert-is-regexp-string": "^0.0.x",
43
44
  "@stdlib/assert-is-string": "^0.0.x",
44
45
  "@stdlib/cli-ctor": "^0.0.x",
45
46
  "@stdlib/fs-read-file": "^0.0.x",
@@ -48,7 +49,8 @@
48
49
  "@stdlib/streams-node-stdin": "^0.0.x",
49
50
  "@stdlib/string-lowercase": "^0.0.x",
50
51
  "@stdlib/string-replace": "^0.0.x",
51
- "@stdlib/string-trim": "^0.0.x"
52
+ "@stdlib/string-trim": "^0.0.x",
53
+ "@stdlib/utils-regexp-from-string": "^0.0.x"
52
54
  },
53
55
  "devDependencies": {
54
56
  "@stdlib/assert-is-browser": "^0.0.x",