Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
capitalize
Advanced tools
Capitalize the first letter of a string, or all words in a string.
Capitalize the first letter of a string:
var capitalize = require('capitalize')
var test = require('tape')
test('Capitalize first letter', function (t) {
t.plan(1)
t.equal(capitalize("united states"), "United states")
})
Or capitalize each word in a string:
test('Capitalize each word', function (t) {
t.plan(1)
t.equal(capitalize.words("united states"), "United States")
})
No matter the original case:
test('Capitalize first letter with original string...', function (t) {
t.plan(2)
t.test('...in upper case', function (t1) {
t1.plan(1)
t1.equal(capitalize.words("UNITED STATES"), "United States")
})
t.test('...in mixed case', function (t2) {
t2.plan(1)
t2.equal(capitalize.words("uNiTeD sTaTeS"), "United States")
})
})
test('Capitalize each word with original string...', function (t) {
t.plan(2)
t.test('...in upper case', function (t1) {
t1.plan(1)
t1.equal(capitalize.words("UNITED STATES"), "United States")
})
t.test('...in mixed case', function (t2) {
t2.plan(1)
t2.equal(capitalize.words("uNiTeD sTaTeS"), "United States")
})
})
Thanks to @c990802 and Stack Overflow, capitalize handles international characters:
test('Capitalize words with international characters', function (t) {
t.plan(1)
t.equal(capitalize.words('hello-cañapolísas'), 'Hello-Cañapolísas')
})
and thanks to @ultraflynn, capitalize properly handles quotes within the string:
test('Capitalize each word, ignoring quotes', function(t) {
t.plan(1)
t.equal(capitalize.words("it's a nice day"), "It's A Nice Day")
})
npm install capitalize
MIT
FAQs
capitalize the first letter of a string, or all words in a string
The npm package capitalize receives a total of 57,127 weekly downloads. As such, capitalize popularity was classified as popular.
We found that capitalize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.