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

string-kit

Package Overview
Dependencies
Maintainers
1
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-kit - npm Package Compare versions

Comparing version 0.16.1 to 0.16.2

37

lib/toTitleCase.js

@@ -31,8 +31,38 @@ /*

module.exports = function toTitleCase( str , options ) {
const DEFAULT_OPTIONS = {
underscoreToSpace: true ,
lowerCaseWords: new Set( [ 'a' , 'the' , 'of' , 'in' ] )
} ;
module.exports = ( str , options = DEFAULT_OPTIONS ) => {
if ( ! str || typeof str !== 'string' ) { return '' ; }
options = options || {} ;
if ( options.dashToSpace ) {
str = str.replace( /-+/g , ' ' ) ;
}
if ( options.underscoreToSpace ) {
str = str.replace( /_+/g , ' ' ) ;
}
// Squash multiple spaces into only one, and trim
str = str.replace( / +/g , ' ' ).trim() ;
var lowerCaseWords =
options.lowerCaseWords instanceof Set ? options.lowerCaseWords :
Array.isArray( options.lowerCaseWords ) ? new Set( options.lowerCaseWords ) :
null ;
var wordCount = 0 ;
return str.replace( /[^\s_-]+/g , ( part ) => {
wordCount ++ ;
if ( wordCount > 1 && options.lowerCaseWords ) {
let lowerCased = part.toLowerCase() ;
if ( options.lowerCaseWords.has( lowerCased ) ) { return lowerCased ; }
}
if ( options.zealous ) {

@@ -45,10 +75,7 @@ if ( options.preserveAllCaps && part === part.toUpperCase() ) {

return part[ 0 ].toUpperCase() + part.slice( 1 ).toLowerCase() ;
}
return part[ 0 ].toUpperCase() + part.slice( 1 ) ;
} ) ;
} ;

2

package.json
{
"name": "string-kit",
"version": "0.16.1",
"version": "0.16.2",
"engines": {

@@ -5,0 +5,0 @@ "node": ">=14.15.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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