https://github.com/gr2m/initials
extract initials from and add initials to names
https://github.com/gr2m/initials
Last synced: 7 months ago
JSON representation
extract initials from and add initials to names
- Host: GitHub
- URL: https://github.com/gr2m/initials
- Owner: gr2m
- License: mit
- Created: 2014-02-10T20:05:03.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T21:49:25.000Z (almost 4 years ago)
- Last Synced: 2025-04-25T14:23:20.456Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://gr2m.github.io/initials
- Size: 1.54 MB
- Stars: 44
- Watchers: 2
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Initials. Because JD is shorter than John Doe
=============================================
> extracts initials from and adds initials to names
[](https://travis-ci.org/gr2m/initials)
[](https://coveralls.io/r/gr2m/initials?branch=main)
[](https://greenkeeper.io/)
## Installation
Install using [npm](https://npmjs.org/) for node.js:
```
npm install --save initials
```
## Usage
```js
initials('John Doe')
// 'JD'
initials(['John Doe', 'Robert Roe'])
// ['JD', 'RR']
// alias for initials('John Doe')
initials.find('John Doe')
// parse name(s)
initials.parse('John Doe')
// {name: 'John Doe', initials: 'JD'}
// add initials to name(s)
initials.addTo('John Doe')
// 'John Doe (JD)'
// pass existing initials for names
initials(['John Doe', 'Jane Dane'], {
existing: { 'John Doe': 'JD' }
})
// ['JD', 'JDa']
```
## Notes
Preffered initials can be passed in `(JD)`, e.g.
```js
console.log( initials('John Doe (JoDo)') );
// 'JoDo'
```
If a name contains an email, it gets ignored when calculating initials
```js
console.log( initials('John Doe joe@example.com') );
// 'JD'
```
If a name _is_ an email, the domain part gets ignored
```js
console.log( initials('joe@example.com') );
// 'jo'
```
When passing an Array of names, duplicates of initials are avoided
```js
console.log( initials(['John Doe', 'Jane Dane']) );
// ['JDo', 'JDa']
```
## Test
```
npm test
```
## LICENSE
[MIT](LICENSE)