lowercase-keys
Lowercase the keys of an object
Last updated 2 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install lowercase-keys 
SYNC missed versions from official npm registry.

lowercase-keys

Lowercase the keys of an object

Check out map-obj if you need support for deep iteration.

Install

npm install lowercase-keys

Usage

import lowercaseKeys from 'lowercase-keys';

lowercaseKeys({FOO: true, bAr: false});
//=> {foo: true, bar: false}

API

lowercaseKeys(object, options?)

Returns a new object with the keys lowercased.

options

Type: object

onConflict

Type: Function

A function that is called when multiple keys in the input object map to the same lowercased key.

The function receives the lowercased key, the new value, and the existing value, and should return the value to use.

By default, the last value wins.

import lowercaseKeys from 'lowercase-keys';

// Throw on conflict
lowercaseKeys({Key: 'value1', key: 'value2'}, {
	onConflict({key}) {
		throw new Error(`Duplicate key: ${key}`);
	}
});

// Keep the first value
lowercaseKeys({Key: 'value1', key: 'value2'}, {
	onConflict: ({existingValue}) => existingValue,
});
//=> {key: 'value1'}

Current Tags

  • 4.0.1                                ...           latest (2 months ago)

6 Versions

  • 4.0.1                                ...           2 months ago
  • 4.0.0                                ...           2 months ago
  • 3.0.0                                ...           4 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 109
This Month 162
Last Day 6
Last Week 125
Last Month 948
Dependencies (0)
None
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |