@rolster/helpers-string
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -11,4 +11,18 @@ 'use strict'; | ||
const lastChar = (value) => { | ||
return value.length ? '' : value.charAt(value.length - 1); | ||
return value.length ? value.charAt(value.length - 1) : ''; | ||
}; | ||
const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace(/á/g, 'a') | ||
.replace(/Á/g, 'A') | ||
.replace(/é/g, 'e') | ||
.replace(/É/g, 'E') | ||
.replace(/í/g, 'i') | ||
.replace(/Í/g, 'I') | ||
.replace(/ó/g, 'o') | ||
.replace(/Ó/g, 'O') | ||
.replace(/ú/g, 'u') | ||
.replace(/Ú/g, 'U'); | ||
}; | ||
const hasPattern = (word, pattern, force = false) => { | ||
@@ -23,16 +37,2 @@ let filter = pattern.toLowerCase(); | ||
}; | ||
const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace('á', 'a') | ||
.replace('Á', 'A') | ||
.replace('é', 'e') | ||
.replace('É', 'E') | ||
.replace('í', 'i') | ||
.replace('Í', 'I') | ||
.replace('ó', 'o') | ||
.replace('Ó', 'O') | ||
.replace('ú', 'u') | ||
.replace('Ú', 'U'); | ||
}; | ||
const initials = (word, size = 2) => { | ||
@@ -47,2 +47,9 @@ const split = word.split(' '); | ||
}; | ||
const regInterpolation = /{([^{}]*)}/g; | ||
function interpolation(template, value) { | ||
if (value) { | ||
return template.replace(regInterpolation, (_, key) => Array.isArray(value) ? value[+key] : value[key]); | ||
} | ||
return !regInterpolation.test(template) ? template : ''; | ||
} | ||
@@ -52,4 +59,5 @@ exports.firstChar = firstChar; | ||
exports.initials = initials; | ||
exports.interpolation = interpolation; | ||
exports.lastChar = lastChar; | ||
exports.normalize = normalize; | ||
//# sourceMappingURL=index.js.map |
@@ -7,4 +7,18 @@ import { firstElement, lastElement } from '@rolster/helpers-array'; | ||
const lastChar = (value) => { | ||
return value.length ? '' : value.charAt(value.length - 1); | ||
return value.length ? value.charAt(value.length - 1) : ''; | ||
}; | ||
const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace(/á/g, 'a') | ||
.replace(/Á/g, 'A') | ||
.replace(/é/g, 'e') | ||
.replace(/É/g, 'E') | ||
.replace(/í/g, 'i') | ||
.replace(/Í/g, 'I') | ||
.replace(/ó/g, 'o') | ||
.replace(/Ó/g, 'O') | ||
.replace(/ú/g, 'u') | ||
.replace(/Ú/g, 'U'); | ||
}; | ||
const hasPattern = (word, pattern, force = false) => { | ||
@@ -19,16 +33,2 @@ let filter = pattern.toLowerCase(); | ||
}; | ||
const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace('á', 'a') | ||
.replace('Á', 'A') | ||
.replace('é', 'e') | ||
.replace('É', 'E') | ||
.replace('í', 'i') | ||
.replace('Í', 'I') | ||
.replace('ó', 'o') | ||
.replace('Ó', 'O') | ||
.replace('ú', 'u') | ||
.replace('Ú', 'U'); | ||
}; | ||
const initials = (word, size = 2) => { | ||
@@ -43,4 +43,11 @@ const split = word.split(' '); | ||
}; | ||
const regInterpolation = /{([^{}]*)}/g; | ||
function interpolation(template, value) { | ||
if (value) { | ||
return template.replace(regInterpolation, (_, key) => Array.isArray(value) ? value[+key] : value[key]); | ||
} | ||
return !regInterpolation.test(template) ? template : ''; | ||
} | ||
export { firstChar, hasPattern, initials, lastChar, normalize }; | ||
export { firstChar, hasPattern, initials, interpolation, lastChar, normalize }; | ||
//# sourceMappingURL=index.js.map |
@@ -0,5 +1,7 @@ | ||
export type Interpolators = LiteralObject<string> | string[]; | ||
export declare const firstChar: (value: string) => string; | ||
export declare const lastChar: (value: string) => string; | ||
export declare const normalize: (word: string) => string; | ||
export declare const hasPattern: (word: string, pattern: string, force?: boolean) => boolean; | ||
export declare const normalize: (word: string) => string; | ||
export declare const initials: (word: string, size?: number) => string; | ||
export declare function interpolation(template: string, value?: Interpolators): string; |
@@ -6,4 +6,18 @@ import { firstElement, lastElement } from '@rolster/helpers-array'; | ||
export const lastChar = (value) => { | ||
return value.length ? '' : value.charAt(value.length - 1); | ||
return value.length ? value.charAt(value.length - 1) : ''; | ||
}; | ||
export const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace(/á/g, 'a') | ||
.replace(/Á/g, 'A') | ||
.replace(/é/g, 'e') | ||
.replace(/É/g, 'E') | ||
.replace(/í/g, 'i') | ||
.replace(/Í/g, 'I') | ||
.replace(/ó/g, 'o') | ||
.replace(/Ó/g, 'O') | ||
.replace(/ú/g, 'u') | ||
.replace(/Ú/g, 'U'); | ||
}; | ||
export const hasPattern = (word, pattern, force = false) => { | ||
@@ -18,16 +32,2 @@ let filter = pattern.toLowerCase(); | ||
}; | ||
export const normalize = (word) => { | ||
return word | ||
.slice() | ||
.replace('á', 'a') | ||
.replace('Á', 'A') | ||
.replace('é', 'e') | ||
.replace('É', 'E') | ||
.replace('í', 'i') | ||
.replace('Í', 'I') | ||
.replace('ó', 'o') | ||
.replace('Ó', 'O') | ||
.replace('ú', 'u') | ||
.replace('Ú', 'U'); | ||
}; | ||
export const initials = (word, size = 2) => { | ||
@@ -42,2 +42,9 @@ const split = word.split(' '); | ||
}; | ||
const regInterpolation = /{([^{}]*)}/g; | ||
export function interpolation(template, value) { | ||
if (value) { | ||
return template.replace(regInterpolation, (_, key) => Array.isArray(value) ? value[+key] : value[key]); | ||
} | ||
return !regInterpolation.test(template) ? template : ''; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@rolster/helpers-string", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Utility package for manipulating String compatible with Typescript projects.", | ||
@@ -23,3 +23,3 @@ "module": "dist/esm/index.js", | ||
"clean": "rimraf ./dist", | ||
"build": "npm run clean && tsc -p tsconfig.json && rollup -c rollup.config.js", | ||
"build": "npm run clean && tsc -p tsconfig.app.json && rollup -c rollup.config.js", | ||
"test": "jest --coverage", | ||
@@ -36,3 +36,3 @@ "test:watch": "jest --coverage --watch", | ||
"@rollup/plugin-typescript": "^11.1.3", | ||
"@rolster/types": "^1.0.0", | ||
"@rolster/types": "^1.0.2", | ||
"@types/jest": "^29.5.1", | ||
@@ -51,3 +51,7 @@ "jest": "^29.5.0", | ||
}, | ||
"keywords": ["rolster", "typescript", "string"] | ||
"keywords": [ | ||
"rolster", | ||
"typescript", | ||
"string" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18462
156