@dicebear/initials 8.0.1 → 8.0.2
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 +4 -3
- package/lib/utils/convertColor.d.ts +0 -6
- package/lib/utils/convertColor.js +0 -6
- package/lib/utils/escape.d.ts +1 -0
- package/lib/utils/escape.js +8 -0
- package/lib/utils/initials.d.ts +1 -6
- package/lib/utils/initials.js +14 -13
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { getInitials } from './utils/initials.js';
|
|
8
8
|
import { convertColor } from './utils/convertColor.js';
|
|
9
|
+
import { escapeXml } from './utils/escape.js';
|
|
9
10
|
export const meta = {
|
|
10
11
|
title: 'Initials',
|
|
11
12
|
creator: 'DiceBear',
|
|
@@ -24,7 +25,7 @@ export const create = ({ prng, options }) => {
|
|
|
24
25
|
const initials = getInitials(prng.seed.trim()).slice(0, (_g = options.chars) !== null && _g !== void 0 ? _g : 2);
|
|
25
26
|
// prettier-ignore
|
|
26
27
|
const svg = [
|
|
27
|
-
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}" font-weight="${fontWeight}" fill="${textColor}" text-anchor="middle" dy="${(fontSize * .356).toFixed(3)}">${initials}</text>`,
|
|
28
|
+
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}" font-weight="${fontWeight}" fill="${textColor}" text-anchor="middle" dy="${(fontSize * .356).toFixed(3)}">${escapeXml(initials)}</text>`,
|
|
28
29
|
].join('');
|
|
29
30
|
return {
|
|
30
31
|
attributes: {
|
|
@@ -36,8 +37,8 @@ export const create = ({ prng, options }) => {
|
|
|
36
37
|
fontSize,
|
|
37
38
|
fontWeight,
|
|
38
39
|
textColor,
|
|
39
|
-
initials
|
|
40
|
-
})
|
|
40
|
+
initials,
|
|
41
|
+
}),
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
44
|
export { schema } from './schema.js';
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma.
|
|
3
|
-
*
|
|
4
|
-
* Plugin: https://www.figma.com/community/plugin/1005765655729342787
|
|
5
|
-
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5
|
|
6
|
-
*/
|
|
7
1
|
export declare function convertColor(color: string): string;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma.
|
|
3
|
-
*
|
|
4
|
-
* Plugin: https://www.figma.com/community/plugin/1005765655729342787
|
|
5
|
-
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5
|
|
6
|
-
*/
|
|
7
1
|
export function convertColor(color) {
|
|
8
2
|
return 'transparent' === color ? color : `#${color}`;
|
|
9
3
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeXml(content: string): string;
|
package/lib/utils/initials.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright by chickens / stackoverflow
|
|
3
|
-
* Licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/).
|
|
4
|
-
* Source: https://stackoverflow.com/a/63763497
|
|
5
|
-
*/
|
|
6
|
-
export declare function getInitials(seed: string): string;
|
|
1
|
+
export declare function getInitials(seed: string, discardAtSymbol?: boolean): string;
|
package/lib/utils/initials.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
// @see https://www.regular-expressions.info/unicode.html
|
|
2
|
+
export function getInitials(seed, discardAtSymbol = true) {
|
|
3
|
+
const input = discardAtSymbol ? seed.replace(/@.*/, '') : seed;
|
|
4
|
+
const matches = input.match(/(\p{L}[\p{L}\p{M}]*)/gu);
|
|
5
|
+
if (!matches) {
|
|
6
|
+
// Re-run without discarding `@`-symbol, if no matches
|
|
7
|
+
return discardAtSymbol ? getInitials(seed, false) : '';
|
|
8
|
+
}
|
|
9
|
+
if (matches.length === 1) {
|
|
10
|
+
return matches[0].match(/^(?:\p{L}\p{M}*){1,2}/u)[0].toUpperCase();
|
|
11
|
+
}
|
|
12
|
+
const firstCharacter = matches[0].match(/^(?:\p{L}\p{M}*)/u)[0];
|
|
13
|
+
const secondCharacter = matches[matches.length - 1].match(/^(?:\p{L}\p{M}*)/u)[0];
|
|
14
|
+
return (firstCharacter + secondCharacter).toUpperCase();
|
|
14
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/initials",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Initials avatar style for DiceBear",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dicebear"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test": "uvu tests"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@dicebear/core": "8.0.
|
|
32
|
+
"@dicebear/core": "8.0.2",
|
|
33
33
|
"@tsconfig/recommended": "^1.0.2",
|
|
34
34
|
"del-cli": "^5.0.0",
|
|
35
35
|
"typescript": "^5.1.6",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a81631f25e0723edc73cf40c1423f7b5242fafe5"
|
|
48
48
|
}
|