dicebear 10.0.0-rc.4 → 10.0.0
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/lib/index.js +1 -3
- package/lib/utils/addStyleCommand.js +1 -3
- package/lib/utils/extractStyleOptions.js +14 -7
- package/lib/utils/getStyleCommandOptions.js +12 -0
- package/lib/utils/handleStyleCommand.js +5 -2
- package/lib/utils/loadStyles.d.ts +1 -1
- package/lib/utils/loadStyles.js +2 -2
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -34,9 +34,7 @@ import { getStyleCommandOptions } from './utils/getStyleCommandOptions.js';
|
|
|
34
34
|
process.exit(1);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return yargs
|
|
38
|
-
.default('outputPath', '.')
|
|
39
|
-
.options(options);
|
|
37
|
+
return yargs.default('outputPath', '.').options(options);
|
|
40
38
|
},
|
|
41
39
|
handler: async (argv) => {
|
|
42
40
|
try {
|
|
@@ -11,9 +11,7 @@ export function addStyleCommand(cli, name, style) {
|
|
|
11
11
|
command: `${name} [outputPath]`,
|
|
12
12
|
describe: `Generate "${name}" avatar(s)`,
|
|
13
13
|
builder: (yargs) => {
|
|
14
|
-
return yargs
|
|
15
|
-
.default('outputPath', '.')
|
|
16
|
-
.options(options);
|
|
14
|
+
return yargs.default('outputPath', '.').options(options);
|
|
17
15
|
},
|
|
18
16
|
handler: async (argv) => {
|
|
19
17
|
try {
|
|
@@ -16,15 +16,22 @@ function parseWeightedValue(value) {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Parses a comma-separated string like `"10,50"` into a `[min, max]` tuple
|
|
19
|
-
* for range options
|
|
20
|
-
*
|
|
19
|
+
* for range options, or a single numeric string like `"50"` into a number.
|
|
20
|
+
* Passes the value through unchanged when it matches neither form.
|
|
21
21
|
*/
|
|
22
22
|
function parseRangeValue(value) {
|
|
23
|
-
if (typeof value
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const parts = value.split(',').map((part) => Number(part.trim()));
|
|
27
|
+
if (!parts.every((n) => !isNaN(n))) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
if (parts.length === 1) {
|
|
31
|
+
return parts[0];
|
|
32
|
+
}
|
|
33
|
+
if (parts.length === 2) {
|
|
34
|
+
return parts;
|
|
28
35
|
}
|
|
29
36
|
return value;
|
|
30
37
|
}
|
|
@@ -33,9 +33,15 @@ export function getStyleCommandOptions(style) {
|
|
|
33
33
|
switch (field.type) {
|
|
34
34
|
case 'string':
|
|
35
35
|
option.type = 'string';
|
|
36
|
+
if (field.list) {
|
|
37
|
+
option.array = true;
|
|
38
|
+
}
|
|
36
39
|
break;
|
|
37
40
|
case 'number':
|
|
38
41
|
option.type = 'number';
|
|
42
|
+
if (field.list) {
|
|
43
|
+
option.array = true;
|
|
44
|
+
}
|
|
39
45
|
break;
|
|
40
46
|
case 'range':
|
|
41
47
|
option.type = 'string';
|
|
@@ -45,12 +51,18 @@ export function getStyleCommandOptions(style) {
|
|
|
45
51
|
break;
|
|
46
52
|
case 'enum':
|
|
47
53
|
option.type = 'string';
|
|
54
|
+
if (field.list) {
|
|
55
|
+
option.array = true;
|
|
56
|
+
}
|
|
48
57
|
if (!field.weighted) {
|
|
49
58
|
option.choices = field.values;
|
|
50
59
|
}
|
|
51
60
|
break;
|
|
52
61
|
case 'color':
|
|
53
62
|
option.type = 'string';
|
|
63
|
+
if (field.list) {
|
|
64
|
+
option.array = true;
|
|
65
|
+
}
|
|
54
66
|
break;
|
|
55
67
|
}
|
|
56
68
|
result[key] = option;
|
|
@@ -37,7 +37,7 @@ export async function handleStyleCommand(argv, name, style) {
|
|
|
37
37
|
try {
|
|
38
38
|
const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${format}`);
|
|
39
39
|
const seed = count <= 1
|
|
40
|
-
? (_a = argv.seed) !== null && _a !== void 0 ? _a : createRandomSeed()
|
|
40
|
+
? ((_a = argv.seed) !== null && _a !== void 0 ? _a : createRandomSeed())
|
|
41
41
|
: createRandomSeed();
|
|
42
42
|
const avatar = new Avatar(style, {
|
|
43
43
|
...extractStyleOptions(argv, style),
|
|
@@ -48,7 +48,10 @@ export async function handleStyleCommand(argv, name, style) {
|
|
|
48
48
|
await writeFile(fileName, avatar.toString());
|
|
49
49
|
break;
|
|
50
50
|
case 'png':
|
|
51
|
-
await writeFile(fileName, await toPng(avatar.toString(), {
|
|
51
|
+
await writeFile(fileName, await toPng(avatar.toString(), {
|
|
52
|
+
includeExif,
|
|
53
|
+
size: argv.size,
|
|
54
|
+
}).toArrayBuffer());
|
|
52
55
|
break;
|
|
53
56
|
case 'jpg':
|
|
54
57
|
case 'jpeg':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Style } from '@dicebear/core';
|
|
2
2
|
/**
|
|
3
|
-
* Loads every minified definition shipped by `@dicebear/
|
|
3
|
+
* Loads every minified definition shipped by `@dicebear/styles`, wraps
|
|
4
4
|
* each in a {@link Style}, and returns them keyed by style name.
|
|
5
5
|
*/
|
|
6
6
|
export declare function loadStyles(): Map<string, Style>;
|
package/lib/utils/loadStyles.js
CHANGED
|
@@ -4,11 +4,11 @@ import * as path from 'node:path';
|
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
/**
|
|
7
|
-
* Loads every minified definition shipped by `@dicebear/
|
|
7
|
+
* Loads every minified definition shipped by `@dicebear/styles`, wraps
|
|
8
8
|
* each in a {@link Style}, and returns them keyed by style name.
|
|
9
9
|
*/
|
|
10
10
|
export function loadStyles() {
|
|
11
|
-
const definitionsDir = path.dirname(require.resolve('@dicebear/
|
|
11
|
+
const definitionsDir = path.dirname(require.resolve('@dicebear/styles/initials.json'));
|
|
12
12
|
const styles = new Map();
|
|
13
13
|
for (const file of fs.readdirSync(definitionsDir)) {
|
|
14
14
|
if (!file.endsWith('.min.json')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dicebear",
|
|
3
|
-
"version": "10.0.0
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "CLI for DiceBear — unique avatars from dozens of styles.",
|
|
6
6
|
"homepage": "https://github.com/dicebear/dicebear",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"prepublishOnly": "npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dicebear/converter": "10.0.0
|
|
29
|
-
"@dicebear/core": "10.0.0
|
|
30
|
-
"@dicebear/
|
|
28
|
+
"@dicebear/converter": "10.0.0",
|
|
29
|
+
"@dicebear/core": "10.0.0",
|
|
30
|
+
"@dicebear/styles": "^10.0.0",
|
|
31
31
|
"ajv": "^8.17.1",
|
|
32
32
|
"chalk": "^5.4.1",
|
|
33
33
|
"chalk-template": "^1.1.2",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"typescript": "^5.9.3"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=22.0.0"
|
|
51
51
|
}
|
|
52
52
|
}
|