Socket
Socket
Sign inDemoInstall

title-case

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

title-case - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

11

dist.es2015/index.js

@@ -1,5 +0,5 @@

const SMALL_WORDS = /^(?:a|an|and|as|at|but|by|en|for|if|in|neither|nor|of|on|only|or|per|so|than|that|the|to|v\.?|versus|vs\.?|via|when|with|without|yet)$/i;
const WORDS = /[^ :–—-]+|./g;
const SMALL_WORDS = /\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\.?|versus|via|when|with|without|yet)\b/i;
const TOKENS = /[^\s:–—-]+|./g;
const WHITESPACE = /\s/;
const IS_CAPITALIZED = /.(?=[A-Z]|\..)/;
const IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
const ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;

@@ -10,7 +10,7 @@ export function titleCase(input) {

// tslint:disable-next-line
while ((m = WORDS.exec(input)) !== null) {
while ((m = TOKENS.exec(input)) !== null) {
const { 0: token, index } = m;
if (
// Ignore already capitalized words.
!IS_CAPITALIZED.test(token) &&
!IS_MANUAL_CASE.test(token) &&
// Ignore small words except at beginning or end.

@@ -23,2 +23,3 @@ (!SMALL_WORDS.test(token) ||

WHITESPACE.test(input.charAt(index + token.length + 1)))) {
// Find and uppercase first word character, skips over *modifiers*.
result += token.replace(ALPHANUMERIC_PATTERN, m => m.toUpperCase());

@@ -25,0 +26,0 @@ continue;

@@ -54,3 +54,9 @@ import { inspect } from "util";

"Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event"
]
],
[
"the quick brown fox jumps over the lazy dog",
"The Quick Brown Fox Jumps over the Lazy Dog"
],
["newcastle upon tyne", "Newcastle upon Tyne"],
["newcastle *upon* tyne", "Newcastle *upon* Tyne"]
];

@@ -57,0 +63,0 @@ describe("swap case", () => {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SMALL_WORDS = /^(?:a|an|and|as|at|but|by|en|for|if|in|neither|nor|of|on|only|or|per|so|than|that|the|to|v\.?|versus|vs\.?|via|when|with|without|yet)$/i;
const WORDS = /[^ :–—-]+|./g;
const SMALL_WORDS = /\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\.?|versus|via|when|with|without|yet)\b/i;
const TOKENS = /[^\s:–—-]+|./g;
const WHITESPACE = /\s/;
const IS_CAPITALIZED = /.(?=[A-Z]|\..)/;
const IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
const ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;

@@ -12,7 +12,7 @@ function titleCase(input) {

// tslint:disable-next-line
while ((m = WORDS.exec(input)) !== null) {
while ((m = TOKENS.exec(input)) !== null) {
const { 0: token, index } = m;
if (
// Ignore already capitalized words.
!IS_CAPITALIZED.test(token) &&
!IS_MANUAL_CASE.test(token) &&
// Ignore small words except at beginning or end.

@@ -25,2 +25,3 @@ (!SMALL_WORDS.test(token) ||

WHITESPACE.test(input.charAt(index + token.length + 1)))) {
// Find and uppercase first word character, skips over *modifiers*.
result += token.replace(ALPHANUMERIC_PATTERN, m => m.toUpperCase());

@@ -27,0 +28,0 @@ continue;

@@ -56,3 +56,9 @@ "use strict";

"Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event"
]
],
[
"the quick brown fox jumps over the lazy dog",
"The Quick Brown Fox Jumps over the Lazy Dog"
],
["newcastle upon tyne", "Newcastle upon Tyne"],
["newcastle *upon* tyne", "Newcastle *upon* Tyne"]
];

@@ -59,0 +65,0 @@ describe("swap case", () => {

{
"name": "title-case",
"version": "3.0.0",
"version": "3.0.1",
"description": "Transform a string into title case following English rules",

@@ -72,6 +72,2 @@ "main": "dist/index.js",

},
"dependencies": {
"lower-case": "^2.0.0",
"upper-case": "^2.0.0"
},
"devDependencies": {

@@ -89,3 +85,3 @@ "@size-limit/preset-small-lib": "^2.2.1",

},
"gitHead": "55911ca17c2e0c964b9b84143e14e29ffc9ff499"
"gitHead": "a3df3a43bfd3d8e3386d0fb09b69454b91516d18"
}

@@ -7,3 +7,3 @@ # Title Case

> Transform a string into title case following English rules.
> Transform a string into [title case](https://en.wikipedia.org/wiki/Letter_case#Title_case) following English rules.

@@ -10,0 +10,0 @@ ## Installation

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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