@dicebear/initials 7.1.1 → 7.1.3

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 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;
@@ -0,0 +1,8 @@
1
+ export function escapeXml(content) {
2
+ return content
3
+ .replace(/&/g, '&amp;')
4
+ .replace(/'/g, '&apos;')
5
+ .replace(/"/g, '&quot;')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;');
8
+ }
@@ -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;
@@ -1,14 +1,15 @@
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 function getInitials(seed) {
7
- return seed
8
- .match(/(^\S\S?|\s\S)?/g)
9
- .map((v) => v.trim())
10
- .join('')
11
- .match(/(^\S|\S$)?/g)
12
- .join('')
13
- .toLocaleUpperCase();
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": "7.1.1",
3
+ "version": "7.1.3",
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": "7.1.1",
32
+ "@dicebear/core": "7.1.3",
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": "94b0427038c8d073aefd35f0e886a7782f257582"
47
+ "gitHead": "7907718cb26312261c302d02eed6bacd7802f57d"
48
48
  }