@mongez/reinforcements 2.2.6 → 2.2.7
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/README.md +37 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +2 -0
- package/cjs/object/get.js +1 -1
- package/cjs/string/initials.d.ts +5 -0
- package/cjs/string/initials.js +17 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/object/get.js +1 -1
- package/esm/string/initials.d.ts +5 -0
- package/esm/string/initials.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1361,6 +1361,7 @@ The following list defines all available string utilities
|
|
|
1361
1361
|
- [Trim Left](#trimming-values-from-string): Remove a string from the beginning of the given string.
|
|
1362
1362
|
- [Trim Right](#trimming-values-from-string): Remove a string from the end of the given string.
|
|
1363
1363
|
- [Starts With Arabic Letter](#detect-if-string-starts-with-arabic): Detect if string starts with Arabic letter.
|
|
1364
|
+
- [Name Initials](#name-initials): Get the initials of the given name.
|
|
1364
1365
|
|
|
1365
1366
|
### Capitalize
|
|
1366
1367
|
|
|
@@ -1736,6 +1737,40 @@ console.log(startsWithArabic(string)); // false
|
|
|
1736
1737
|
console.log(startsWithArabic(arabicString)); // true
|
|
1737
1738
|
```
|
|
1738
1739
|
|
|
1740
|
+
### Name Initials
|
|
1741
|
+
|
|
1742
|
+
Get initials from a name.
|
|
1743
|
+
|
|
1744
|
+
`initials(name: string, separator = ''): string`
|
|
1745
|
+
|
|
1746
|
+
```ts
|
|
1747
|
+
import { initials } from "@mongez/reinforcements";
|
|
1748
|
+
|
|
1749
|
+
const name = "John Doe";
|
|
1750
|
+
|
|
1751
|
+
console.log(initials(name)); // JD
|
|
1752
|
+
```
|
|
1753
|
+
|
|
1754
|
+
You can also pass a separator to separate the initials.
|
|
1755
|
+
|
|
1756
|
+
```ts
|
|
1757
|
+
import { initials } from "@mongez/reinforcements";
|
|
1758
|
+
|
|
1759
|
+
const name = "John Doe";
|
|
1760
|
+
|
|
1761
|
+
console.log(initials(name, '.')); // J.D
|
|
1762
|
+
```
|
|
1763
|
+
|
|
1764
|
+
If the given parameter is not a string it will throw an error.
|
|
1765
|
+
|
|
1766
|
+
```ts
|
|
1767
|
+
import { initials } from "@mongez/reinforcements";
|
|
1768
|
+
|
|
1769
|
+
const name = 123;
|
|
1770
|
+
|
|
1771
|
+
console.log(initials(name)); // Error: The given name is not a string.
|
|
1772
|
+
```
|
|
1773
|
+
|
|
1739
1774
|
## Numbers
|
|
1740
1775
|
|
|
1741
1776
|
Here are the aviation numbers utilities.
|
|
@@ -2003,6 +2038,8 @@ To run tests run `npm run test` or `yarn test`
|
|
|
2003
2038
|
|
|
2004
2039
|
## Change Log
|
|
2005
2040
|
|
|
2041
|
+
- 2.2.7 (22 Feb 2023)
|
|
2042
|
+
- Added [Name Initials](#name-initials) function.
|
|
2006
2043
|
- 2.2.0 (08 Nov 2022)
|
|
2007
2044
|
- Migrated Collections From Package to separate package.
|
|
2008
2045
|
- 2.1.0 (06 Nov 2022)
|
package/cjs/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { default as unset } from "./object/unset";
|
|
|
31
31
|
export { default as Random } from "./Random/random";
|
|
32
32
|
export { default as capitalize } from "./string/capitalize";
|
|
33
33
|
export { default as extension } from "./string/extension";
|
|
34
|
+
export { default as initials } from "./string/initials";
|
|
34
35
|
export { default as ltrim } from "./string/ltrim";
|
|
35
36
|
export { default as readMoreChars } from "./string/readMoreChars";
|
|
36
37
|
export { default as readMoreWords } from "./string/readMoreWords";
|
package/cjs/index.js
CHANGED
|
@@ -35,6 +35,7 @@ var unset = require("./object/unset.js");
|
|
|
35
35
|
var random = require("./Random/random.js");
|
|
36
36
|
var capitalize = require("./string/capitalize.js");
|
|
37
37
|
var extension = require("./string/extension.js");
|
|
38
|
+
var initials = require("./string/initials.js");
|
|
38
39
|
var ltrim = require("./string/ltrim.js");
|
|
39
40
|
var readMoreChars = require("./string/readMoreChars.js");
|
|
40
41
|
var readMoreWords = require("./string/readMoreWords.js");
|
|
@@ -90,6 +91,7 @@ exports.unset = unset;
|
|
|
90
91
|
exports.Random = random;
|
|
91
92
|
exports.capitalize = capitalize;
|
|
92
93
|
exports.extension = extension;
|
|
94
|
+
exports.initials = initials;
|
|
93
95
|
exports.ltrim = ltrim;
|
|
94
96
|
exports.readMoreChars = readMoreChars;
|
|
95
97
|
exports.readMoreWords = readMoreWords;
|
package/cjs/object/get.js
CHANGED
|
@@ -17,7 +17,7 @@ function getValue(object, keyChain, defaultValue) {
|
|
|
17
17
|
/**
|
|
18
18
|
* Get the value of the given key
|
|
19
19
|
*/
|
|
20
|
-
function get(object, key, defaultValue
|
|
20
|
+
function get(object, key, defaultValue) {
|
|
21
21
|
if (!object) return defaultValue;
|
|
22
22
|
if (object[key]) return object[key];
|
|
23
23
|
return getValue(object, key, defaultValue);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the initials of the given name
|
|
5
|
+
*/
|
|
6
|
+
function initials(name, separator = "") {
|
|
7
|
+
if (!name) return "";
|
|
8
|
+
if (typeof name !== "string") {
|
|
9
|
+
throw new Error("The name must be a string");
|
|
10
|
+
}
|
|
11
|
+
return name
|
|
12
|
+
.split(" ")
|
|
13
|
+
.map(name => name.charAt(0))
|
|
14
|
+
.join(separator);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = initials;
|
package/esm/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { default as unset } from "./object/unset";
|
|
|
31
31
|
export { default as Random } from "./Random/random";
|
|
32
32
|
export { default as capitalize } from "./string/capitalize";
|
|
33
33
|
export { default as extension } from "./string/extension";
|
|
34
|
+
export { default as initials } from "./string/initials";
|
|
34
35
|
export { default as ltrim } from "./string/ltrim";
|
|
35
36
|
export { default as readMoreChars } from "./string/readMoreChars";
|
|
36
37
|
export { default as readMoreWords } from "./string/readMoreWords";
|
package/esm/index.js
CHANGED
|
@@ -31,6 +31,7 @@ export { default as unset } from "./object/unset.js";
|
|
|
31
31
|
export { default as Random } from "./Random/random.js";
|
|
32
32
|
export { default as capitalize } from "./string/capitalize.js";
|
|
33
33
|
export { default as extension } from "./string/extension.js";
|
|
34
|
+
export { default as initials } from "./string/initials.js";
|
|
34
35
|
export { default as ltrim } from "./string/ltrim.js";
|
|
35
36
|
export { default as readMoreChars } from "./string/readMoreChars.js";
|
|
36
37
|
export { default as readMoreWords } from "./string/readMoreWords.js";
|
package/esm/object/get.js
CHANGED
|
@@ -15,7 +15,7 @@ function getValue(object, keyChain, defaultValue) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get the value of the given key
|
|
17
17
|
*/
|
|
18
|
-
function get(object, key, defaultValue
|
|
18
|
+
function get(object, key, defaultValue) {
|
|
19
19
|
if (!object) return defaultValue;
|
|
20
20
|
if (object[key]) return object[key];
|
|
21
21
|
return getValue(object, key, defaultValue);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the initials of the given name
|
|
3
|
+
*/
|
|
4
|
+
function initials(name, separator = "") {
|
|
5
|
+
if (!name) return "";
|
|
6
|
+
if (typeof name !== "string") {
|
|
7
|
+
throw new Error("The name must be a string");
|
|
8
|
+
}
|
|
9
|
+
return name
|
|
10
|
+
.split(" ")
|
|
11
|
+
.map(name => name.charAt(0))
|
|
12
|
+
.join(separator);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { initials as default };
|
package/package.json
CHANGED