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

string-title-case

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-title-case - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

19

index.js
/**
* Valid word starting characters
* @type {[string,string,string,string]}
*/
const CONTAINERS = ['(', '[', '{'];
/**
* Title Case a String whilst Excluding Certain Words

@@ -12,3 +18,3 @@ * @param {string} title String to be "title cased"

.split(' ')
.map(function filterWords(word) {
.map((word) => {
if (exclusions.includes(word))

@@ -28,7 +34,12 @@ return word;

const capitaliseFirstChar = (word) => {
return word.split('').map(function(w,i) {
return i == 0 ? w.toUpperCase() : w;
}).join('');
return word
.split('')
.map((letter, index, array) => {
return index === 0 || CONTAINERS.includes(array[index - 1]) ? letter.toUpperCase() : letter;
})
.join('');
};
module.exports = titleCase;
{
"name": "string-title-case",
"version": "2.0.0",
"version": "3.0.0",
"description": "Capitalises first character of each word in string except words from an exclusion array.",

@@ -24,3 +24,4 @@ "main": "index.js",

},
"homepage": "https://github.com/bradleyflood/string-title-case#readme"
"homepage": "https://github.com/bradleyflood/string-title-case#readme",
"dependencies": {}
}

@@ -6,3 +6,3 @@ const titleCase = require('./index.js');

if (titleCase("g'day mate ") !== "G'day Mate")
if (titleCase("g'day (mate) ") !== "G'day (Mate)")
process.exit(1);

@@ -9,0 +9,0 @@

Sorry, the diff of this file is not supported yet

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