Skip to content
Myr

string-util.js

This file

Path

examples/string-util.js

38 lines · 1.2 KiB · JavaScript

Last changed by

Merge from develop (#2482)John Geebefore adoptionb51c0ea

History of this file

Take it

The walk stopped after 200 commits: lines older than 3103c6b point at it.

Use standard import in examples (#2168)John Geebefore adoption41b12cf

line 1why, one step back
1const { Command } = require('commander');

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 2–10why, one step back
2const program = new Command();
34// This is used as an example in the README for the Quick Start.56program7 .name('string-util')8 .description('CLI to some JavaScript string utilities')9 .version('0.8.0');10

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 11–12why, one step back
11program
12 .command('split')

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 13–21why, one step back
13 .description('Split a string into substrings and display as an array.')
14 .argument('<string>', 'string to split')15 .option('--first', 'display just the first substring')16 .option('-s, --separator <char>', 'separator character', ',')17 .action((str, options) => {18 const limit = options.first ? 1 : undefined;19 console.log(str.split(options.separator, limit));20 });21

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 22–23why, one step back
22program
23 .command('join')

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 24–35why, one step back
24 .description('Join the command-arguments into a single string')
25 .argument('<strings...>', 'one or more strings')26 .option('-s, --separator <char>', 'separator character', ',')27 .action((strings, options) => {28 console.log(strings.join(options.separator));29 });3031program.parse();3233// Try the following:34// node string-util35// node string-util help split

Merge from develop (#2482)John Geebefore adoptionb51c0ea

line 36why, one step back
36// node string-util split --separator=- a-b-c

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 37–38why, one step back
37// node string-util split --first a,b,c
38// node string-util join a b c d