Skip to content

Commit b1f5754

Browse files
committed
fix: added missing examples
1 parent d329d40 commit b1f5754

6 files changed

Lines changed: 458 additions & 0 deletions

File tree

07-creational-design-patterns/04-factory-example-profiler/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ node index.js 2201307499
1414
NODE_ENV=production node index.js 2201307499
1515
```
1616

17+
or, if you are not using a Unix-like OS:
18+
19+
```bash
20+
npx cross-env NODE_ENV=production node index.js 2201307499
21+
```
22+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 06b-builder-in-the-wild
2+
3+
This example contains a couple of usages of the builder pattern in the wild.
4+
5+
## Dependencies
6+
7+
This example requires you to install some third-party dependencies from npm.
8+
9+
If you have `pnpm` installed, you can do that with:
10+
11+
```bash
12+
pnpm install
13+
```
14+
15+
Alternatively, if you prefer to use another package manager, make sure to delete
16+
the `pnpm-lock.yaml` file before using it.
17+
18+
If you want to use `npm`, you can run:
19+
20+
```bash
21+
npm install
22+
```
23+
24+
If you want to use `yarn`, you can run:
25+
26+
```bash
27+
yarn install
28+
```
29+
30+
## Run
31+
32+
To run the examples launch:
33+
34+
```bash
35+
node superagent.js
36+
```
37+
38+
and
39+
40+
```bash
41+
node cli.js --separator "," "Hello, World"
42+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Command } from 'commander' // v14.0.0
2+
3+
const program = new Command()
4+
program
5+
.name('string-util')
6+
.description('CLI to some JavaScript string utilities')
7+
.version('0.8.0')
8+
.command('split')
9+
.description('Split a string into substrings and display as an array')
10+
.argument('<string>', 'string to split')
11+
.option('--first', 'display just the first substring')
12+
.option('-s, --separator <char>', 'separator character', ',')
13+
.action((str, options) => {
14+
const limit = options.first ? 1 : undefined
15+
console.log(str.split(options.separator, limit))
16+
})
17+
.parse()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "06b-builder-in-the-wild",
3+
"version": "1.0.0",
4+
"description": "This example contains a couple of usages of the builder pattern in the wild.",
5+
"type": "module",
6+
"scripts": {},
7+
"engines": {
8+
"node": ">=24"
9+
},
10+
"engineStrict": true,
11+
"keywords": [],
12+
"author": "Luciano Mammino and Mario Casciaro",
13+
"license": "MIT",
14+
"dependencies": {
15+
"commander": "14.0.0",
16+
"superagent": "^10.1.1"
17+
}
18+
}

0 commit comments

Comments
 (0)