@ulu/utils
Advanced tools
Comparing version 0.0.8 to 0.0.9
# Change Log | ||
## 0.0.9 | ||
- Add String (toInitials) Creates initials from string | ||
## 0.0.8 | ||
- add number (sum and average) | ||
- Add array (removeDuplicates, createEmptyMatrix) | ||
- Add string (titleCase) | ||
## 0.0.7 | ||
Fix missing jsdoc comments in string module. Add linting and fix issues. |
@@ -96,2 +96,21 @@ /** | ||
/** | ||
* Converts a string to initials | ||
* - Example "Jane Allen-Doe" --> "JAD" | ||
* - Example (short) "Jane Allen-Doe" --> "JD" | ||
* - Example "Wow this part-time" --> "WTPT" | ||
* - Example "Wow There are 2 !! People." --> "WTA2P" | ||
* @param {String} string String to convert | ||
* @param {Boolean} short If true the initials will be limited to two letters, unless it's only one word which would be single letter | ||
* @returns {String} | ||
*/ | ||
export function toInitials(string, short) { | ||
const notAllowed = /[^A-Z0-9\s-]/gi; | ||
const seperators = /[\s-]+/g; | ||
const parts = string.replace(notAllowed, "").split(seperators); | ||
const isShort = short && parts.length > 2; | ||
const final = isShort ? [parts.shift(), parts.pop()] : parts; | ||
return final.map(part => part.substring(0, 1).toUpperCase()).join(""); | ||
} | ||
/** | ||
* Convert string to title case | ||
@@ -98,0 +117,0 @@ * @param {String} string String to convert to title case |
{ | ||
"name": "@ulu/utils", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Low level utility library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -55,2 +55,13 @@ /** | ||
/** | ||
* Converts a string to initials | ||
* - Example "Jane Allen-Doe" --> "JAD" | ||
* - Example (short) "Jane Allen-Doe" --> "JD" | ||
* - Example "Wow this part-time" --> "WTPT" | ||
* - Example "Wow There are 2 !! People." --> "WTA2P" | ||
* @param {String} string String to convert | ||
* @param {Boolean} short If true the initials will be limited to two letters, unless it's only one word which would be single letter | ||
* @returns {String} | ||
*/ | ||
export function toInitials(string: string, short: boolean): string; | ||
/** | ||
* Convert string to title case | ||
@@ -57,0 +68,0 @@ * @param {String} string String to convert to title case |
Sorry, the diff of this file is not supported yet
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
38875
1024