JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22
  • Score
    100M100P100Q53387F
  • License MIT

formatting string keys for display

Package Exports

  • humanize-key
  • humanize-key/dist/humanizeKey.js
  • humanize-key/dist/humanizeKey.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (humanize-key) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Format string keys for display

CI Release & Publish NPM version

Installation

  • npm install humanize-key

Usage

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 than Id
  • ids -> IDsrather than Ids

other custom values can be set by use of makeHumanizeKey

Custom values

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: []