@dicebear/initials
Advanced tools
Comparing version 5.4.2 to 5.4.3
@@ -9,2 +9,3 @@ /*! | ||
import { convertColor } from './utils/convertColor.js'; | ||
import { escapeXml } from './utils/escape.js'; | ||
export const meta = { | ||
@@ -28,3 +29,3 @@ title: 'Initials', | ||
const svg = [ | ||
`<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>`, | ||
`<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>`, | ||
].join(''); | ||
@@ -41,6 +42,6 @@ return { | ||
textColor, | ||
initials | ||
}) | ||
initials, | ||
}), | ||
}; | ||
}; | ||
export { schema } from './schema.js'; |
@@ -9,2 +9,3 @@ /*! | ||
import { convertColor } from './utils/convertColor.js'; | ||
import { escapeXml } from './utils/escape.js'; | ||
export const meta = { | ||
@@ -28,3 +29,3 @@ title: 'Initials', | ||
const svg = [ | ||
`<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>`, | ||
`<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>`, | ||
].join(''); | ||
@@ -41,6 +42,6 @@ return { | ||
textColor, | ||
initials | ||
}) | ||
initials, | ||
}), | ||
}; | ||
}; | ||
export { schema } from './schema.js'; |
@@ -1,7 +0,1 @@ | ||
/** | ||
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma. | ||
* | ||
* Plugin: https://www.figma.com/community/plugin/1005765655729342787 | ||
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5 | ||
*/ | ||
export declare function convertColor(color: string): string; |
@@ -1,9 +0,3 @@ | ||
/** | ||
* Do not change this file manually! This file was generated with the "Dicebear Exporter"-Plugin for Figma. | ||
* | ||
* Plugin: https://www.figma.com/community/plugin/1005765655729342787 | ||
* File: https://www.figma.com/file/BRj9eonsORJ7GIUdm8gnu5 | ||
*/ | ||
export function convertColor(color) { | ||
return 'transparent' === color ? color : `#${color}`; | ||
} |
@@ -1,6 +0,1 @@ | ||
/*! | ||
* Copyright by chickens / stackoverflow | ||
* Licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/). | ||
* Source: https://stackoverflow.com/a/63763497 | ||
*/ | ||
export declare function getInitials(seed: string): string; | ||
export declare function getInitials(seed: string, discardAtSymbol?: boolean): string; |
@@ -1,14 +0,15 @@ | ||
/*! | ||
* Copyright by chickens / stackoverflow | ||
* Licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/). | ||
* Source: https://stackoverflow.com/a/63763497 | ||
*/ | ||
export function getInitials(seed) { | ||
return seed | ||
.match(/(^\S\S?|\s\S)?/g) | ||
.map((v) => v.trim()) | ||
.join('') | ||
.match(/(^\S|\S$)?/g) | ||
.join('') | ||
.toLocaleUpperCase(); | ||
// @see https://www.regular-expressions.info/unicode.html | ||
export function getInitials(seed, discardAtSymbol = true) { | ||
const input = discardAtSymbol ? seed.replace(/@.*/, '') : seed; | ||
const matches = input.match(/(\p{L}[\p{L}\p{M}]*)/gu); | ||
if (!matches) { | ||
// Re-run without discarding `@`-symbol, if no matches | ||
return discardAtSymbol ? getInitials(seed, false) : ''; | ||
} | ||
if (matches.length === 1) { | ||
return matches[0].match(/^(?:\p{L}\p{M}*){1,2}/u)[0].toUpperCase(); | ||
} | ||
const firstCharacter = matches[0].match(/^(?:\p{L}\p{M}*)/u)[0]; | ||
const secondCharacter = matches[matches.length - 1].match(/^(?:\p{L}\p{M}*)/u)[0]; | ||
return (firstCharacter + secondCharacter).toUpperCase(); | ||
} |
{ | ||
"name": "@dicebear/initials", | ||
"version": "5.4.2", | ||
"version": "5.4.3", | ||
"description": "Initials avatar style for DiceBear", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@dicebear/core": "5.4.2", | ||
"@dicebear/core": "5.4.3", | ||
"@tsconfig/recommended": "^1.0.1", | ||
@@ -48,3 +48,3 @@ "del-cli": "^5.0.0", | ||
}, | ||
"gitHead": "b3434ed9763c294ba78a14c513a850b629028281" | ||
"gitHead": "dd707aa363639dfe8fcae0948035dae3d34f993c" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11267
16
219