@stdlib/string-constantcase 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
  # constantcase
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
  > Returns a string converted to a constant case.
26
26
 
@@ -63,7 +63,6 @@ str = constantcase( 'foo_bar' );
63
63
 
64
64
  <!-- /.usage -->
65
65
 
66
-
67
66
  <!-- Package usage examples. -->
68
67
 
69
68
  <section class="examples">
@@ -98,7 +97,6 @@ out = constantcase( str );
98
97
 
99
98
  <!-- /.examples -->
100
99
 
101
-
102
100
  * * *
103
101
 
104
102
  <section class="cli">
@@ -117,6 +115,8 @@ npm install -g @stdlib/string-constantcase
117
115
 
118
116
  </section>
119
117
 
118
+ <!-- CLI usage documentation. -->
119
+
120
120
  <section class="usage">
121
121
 
122
122
  ### Usage
@@ -128,12 +128,35 @@ Options:
128
128
 
129
129
  -h, --help Print this message.
130
130
  -V, --version Print the package version.
131
+ --split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
131
132
  ```
132
133
 
133
134
  </section>
134
135
 
135
136
  <!-- /.usage -->
136
137
 
138
+ <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
139
+
140
+ <section class="notes">
141
+
142
+ ### Notes
143
+
144
+ - If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
145
+
146
+ ```bash
147
+ # Not escaped...
148
+ $ echo -n $'beEp booP\nisMobile' | constantcase --split /\r?\n/
149
+
150
+ # Escaped...
151
+ $ echo -n $'beEp booP\nisMobile' | constantcase --split /\\r?\\n/
152
+ ```
153
+
154
+ - The implementation ignores trailing delimiters.
155
+
156
+ </section>
157
+
158
+ <!-- /.notes -->
159
+
137
160
  <section class="examples">
138
161
 
139
162
  ### Examples
@@ -150,6 +173,21 @@ $ echo -n 'beEp booP' | constantcase
150
173
  BEEP_BOOP
151
174
  ```
152
175
 
176
+ To use as a [standard stream][standard-streams],
177
+
178
+ ```bash
179
+ $ echo -n 'isMobile' | constantcase
180
+ IS_MOBILE
181
+ ```
182
+
183
+ 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.
184
+
185
+ ```bash
186
+ $ echo -n 'beep_boop\tisMobile' | constantcase --split '\t'
187
+ BEEP_BOOP
188
+ IS_MOBILE
189
+ ```
190
+
153
191
  </section>
154
192
 
155
193
  <!-- /.examples -->
@@ -158,6 +196,25 @@ BEEP_BOOP
158
196
 
159
197
  <!-- /.cli -->
160
198
 
199
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
200
+
201
+ <section class="related">
202
+
203
+ * * *
204
+
205
+ ## See Also
206
+
207
+ - <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>
208
+ - <span class="package-name">[`@stdlib/string/kebabcase`][@stdlib/string/kebabcase]</span><span class="delimiter">: </span><span class="description">convert a string to kebab case.</span>
209
+ - <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>
210
+ - <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>
211
+
212
+ </section>
213
+
214
+ <!-- /.related -->
215
+
216
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
217
+
161
218
 
162
219
  <section class="main-repo" >
163
220
 
@@ -182,7 +239,7 @@ See [LICENSE][stdlib-license].
182
239
 
183
240
  ## Copyright
184
241
 
185
- Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
242
+ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
186
243
 
187
244
  </section>
188
245
 
@@ -201,9 +258,20 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
201
258
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-constantcase/main.svg
202
259
  [coverage-url]: https://codecov.io/github/stdlib-js/string-constantcase?branch=main
203
260
 
261
+ <!--
262
+
204
263
  [dependencies-image]: https://img.shields.io/david/stdlib-js/string-constantcase.svg
205
264
  [dependencies-url]: https://david-dm.org/stdlib-js/string-constantcase/main
206
265
 
266
+ -->
267
+
268
+ [umd]: https://github.com/umdjs/umd
269
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
270
+
271
+ [deno-url]: https://github.com/stdlib-js/string-constantcase/tree/deno
272
+ [umd-url]: https://github.com/stdlib-js/string-constantcase/tree/umd
273
+ [esm-url]: https://github.com/stdlib-js/string-constantcase/tree/esm
274
+
207
275
  [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
208
276
  [chat-url]: https://gitter.im/stdlib-js/stdlib/
209
277
 
@@ -215,6 +283,20 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
215
283
 
216
284
  [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
217
285
 
286
+ [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
287
+
288
+ <!-- <related-links> -->
289
+
290
+ [@stdlib/string/camelcase]: https://www.npmjs.com/package/@stdlib/string-camelcase
291
+
292
+ [@stdlib/string/kebabcase]: https://www.npmjs.com/package/@stdlib/string-kebabcase
293
+
294
+ [@stdlib/string/pascalcase]: https://www.npmjs.com/package/@stdlib/string-pascalcase
295
+
296
+ [@stdlib/string/snakecase]: https://www.npmjs.com/package/@stdlib/string-snakecase
297
+
298
+ <!-- </related-links> -->
299
+
218
300
  </section>
219
301
 
220
302
  <!-- /.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 constantcase = require( './../lib' );
32
34
 
33
35
 
@@ -40,6 +42,7 @@ var constantcase = 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( constantcase( 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( constantcase( 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/string-constantcase",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Convert a string to constant 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-replace": "^0.0.x",
50
51
  "@stdlib/string-trim": "^0.0.x",
51
- "@stdlib/string-uppercase": "^0.0.x"
52
+ "@stdlib/string-uppercase": "^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",