string-util.js
This file
Path
examples/string-util.js
38 lines · 1.1 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 1why, one step back1import { Command } from 'commander';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 2–10why, one step back2const 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');10Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 11–12why, one step back11program12 .command('split')Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 13–21why, one step back13 .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 });21Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 22–23why, one step back22program23 .command('join')Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 24–35why, one step back24 .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 splitMerge from develop (#2482)John Geebefore adoptionb51c0ea
line 36why, one step back36// node string-util split --separator=- a-b-cAdd copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 37–38why, one step back37// node string-util split --first a,b,c38// node string-util join a b c d