@teambit/toolbox.string.get-initials 0.0.0-74247ab40af540a67a0b90d712d28e456e6779a7

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * return the initials of a string if possible.
3
+ * @param name string to get initials from
4
+ */
5
+ export declare function getInitials(name: string): string | undefined;
@@ -0,0 +1,13 @@
1
+ ---
2
+ labels: ['typescript', 'utils', 'string', 'text']
3
+ description: 'Get initials of a string.'
4
+ ---
5
+
6
+ import { getInitials } from './get-initials';
7
+
8
+ A util function that return the initials of a string if possible.
9
+ For example:
10
+
11
+ ```js live
12
+ getInitials('scope name');
13
+ ```
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInitials = getInitials;
4
+ /**
5
+ * return the initials of a string if possible.
6
+ * @param name string to get initials from
7
+ */
8
+ function getInitials(name) {
9
+ if (!name)
10
+ return undefined;
11
+ const words = name.split(' ');
12
+ if (words.length > 1) {
13
+ return words
14
+ .slice(0, 2)
15
+ .map((word) => word[0])
16
+ .join('');
17
+ }
18
+ return name.slice(0, 2);
19
+ }
20
+ //# sourceMappingURL=get-initials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-initials.js","sourceRoot":"","sources":["../get-initials.ts"],"names":[],"mappings":";;AAIA,kCAWC;AAfD;;;GAGG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAE5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK;aACT,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACtB,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const get_initials_1 = require("./get-initials");
4
+ const chai_1 = require("chai");
5
+ describe('getInitials()', () => {
6
+ it('should return two letters for the initialsof two word', () => {
7
+ (0, chai_1.expect)((0, get_initials_1.getInitials)('scope name')).to.equal('sn');
8
+ });
9
+ it('should return the two first letters if one word', () => {
10
+ (0, chai_1.expect)((0, get_initials_1.getInitials)('scope')).to.equal('sc');
11
+ });
12
+ it('should return undefined if the word is empty', () => {
13
+ (0, chai_1.expect)((0, get_initials_1.getInitials)('')).to.be.undefined;
14
+ });
15
+ });
16
+ //# sourceMappingURL=get-initials.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-initials.spec.js","sourceRoot":"","sources":["../get-initials.spec.ts"],"names":[],"mappings":";;AAAA,iDAA6C;AAC7C,+BAA8B;AAE9B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,IAAA,aAAM,EAAC,IAAA,0BAAW,EAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,IAAA,aAAM,EAAC,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,IAAA,aAAM,EAAC,IAAA,0BAAW,EAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export { getInitials } from './get-initials';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInitials = void 0;
4
+ var get_initials_1 = require("./get-initials");
5
+ Object.defineProperty(exports, "getInitials", { enumerable: true, get: function () { return get_initials_1.getInitials; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
@@ -0,0 +1,13 @@
1
+ ---
2
+ labels: ['typescript', 'utils', 'string', 'text']
3
+ description: 'Get initials of a string.'
4
+ ---
5
+
6
+ import { getInitials } from './get-initials';
7
+
8
+ A util function that return the initials of a string if possible.
9
+ For example:
10
+
11
+ ```js live
12
+ getInitials('scope name');
13
+ ```
@@ -0,0 +1,16 @@
1
+ import { getInitials } from './get-initials';
2
+ import { expect } from 'chai';
3
+
4
+ describe('getInitials()', () => {
5
+ it('should return two letters for the initialsof two word', () => {
6
+ expect(getInitials('scope name')).to.equal('sn');
7
+ });
8
+
9
+ it('should return the two first letters if one word', () => {
10
+ expect(getInitials('scope')).to.equal('sc');
11
+ });
12
+
13
+ it('should return undefined if the word is empty', () => {
14
+ expect(getInitials('')).to.be.undefined;
15
+ });
16
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * return the initials of a string if possible.
3
+ * @param name string to get initials from
4
+ */
5
+ export function getInitials(name: string) {
6
+ if (!name) return undefined;
7
+
8
+ const words = name.split(' ');
9
+ if (words.length > 1) {
10
+ return words
11
+ .slice(0, 2)
12
+ .map((word) => word[0])
13
+ .join('');
14
+ }
15
+ return name.slice(0, 2);
16
+ }
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { getInitials } from './get-initials';
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@teambit/toolbox.string.get-initials",
3
+ "version": "0.0.0-74247ab40af540a67a0b90d712d28e456e6779a7",
4
+ "homepage": "https://bit.cloud/teambit/toolbox/string/get-initials",
5
+ "main": "dist/index.js",
6
+ "componentId": {
7
+ "scope": "teambit.toolbox",
8
+ "name": "string/get-initials",
9
+ "version": "74247ab40af540a67a0b90d712d28e456e6779a7"
10
+ },
11
+ "dependencies": {},
12
+ "devDependencies": {
13
+ "@types/chai": "4.2.15",
14
+ "chai": "4.3.0",
15
+ "@types/mocha": "9.1.0",
16
+ "@teambit/node.envs.node-typescript-mocha": "0.0.4"
17
+ },
18
+ "peerDependencies": {},
19
+ "license": "Apache-2.0",
20
+ "optionalDependencies": {},
21
+ "peerDependenciesMeta": {},
22
+ "private": false,
23
+ "engines": {
24
+ "node": ">=12.22.0"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/teambit/bit"
29
+ },
30
+ "keywords": [
31
+ "bit",
32
+ "components",
33
+ "collaboration",
34
+ "web",
35
+ "react",
36
+ "react-components",
37
+ "angular",
38
+ "angular-components"
39
+ ]
40
+ }
@@ -0,0 +1,41 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
11
+ const src: string;
12
+ export default src;
13
+ }
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }