@t0ri/strings
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "@t0ri/strings", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "", | ||
@@ -18,4 +18,5 @@ "repository": "https://github.com/t0ri/FEW2.1-libs", | ||
"eslint-plugin-import": "^2.18.2", | ||
"jest": "^24.9.0" | ||
"jest": "^24.9.0", | ||
"rollup-plugin-terser": "^5.1.2" | ||
} | ||
} |
@@ -1,8 +0,21 @@ | ||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
file: 'umd/strings.js', | ||
format: 'umd', | ||
name: 'strings', | ||
import { terser } from 'rollup-plugin-terser' | ||
export default [ | ||
{ | ||
input: 'src/index.js', | ||
plugins: [terser()], | ||
output: { | ||
file: 'umd/strings.js', | ||
format: 'umd', | ||
name: 'strings', | ||
esModule: false, | ||
}, | ||
}, | ||
} | ||
{ | ||
input: 'src/index.js', | ||
output: { | ||
file: 'esm/strings.js', | ||
format: 'esm', | ||
}, | ||
}, | ||
] |
@@ -1,199 +0,1 @@ | ||
(function (factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
}((function () { 'use strict'; | ||
String.prototype.capitalize = function (option) { | ||
const string = String(this); | ||
if (string.validString()) { | ||
// Challenge 1: capitalize() | ||
// Make the first character of a given string uppercase | ||
if (option === 'firstLetter') { | ||
return string[0].toUpperCase() + string.slice(1) | ||
} | ||
// Challenge 3: capitalizeWords() | ||
// Make the first letter of each word uppercase | ||
if (option === 'allFirstLetter') { | ||
let capitalized = ''; | ||
string.split(' ').forEach((word) => { | ||
capitalized += word.capitalize('firstLetter') + ' '; | ||
}); | ||
return capitalized.trim() | ||
} | ||
// Challenge 2: allCaps() | ||
// Makes all characters uppercase | ||
if (option === 'all') { | ||
let capitalized = ''; // spread operator below won't work without this semicolon and i hate it 😓 | ||
[...string].forEach((char) => { | ||
capitalized += char.toUpperCase(); | ||
}); | ||
return capitalized | ||
} | ||
} | ||
return string | ||
}; | ||
String.prototype.clean = function (option) { | ||
let string = String(this); | ||
if (string.validString()) { | ||
// Challenge 4: removeExtraSpace() | ||
// Remove all spaces from the beginning and end of a String | ||
if (option === 'trimSpaces') { | ||
string = string.trim(); | ||
if (string !== '') { | ||
return string | ||
} | ||
} | ||
// Challenge 4.5: removeExtraSpaces() | ||
// Remove any extra spaces in the middle, and the beginning/end | ||
if (option === 'trimAllSpaces') { | ||
let cleaned = ''; | ||
string.split(' ').forEach((word) => { | ||
const trimmed = word.clean('trimSpaces'); | ||
if (trimmed !== undefined) { | ||
cleaned += word.clean('trimSpaces') + ' '; | ||
} | ||
}); | ||
return cleaned.trim() | ||
} | ||
} | ||
}; | ||
String.prototype.changeCase = function (option) { | ||
// Challenge 5: kabobCase() | ||
// Removes extra spaces and replaces spaces with "-", & makes all characters lowercase | ||
if (option === 'kabob') { | ||
const string = String(this).removePunctuation().clean('trimAllSpaces'); | ||
return string.split(' ').join('-').slice(0, string.length).toLowerCase() | ||
} | ||
// Challenge 6: snakeCase() | ||
// Removes extra space and replaces spaces with "_", & makes all characters lowercase | ||
if (option === 'snake') { | ||
const string = String(this).removePunctuation().clean('trimAllSpaces'); | ||
return string.split(' ').join('_').slice(0, string.length).toLowerCase() | ||
} | ||
// Challenge 7 camelCase() | ||
// Lowercases the first character of the first word; | ||
// uppercases the first character of all other words; & removes all spaces | ||
if (option === 'camel') { | ||
const string = String(this).removePunctuation().clean('trimAllSpaces').toLowerCase(); | ||
let capitalized = string.split(' ').map((word) => { | ||
if (word === string[0]) { | ||
return word | ||
} | ||
if (word !== '') { | ||
return word.capitalize('firstLetter') | ||
} | ||
}); | ||
capitalized = capitalized.join(''); | ||
return capitalized.charAt(0).toLowerCase() + capitalized.slice(1, string.length) | ||
} | ||
}; | ||
// ⬇️ Helpers! ⬇️ | ||
// removePunctuation: filters out punctuation, keeps ' ' | ||
String.prototype.removePunctuation = function () { | ||
const string = String(this); | ||
const noPunct = [...string].filter((char) => { | ||
if (char === ' ') { | ||
return char | ||
} | ||
return char.isAlpha() | ||
}); | ||
return noPunct.join('') | ||
}; | ||
// validString: checks if string is longer than 1 (except I forgot to use it) | ||
String.prototype.validString = function () { | ||
const string = String(this); | ||
if (string) { | ||
return true | ||
} | ||
return false | ||
}; | ||
// isAlpha: checks if string is a single letter | ||
String.prototype.isAlpha = function () { | ||
const string = String(this); | ||
return string.length === 1 && string.match(/[a-z]/i) | ||
}; | ||
// """Test""" Methods | ||
// function test() { | ||
// function capitalize(input) { | ||
// console.log('--- Testing Challenge 1: capitalize() ---') | ||
// console.log('testInput =', input) | ||
// console.log('testIinput.capitalize(\'firstLetter\') =', input.capitalize('firstLetter'), '\n') | ||
// } | ||
// function allCaps(input) { | ||
// console.log('--- Testing Challenge 2: allCaps() ---') | ||
// console.log('testInput =', input) | ||
// console.log('testIinput.capitalize(\'all\') =', input.capitalize('all'), '\n') | ||
// } | ||
// function capitalizeWords(input) { | ||
// console.log('--- Testing Challenge 3: capitalizeWords() ---') | ||
// console.log('testInput =', input) | ||
// console.log('testIinput.capitalize(\'allFirstLetter\') =', input.capitalize('allFirstLetter'), '\n') | ||
// } | ||
// function removeExtraSpaces(input) { | ||
// console.log('--- Testing Challenge 4: removeExtraSpaces() ---') | ||
// console.log('testInput =', input) | ||
// console.log('testIinput.clean(\'trimAllSpaces\') =', input.clean('trimAllSpaces'), '\n') | ||
// } | ||
// function kabobCase(input) { | ||
// console.log('--- Testing Challenge 5: kabobCase() ---') | ||
// console.log('testInput =', spaceInput) | ||
// console.log('testIinput.changeCase(\'kabob\') =', spaceInput.changeCase('kabob'), '\n') | ||
// } | ||
// function snakeCase(input) { | ||
// console.log('--- Testing Challenge 6: snakeCase() ---') | ||
// console.log('testInput =', spaceInput) | ||
// console.log('testIinput.changeCase(\'snake\') =', spaceInput.changeCase('snake'), '\n') | ||
// } | ||
// function camelCase(input) { | ||
// console.log('--- Testing Challenge 7: camelCase() ---') | ||
// console.log('testInput =', spaceInput) | ||
// console.log('testIinput.changeCase(\'camel\') =', spaceInput.changeCase('camel')) | ||
// } | ||
// let capitalizeInput = 'hello mitchell or ki' | ||
// capitalize(capitalizeInput) | ||
// allCaps(capitalizeInput) | ||
// capitalizeWords(capitalizeInput) | ||
// let spaceInput = ' hello Mitchell? OR ki!' | ||
// removeExtraSpaces(spaceInput) | ||
// kabobCase(spaceInput) | ||
// snakeCase(spaceInput) | ||
// camelCase(spaceInput) | ||
// } | ||
// test() | ||
}))); | ||
!function(t){"function"==typeof define&&define.amd?define(t):t()}((function(){"use strict";String.prototype.capitalize=function(t){const i=String(this);if(i.validString()){if("firstLetter"===t)return i[0].toUpperCase()+i.slice(1);if("allFirstLetter"===t){let t="";return i.split(" ").forEach(i=>{t+=i.capitalize("firstLetter")+" "}),t.trim()}if("all"===t){let t="";return[...i].forEach(i=>{t+=i.toUpperCase()}),t}}return i},String.prototype.clean=function(t){let i=String(this);if(i.validString()){if("trimSpaces"===t&&""!==(i=i.trim()))return i;if("trimAllSpaces"===t){let t="";return i.split(" ").forEach(i=>{void 0!==i.clean("trimSpaces")&&(t+=i.clean("trimSpaces")+" ")}),t.trim()}}},String.prototype.changeCase=function(t){if("kabob"===t){const t=String(this).removePunctuation().clean("trimAllSpaces");return t.split(" ").join("-").slice(0,t.length).toLowerCase()}if("snake"===t){const t=String(this).removePunctuation().clean("trimAllSpaces");return t.split(" ").join("_").slice(0,t.length).toLowerCase()}if("camel"===t){const t=String(this).removePunctuation().clean("trimAllSpaces").toLowerCase();let i=t.split(" ").map(i=>i===t[0]?i:""!==i?i.capitalize("firstLetter"):void 0);return(i=i.join("")).charAt(0).toLowerCase()+i.slice(1,t.length)}},String.prototype.removePunctuation=function(){return[...String(this)].filter(t=>" "===t?t:t.isAlpha()).join("")},String.prototype.validString=function(){return!!String(this)},String.prototype.isAlpha=function(){const t=String(this);return 1===t.length&&t.match(/[a-z]/i)}})); |
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
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
19090
9
414
0
6