@dicebear/initials 5.0.0-beta.9 → 5.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 +2 -4
- package/lib/utils/initials.d.ts +6 -0
- package/lib/utils/initials.js +14 -0
- package/package.json +4 -7
- package/lib/core.d.ts +0 -3
- package/lib/core.js +0 -33
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
5
5
|
* Copyright (c) 2022 Florian Körner
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { getInitials } from './utils/initials.js';
|
|
8
8
|
export const meta = {
|
|
9
9
|
title: 'Initials',
|
|
10
10
|
creator: 'Florian Körner',
|
|
@@ -19,9 +19,7 @@ export const create = ({ prng, options }) => {
|
|
|
19
19
|
const fontFamily = (_b = (_a = options.fontFamily) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : 'Arial, sans-serif';
|
|
20
20
|
const fontSize = (_c = options.fontSize) !== null && _c !== void 0 ? _c : 50;
|
|
21
21
|
const fontWeight = (_d = options.fontWeight) !== null && _d !== void 0 ? _d : 400;
|
|
22
|
-
const seedInitials =
|
|
23
|
-
.toLocaleUpperCase()
|
|
24
|
-
.slice(0, (_e = options.chars) !== null && _e !== void 0 ? _e : 2);
|
|
22
|
+
const seedInitials = getInitials(prng.seed.trim()).slice(0, (_e = options.chars) !== null && _e !== void 0 ? _e : 2);
|
|
25
23
|
// prettier-ignore
|
|
26
24
|
const svg = [
|
|
27
25
|
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}" fontWeight="${fontWeight}" fill="#FFF" text-anchor="middle" dy="${(fontSize * .356).toFixed(3)}">${seedInitials}</text>`,
|
|
@@ -0,0 +1,14 @@
|
|
|
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();
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dicebear/initials",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Initials avatar style for DiceBear",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dicebear"
|
|
@@ -28,18 +28,15 @@
|
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"test": "uvu tests"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"initials": "^3.1.2"
|
|
33
|
-
},
|
|
34
31
|
"devDependencies": {
|
|
35
|
-
"@dicebear/core": "^5.0.0
|
|
32
|
+
"@dicebear/core": "^5.0.0",
|
|
36
33
|
"@tsconfig/recommended": "^1.0.1",
|
|
37
34
|
"del-cli": "^4.0.1",
|
|
38
35
|
"typescript": "^4.6.3",
|
|
39
36
|
"uvu": "^0.5.3"
|
|
40
37
|
},
|
|
41
38
|
"peerDependencies": {
|
|
42
|
-
"@dicebear/core": "^5.0.0
|
|
39
|
+
"@dicebear/core": "^5.0.0"
|
|
43
40
|
},
|
|
44
41
|
"engines": {
|
|
45
42
|
"node": "^14.13.1 || >=16.0.0"
|
|
@@ -47,5 +44,5 @@
|
|
|
47
44
|
"publishConfig": {
|
|
48
45
|
"access": "public"
|
|
49
46
|
},
|
|
50
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "e8a60b4611b5738c7f46910f77b97ef1967f32dc"
|
|
51
48
|
}
|
package/lib/core.d.ts
DELETED
package/lib/core.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { schema } from './schema.js';
|
|
2
|
-
import initials from 'initials';
|
|
3
|
-
export const style = {
|
|
4
|
-
meta: {
|
|
5
|
-
title: 'Initials',
|
|
6
|
-
creator: 'Florian Körner',
|
|
7
|
-
source: 'https://github.com/dicebear/dicebear',
|
|
8
|
-
license: {
|
|
9
|
-
name: 'CC0 1.0',
|
|
10
|
-
url: 'https://creativecommons.org/publicdomain/zero/1.0/',
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
schema: schema,
|
|
14
|
-
create: ({ prng, options }) => {
|
|
15
|
-
var _a, _b, _c, _d, _e;
|
|
16
|
-
const fontFamily = (_b = (_a = options.fontFamily) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : 'Arial, sans-serif';
|
|
17
|
-
const fontSize = (_c = options.fontSize) !== null && _c !== void 0 ? _c : 50;
|
|
18
|
-
const fontWeight = (_d = options.fontWeight) !== null && _d !== void 0 ? _d : 400;
|
|
19
|
-
const seedInitials = initials(prng.seed.trim())
|
|
20
|
-
.toLocaleUpperCase()
|
|
21
|
-
.slice(0, (_e = options.chars) !== null && _e !== void 0 ? _e : 2);
|
|
22
|
-
// prettier-ignore
|
|
23
|
-
const svg = [
|
|
24
|
-
`<text x="50%" y="50%" font-family="${fontFamily}" font-size="${fontSize}" fontWeight="${fontWeight}" fill="#FFF" text-anchor="middle" dy="${(fontSize * .356).toFixed(3)}">${seedInitials}</text>`,
|
|
25
|
-
].join('');
|
|
26
|
-
return {
|
|
27
|
-
attributes: {
|
|
28
|
-
viewBox: '0 0 100 100',
|
|
29
|
-
},
|
|
30
|
-
body: svg,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
};
|