Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string-wks

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-wks - npm Package Compare versions

Comparing version 1.0.2 to 1.0.5

readme.md

3

package.json
{
"name": "string-wks",
"version": "1.0.2",
"version": "1.0.5",
"description": "Some string manipulation functions that I need to use commonly",

@@ -9,2 +9,3 @@ "main": "string.js",

},
"type": "module",
"repository": {

@@ -11,0 +12,0 @@ "type": "git",

//exporting functions
exports.capitalize = capitalize;
exports.noSpace = noSpace;
exports.escape = escape;
exports.simplify = simplify;
exports.kebab = kebab;
export {
capitalize,
noSpace,
escape,
escapeSimple,
kebab,
oneSpace,
elaps,
validateURL,
trimTo
};
//capitalize first letter of a string and turn others to small caps. capitalize("hello") > Hello
function capitalize(str) {
//crop fist letter
const firstLetter = str.substring(0, 1);
//crop the other letters expect for the first one
const otherLetters = str.substring(1, str.length);
//capitalize first Letter and assemble it with lowercase other Letters
const finalString = firstLetter.toUpperCase() + otherLetters.toLowerCase();
//return the cropped version
return finalString;
const nStr = str.trim();
return (
nStr.trim().substring(0, 1).toUpperCase() +
nStr.substring(1, nStr.length).toLowerCase()
);
}
//noSpace. remove all spaces in your noSpace("He ll o") > "Hello"
function noSpace(str) {
return str.replace(" ", "");
return str.replace(/ /g, "");
}
//remove all non-alphanumeric characters from string. escape("hello&#9!_WORLD") >hello9WORLD
function escape(str) {
//regular expression
const regExp = /[^a-z0-9]/gi;
return str.replace(regExp, "");
return str.replace(/[^a-z0-9]/gi, "");
}
//simplify
function simplify(str){
let text = str;
text = escape(text);
text = noSpace(text);
return text.toLowerCase();
function escapeSimple(str) {
return oneSpace(str.replace(/[^a-z0-9| ]/gi, ""));
}
//kebab case
function kebab(str) {
return escape(str).toLowerCase().replace(" ", "-");
return str
.trim()
.toLowerCase()
.replace(/[^a-z0-9/d-]/gi, "-");
}
function oneSpace(str) {
return str.replace(/ +/g, " ");
}
function elaps(str) {
return str.replace(/\s\s+/g, " ");
}
function validateURL(URL) {
const regExp = new RegExp(
"^(https?:\\/\\/)?" +
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" +
"((\\d{1,3}\\.){3}\\d{1,3}))" +
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" +
"(\\?[;&a-z\\d%_.~+=-]*)?" +
"(\\#[-a-z\\d_]*)?$",
"i"
);
return !!regExp.test(URL);
}
function trimTo(string, count, co){
const dotsCounter = co ? co : 100;
const dots = string.length >= dotsCounter ? "..." : "";
return string.substring(0, count).trim() + dots;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc