uniformize
Advanced tools
Comparing version 1.0.8 to 2.0.0
"use strict"; | ||
// src/index.ts | ||
Object.defineProperty(String.prototype, "removeAccents", { | ||
value: function() { | ||
return this.normalize("NFD").replace(/\p{Diacritic}/gu, ""); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "standardize", { | ||
value: function(noTrim) { | ||
if (!noTrim) return this.removeAccents().toLowerCase(); | ||
return this.removeAccents().toLowerCase().trim(); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "toTitle", { | ||
value: function(toLowerCase) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
return text.charAt(0).toUpperCase() + text.slice(1); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "capitalize", { | ||
value: function(toLowerCase) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
text.replace(/(^\w{1})|(\s+\w{1})/g, (char) => char.toUpperCase()); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "subText", { | ||
value: function(query, strict) { | ||
if (strict) return this.standardize() === query?.standardize(); | ||
return this.standardize().includes(query?.standardize()); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "unidecode", { | ||
value: function(keepAccent) { | ||
const emojiRegex = /[\p{Emoji}]/gu; | ||
const decoded = this.replace(emojiRegex, "").trim(); | ||
if (keepAccent) return decoded; | ||
return decoded.standardize(); | ||
}, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(String.prototype, "removeBacktick", { | ||
value: function() { | ||
return this.replace(/`/g, ""); | ||
}, | ||
enumerable: false | ||
}); | ||
String.prototype.removeAccents = function() { | ||
return this.normalize("NFD").replace(/\p{Diacritic}/gu, ""); | ||
}; | ||
String.prototype.standardize = function(noTrim) { | ||
if (!noTrim) return this.removeAccents().toLowerCase(); | ||
return this.removeAccents().toLowerCase().trim(); | ||
}; | ||
String.prototype.toTitle = function(toLowerCase) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
return text.charAt(0).toUpperCase() + text.slice(1); | ||
}; | ||
String.prototype.capitalize = function(toLowerCase) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
return text.replace(/(^\w{1})|(\s+\w{1})/g, (char) => char.toUpperCase()); | ||
}; | ||
String.prototype.subText = function(query, strict) { | ||
if (strict) return this.standardize() === query?.standardize(); | ||
return this.standardize().includes(query?.standardize() ?? ""); | ||
}; | ||
String.prototype.unidecode = function(keepAccent) { | ||
const emojiRegex = /[\p{Emoji}]/gu; | ||
const decoded = this.replace(emojiRegex, "").trim(); | ||
if (keepAccent) return decoded; | ||
return decoded.standardize(); | ||
}; | ||
String.prototype.removeBacktick = function() { | ||
return this.replace(/`/g, ""); | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -5,5 +5,5 @@ { | ||
"main": "dist/index.js", | ||
"types": "dist/global.d.ts", | ||
"types": "dist/types.d.ts", | ||
"type": "commonjs", | ||
"version": "1.0.8", | ||
"version": "2.0.0", | ||
"repository": { | ||
@@ -24,4 +24,4 @@ "type": "git", | ||
"cp": { | ||
"win32": "xcopy /i /Y .\\src\\global.d.ts .\\dist", | ||
"darwin": "cp ./src/global.d.ts ./dist" | ||
"win32": "xcopy /i /Y .\\src\\types.d.ts .\\dist", | ||
"darwin": "cp ./src/types.d.ts ./dist" | ||
} | ||
@@ -28,0 +28,0 @@ }, |
@@ -18,9 +18,6 @@ # Uniformize | ||
As already said, it extends the `String` prototype, by using the global module. So, in your `tsconfig.json` : | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"typeRoots": ["node_modules/@types", "node_modules/uniformize"] | ||
} | ||
} | ||
At the root (your `index.ts` file for example), import the package once to extend the `String` prototype: | ||
```ts | ||
import "uniformize"; | ||
``` | ||
@@ -27,0 +24,0 @@ |
@@ -1,42 +0,26 @@ | ||
Object.defineProperty(String.prototype, "removeAccents", { | ||
value: function () { | ||
return this.normalize("NFD").replace(/\p{Diacritic}/gu, ""); | ||
}, | ||
enumerable: false, | ||
}); | ||
String.prototype.removeAccents = function () { | ||
return this.normalize("NFD").replace(/\p{Diacritic}/gu, ""); | ||
}; | ||
Object.defineProperty(String.prototype, "standardize", { | ||
value: function (noTrim?: boolean) { | ||
if (!noTrim) return this.removeAccents().toLowerCase(); | ||
return this.removeAccents().toLowerCase().trim(); | ||
}, | ||
enumerable: false, | ||
}); | ||
String.prototype.standardize = function (noTrim?: boolean) { | ||
if (!noTrim) return this.removeAccents().toLowerCase(); | ||
return this.removeAccents().toLowerCase().trim(); | ||
}; | ||
Object.defineProperty(String.prototype, "toTitle", { | ||
value: function (toLowerCase?: boolean) { | ||
String.prototype.toTitle = function (toLowerCase?: boolean) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
return text.charAt(0).toUpperCase() + text.slice(1); | ||
}, | ||
enumerable: false, | ||
}); | ||
}; | ||
Object.defineProperty(String.prototype, "capitalize", { | ||
value: function (toLowerCase?: boolean) { | ||
String.prototype.capitalize = function (toLowerCase?: boolean) { | ||
const text = toLowerCase ? this.toLowerCase() : this; | ||
text.replace(/(^\w{1})|(\s+\w{1})/g, (char: string) => char.toUpperCase()); | ||
}, | ||
enumerable: false, | ||
}); | ||
return text.replace(/(^\w{1})|(\s+\w{1})/g, (char: string) => char.toUpperCase()); | ||
}; | ||
Object.defineProperty(String.prototype, "subText", { | ||
value: function (query?: string | null, strict?: boolean) { | ||
if (strict) return this.standardize() === query?.standardize(); | ||
return this.standardize().includes(query?.standardize()); | ||
}, | ||
enumerable: false, | ||
}); | ||
String.prototype.subText = function (query?: string | null, strict?: boolean) { | ||
if (strict) return this.standardize() === query?.standardize(); | ||
return this.standardize().includes(query?.standardize() ?? ""); | ||
}; | ||
Object.defineProperty(String.prototype, "unidecode", { | ||
value: function (keepAccent?: boolean) { | ||
String.prototype.unidecode = function (keepAccent?: boolean) { | ||
const emojiRegex = /[\p{Emoji}]/gu; | ||
@@ -46,11 +30,6 @@ const decoded = this.replace(emojiRegex, "").trim(); | ||
return decoded.standardize(); | ||
}, | ||
enumerable: false, | ||
}); | ||
}; | ||
Object.defineProperty(String.prototype, "removeBacktick", { | ||
value: function () { | ||
return this.replace(/`/g, ""); | ||
}, | ||
enumerable: false, | ||
}); | ||
String.prototype.removeBacktick = function () { | ||
return this.replace(/`/g, ""); | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15127
174
110
1