Format string keys for display
npm install humanize-key
import humanizeKey from 'humanize-key'
// or
const { humanizeKey } = require('humanize-key')
const displayString = humanizeKey(key)
const display = (obj) => {
forEach(obj, (value, key) => console.log(`${humanizeKey(key)}: ${value}`))
}
display({
id: 12,
userName: 'bobby',
'first-name': 'Bob',
last_name: 'Roberts',
account_id: 321,
})
ID: 12
User Name: bobby
First Name: Bob
Last Name: Roberts
Account ID: 321
currently there are two exemptions to the default capitalization
id
->ID
rather thanId
ids
->IDs
rather thanIds
other custom values can be set by use of makeHumanizeKey
domains-specific acronyms
import { makeHumanizeKey } from 'humanize-key'
const humanizeKey = makeHumanizeKey({ acronyms: ['IRS', 'SSN'] })
const obj = {
id: 12,
ssn_last_four: '1234',
'irs-account-number': '5678',
}
ID: 12
SSN Last Four: 1234
IRS Account Number: 5678
custom capitalization for terms of art
import { makeHumanizeKey } from 'humanize-key'
const humanizeKey = makeHumanizeKey({
acronyms: ['URL']
uniques: {
oauth: "OAuth",
uuids: "UUIDs",
}
})
display({
oauth_url: 'http://localhost:3000/oauth/callback',
recent_uuids: [],
})
OAuth URL: http://localhost:3000/oauth/callback
Recent UUIDs: []