Skip to content

Commit 68f9f3d

Browse files
committed
Adding new defaults functionality
1 parent 0f0da95 commit 68f9f3d

File tree

7 files changed

+1100
-701
lines changed

7 files changed

+1100
-701
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ You can specify a gender by setting either `male` or `female` (or for convenienc
3636

3737
```javascript
3838
const Nomina = require('nomina');
39+
const nomina = new Nomina();
3940

4041
// specify options, none are required
4142
const options = {
@@ -44,10 +45,40 @@ const options = {
4445
};
4546

4647
// call the method
47-
const result = Nomina.generate(options);
48+
const result = nomina.generate(options);
4849

4950
// get all themes available
50-
const themes = Nomina.getThemes();
51+
const themes = nomina.getThemes();
52+
```
53+
54+
## Custom Configs
55+
There are a couple of ways you can configure the themes that the tool uses:
56+
57+
### CLI Config
58+
The CLI checks for `~/.dnd/nomina/defaults.js` before loading any other configuration. Simply add a file here while using the tool and you can customize the themes.
59+
60+
### Class Config
61+
You can pass a "defaults" config directly to the class on initialization:
62+
63+
```javascript
64+
const Nomina = require('nomina');
65+
const defaults = {
66+
themes: {
67+
myCustomTheme: {
68+
male: [],
69+
female: [],
70+
dominia: [],
71+
},
72+
myOtherCustomTheme: {
73+
male: [],
74+
female: [],
75+
dominia: [],
76+
},
77+
},
78+
};
79+
80+
const nomina = new Nomina({ defaults });
81+
const themes = nomina.getThemes(); // ['myCustomTheme', 'myOtherCustomTheme']
5182
```
5283

5384
## Developing

lib/nomina.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ const Generator = require(path.join(libDir, 'generator'));
66

77
// create nomina
88
class Nomina {
9+
// init
10+
constructor(opts = {}) {
11+
this.defaults = opts.defaults || defaults;
12+
}
13+
914
// list themes
10-
static getThemes() {
11-
return Object.keys(defaults.themes);
15+
getThemes() {
16+
return Object.keys(this.defaults.themes);
1217
}
1318

1419
// generate
15-
static generate(opts = {}) {
20+
generate(opts = {}) {
1621
const themes = this.getThemes();
1722
const number = opts.number || 1;
1823
const theme = opts.theme || themes.sample();
1924
const type = opts.type || ['female', 'male', 'dominia'].sample();
20-
const set = defaults.themes[theme][type];
25+
const set = this.defaults.themes[theme][type];
2126
const nameSet = { default: set };
2227
const generator = new Generator();
2328
generator.nameSet = nameSet;

lib/program-list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ const path = require('path');
22
const rootDir = path.join(__dirname, '..');
33
const libDir = path.join(rootDir, 'lib');
44
const Nomina = require(path.join(libDir, 'nomina'));
5+
const nomina = new Nomina();
56

67
process.stdout.write('Here are the available types:\n');
78

8-
Nomina.getThemes().forEach((name) => {
9+
nomina.getThemes().forEach((name) => {
910
process.stdout.write(` - ${name}\n`);
1011
});

lib/program.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const rootDir = path.join(__dirname, '..');
44
const libDir = path.join(rootDir, 'lib');
55
const pinfo = require(path.join(rootDir, 'package.json'));
66
const Nomina = require(path.join(libDir, 'nomina'));
7+
const nomina = new Nomina();
78

89
// program basics
910
program
@@ -53,7 +54,7 @@ if (program.args.indexOf('list') < 0) {
5354
opts.number = numberValue;
5455
}
5556

56-
const result = Nomina.generate(opts);
57+
const result = nomina.generate(opts);
5758

5859
if (Array.isArray(result)) {
5960
result.forEach((name) => {

0 commit comments

Comments
 (0)