@ribajs/utils
Advanced tools
Comparing version 1.9.0-beta.1 to 1.9.0-beta.2
{ | ||
"name": "@ribajs/utils", | ||
"description": "Utils module of Riba.js", | ||
"version": "1.9.0-beta.1", | ||
"version": "1.9.0-beta.2", | ||
"author": "Pascal Garber <pascal@artandcode.studio>", | ||
@@ -35,3 +35,12 @@ "contributors": [ | ||
], | ||
"scripts": {}, | ||
"scripts": { | ||
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix && tsc --noEmit", | ||
"build": "npm run lint && tsc", | ||
"build:ts": "npm run lint", | ||
"clean": "rm -rf ./dist ./lib" | ||
}, | ||
"files": [ | ||
"/src", | ||
"/dist" | ||
], | ||
"bugs": { | ||
@@ -43,7 +52,11 @@ "url": "https://github.com/ribajs/riba/issues" | ||
"devDependencies": { | ||
"@babel/runtime": "^7.11.2", | ||
"@babel/runtime-corejs3": "^7.11.2", | ||
"@ribajs/tsconfig": "1.9.0-beta.1", | ||
"babel-jest": "^26.3.0" | ||
"@babel/runtime": "^7.12.0", | ||
"@babel/runtime-corejs3": "^7.12.0", | ||
"@ribajs/eslint-config": "1.9.0-beta.2", | ||
"@ribajs/tsconfig": "1.9.0-beta.2", | ||
"@types/jest": "^26.0.14", | ||
"babel-jest": "^26.5.2", | ||
"eslint": "^7.11.0", | ||
"typescript": "^4.0.3" | ||
} | ||
} |
@@ -169,2 +169,36 @@ export const couldBeJson = (str?: string | null) => { | ||
/** | ||
* Remove all special chars from a string | ||
* @see https://stackoverflow.com/a/11090301/1465919 | ||
* @param str | ||
*/ | ||
const withoutSpecialChars = (str: string) => { | ||
// str = str.replace(/[^\w\s]/gi, ""); // http://stackoverflow.com/a/4374890 | ||
str = str.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>{}[\]\\/]/gi, ""); | ||
return str; | ||
}; | ||
/** | ||
* Removes multiple tabs, newlines, etc from a string | ||
* @param str | ||
*/ | ||
const withoutMultiWhitespace = (str: string) => { | ||
str = str.replace(/\s\s+/g, " "); | ||
return str; | ||
}; | ||
/** | ||
* Formats a string into a handle. | ||
* E.g. '100% M & Ms!!!' -> 100-m-ms | ||
* @see https://help.shopify.com/themes/liquid/filters/string-filters#handle-handleize | ||
*/ | ||
export const handleize = (str: string) => { | ||
str = str.trim(); | ||
str = withoutMultiWhitespace(str); | ||
str = withoutSpecialChars(str); | ||
str = str.toLowerCase(); | ||
str = str.replace(/ /g, "-"); | ||
return str; | ||
}; | ||
export const stripHtml = (html: string) => { | ||
@@ -171,0 +205,0 @@ const tmp = document.createElement("DIV"); |
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
84955
28
1887
8