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 1.0.0 to 2.0.0

.idea/modules.xml

47

index.js
/**
* Title Case a String whilst Excluding Certain Words
* @param {string} title String to be "title cased"
* @param {array} exclusions Array of strings to be excluded from title casing [optional]
* @return {string} Title-cased string
* @param {string} title String to be "title cased"
* @param {array} exclusions Array of strings to be excluded from title casing [optional]
* @return {string} Title-cased string
*/
const titleCase = (title, exclusions = []) => {
return title
.trim()
.toLowerCase()
.split(' ')
.map(function(str, i) {
if (exclusions.indexOf(str) === -1)
return capitalizeFirstChar(str);
else
return str;
})
.join(' ');
}
return title
.trim()
.toLowerCase()
.split(' ')
.map(function filterWords(word) {
if (exclusions.includes(word))
return word;
else
return capitaliseFirstChar(word);
})
.join(' ');
};
const capitalizeFirstChar = word => {
return word.split('').map(function(w,i) {
return i == 0 ? w.toUpperCase() : w;
}).join('');
}
/**
* Capitalise the first character in a string
* @param word
* @returns {string}
*/
const capitaliseFirstChar = (word) => {
return word.split('').map(function(w,i) {
return i == 0 ? w.toUpperCase() : w;
}).join('');
};
exports.titleCase = titleCase;
module.exports = titleCase;
{
"name": "string-title-case",
"version": "1.0.0",
"version": "2.0.0",
"description": "Capitalises first character of each word in string except words from an exclusion array.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,19 +6,14 @@ # StringTitleCase - JavaScript

## Installation
`npm install string-title-case`
```javascript
npm install string-title-case
```
## Usage
Node.JS:
```javascript
const {titleCase} = require('string-title-case');
const titleCase = require('string-title-case');
console.log( titleCase("hello TO The world", ['to','the']) ); // Hello to the World
console.log( titleCase("g'day mate") ); // G'day Mate
```
const myString = 'This messAge IS the best!';
const myTitleCasedString = titleCase(myString, ['is', 'the']);
ES6:
```javascript
import {titleCase} from 'string-title-case';
console.log( titleCase("hello TO The world", ['to','the']) ); // Hello to the World
console.log( titleCase("g'day mate") ); // G'day Mate
console.log(myTitleCasedString); // 'This Message is the Best!'
```

@@ -1,2 +0,2 @@

const {titleCase} = require('./index.js');
const titleCase = require('./index.js');

@@ -9,2 +9,5 @@ if (titleCase("hello To The world!", ['to','the']) !== "Hello to the World!")

if (titleCase("This messAge IS thE best!", ['is', 'the']) !== "This Message is the Best!")
process.exit(1);
process.exit(0);
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