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

@directus/format-title

Package Overview
Dependencies
Maintainers
2
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@directus/format-title - npm Package Compare versions

Comparing version 10.1.0 to 10.1.1

license

5

dist/index.d.ts

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

export declare function formatTitle(title: string, separator?: RegExp): string;
export default formatTitle;
declare function formatTitle(title: string, separator?: RegExp): string;
export { formatTitle as default, formatTitle };

287

dist/index.js

@@ -1,10 +0,279 @@

import { decamelize } from './utils/decamelize.js';
import { capitalize } from './utils/capitalize.js';
import { handleSpecialWords } from './utils/handle-special-words.js';
import { combine } from './utils/combine.js';
export function formatTitle(title, separator) {
if (!separator)
separator = new RegExp('/s|-|_| ', 'g');
return decamelize(title).split(separator).map(capitalize).map(handleSpecialWords).reduce(combine);
// src/utils/decamelize.ts
function decamelize(string) {
return string.replace(/([a-z\d])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1_$2").toLowerCase();
}
export default formatTitle;
// src/utils/capitalize.ts
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.substring(1);
}
// src/constants/acronyms.ts
var acronyms_default = [
"2D",
"3D",
"4WD",
"A2O",
"AI",
"API",
"BIOS",
"CC",
"CCTV",
"CCV",
"CD",
"CD-ROM",
"CIA",
"CMS",
"COBOL",
"CSS",
"CSV",
"CV",
"DB",
"DIY",
"DNA",
"DVD",
"E3",
"EIN",
"ESPN",
"FAQ",
"FAQs",
"FBI",
"FORTRAN",
"FPS",
"FTP",
"HTML",
"HTTP",
"HTTPS",
"ID",
"IP",
"ISO",
"JS",
"JSON",
"LASER",
"M2A",
"M2M",
"M2MM",
"M2O",
"MMORPG",
"NAFTA",
"NASA",
"NDA",
"O2A",
"O2M",
"PDF",
"PHP",
"POP",
"RAM",
"RNGR",
"ROM",
"RPG",
"RTFM",
"RTS",
"SCUBA",
"SDK",
"SITCOM",
"SKU",
"SMTP",
"SQL",
"SSL",
"SSN",
"SWAT",
"TBS",
"TLS",
"TNA",
"TS",
"TTL",
"TV",
"UI",
"URL",
"USB",
"UWP",
"VIP",
"W3C",
"WWE",
"WWF",
"WWW",
"WYSIWYG"
];
// src/constants/articles.ts
var articles_default = ["a", "an", "the"];
// src/constants/conjunctions.ts
var conjunctions_default = [
"and",
"that",
"but",
"or",
"as",
"if",
"when",
"than",
"because",
"while",
"where",
"after",
"so",
"though",
"since",
"until",
"whether",
"before",
"although",
"nor",
"like",
"once",
"unless",
"now",
"except"
];
// src/constants/prepositions.ts
var prepositions_default = [
"about",
"above",
"across",
"after",
"against",
"along",
"among",
"around",
"at",
"because of",
"before",
"behind",
"below",
"beneath",
"beside",
"besides",
"between",
"beyond",
"but",
"by",
"concerning",
"despite",
"down",
"during",
"except",
"excepting",
"for",
"from",
"in",
"in front of",
"inside",
"in spite of",
"instead of",
"into",
"like",
"near",
"of",
"off",
"on",
"onto",
"out",
"outside",
"over",
"past",
"regarding",
"since",
"through",
"throughout",
"to",
"toward",
"under",
"underneath",
"until",
"up",
"upon",
"up to",
"with",
"within",
"without",
"with regard to",
"with respect to"
];
// src/constants/special-case.ts
var special_case_default = [
"2FA",
"4K",
"5K",
"8K",
"AGI",
"BI",
"ChatGPT",
"CTA",
"DateTime",
"GitHub",
"GPT",
"HD",
"IBMid",
"IDs",
"iMac",
"IMAX",
"iOS",
"iPad",
"iPhone",
"iPod",
"LDAP",
"LinkedIn",
"LLM",
"macOS",
"McDonalds",
"ML",
"MySQL",
"NLG",
"NLP",
"NLU",
"OpenAI",
"PDFs",
"PEFT",
"pH",
"PostgreSQL",
"SEO",
"TTS",
"UHD",
"UUID",
"XSS",
"YouTube"
];
// src/utils/handle-special-words.ts
function handleSpecialWords(str, index, words) {
const lowercaseStr = str.toLowerCase();
const uppercaseStr = str.toUpperCase();
for (const special of special_case_default) {
if (special.toLowerCase() === lowercaseStr)
return special;
}
if (acronyms_default.includes(uppercaseStr))
return uppercaseStr;
if (index === 0)
return str;
if (index === words.length - 1)
return str;
if (str.length >= 4)
return str;
if (prepositions_default.includes(lowercaseStr))
return lowercaseStr;
if (conjunctions_default.includes(lowercaseStr))
return lowercaseStr;
if (articles_default.includes(lowercaseStr))
return lowercaseStr;
return str;
}
// src/utils/combine.ts
function combine(acc, str) {
return `${acc} ${str}`;
}
// src/index.ts
function formatTitle(title, separator = new RegExp("\\s|-|_", "g")) {
return decamelize(title).split(separator).map(capitalize).map(handleSpecialWords).reduce(combine);
}
var src_default = formatTitle;
export {
src_default as default,
formatTitle
};
{
"name": "@directus/format-title",
"version": "10.1.0",
"type": "module",
"description": "Custom string formatter that converts any string into [Title Case](http://www.grammar-monster.com/lessons/capital_letters_title_case.htm)",
"version": "10.1.1",
"description": "Custom formatter that converts any string into Title Case",
"keywords": [

@@ -17,2 +16,12 @@ "title-case",

],
"homepage": "https://directus.io",
"repository": {
"type": "git",
"url": "https://github.com/directus/directus.git",
"directory": "packages/format-title"
},
"funding": "https://github.com/directus/directus?sponsor=1",
"license": "MIT",
"author": "rijkvanzanten <rijkvanzanten@me.com>",
"type": "module",
"exports": {

@@ -22,46 +31,20 @@ ".": "./dist/index.js",

},
"module": "dist/format-title.bundler.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"author": "rijkvanzanten <rijkvanzanten@me.com>",
"repository": {
"type": "git",
"url": "git+https://github.com/directus/format-title.git"
"devDependencies": {
"tsup": "8.0.2",
"typescript": "5.3.3",
"vitest": "1.3.1",
"@directus/tsconfig": "1.0.1"
},
"license": "MIT",
"engines": {
"node": ">=6.0.0"
"node": ">=18"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"lint-staged": "^13.1.2",
"prettier": "^2.8.4",
"rimraf": "4.1.2",
"simple-git-hooks": "^2.8.1",
"tsx": "^3.12.3",
"typescript": "^4.9.5",
"vitest": "^0.28.5"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,ts}": "eslint --fix"
},
"gitHead": "24621f3934dc77eb23441331040ed13c676ceffd",
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc --build",
"dev": "tsx watch ./src/index.ts",
"lint": "eslint src",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest"
"build": "pnpm run '/^bundle|typecheck$/'",
"bundle": "tsup src/index.ts --format=esm --dts",
"test": "vitest --watch=false",
"typecheck": "tsc --noEmit"
}
}
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