1.0.2 • Published 7 years ago

object-upperkeys v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

object-upperkeys

It provides an API to convert the keys of the object into uppercase. Client of this API can specify if nested keys are also required to be converted to uppercase

Installation

Install with npm:

$ npm install object-upperkeys --save

Usage

var UPPERCASE_KEYS = require('object-upperkeys');

var object = {
    'California' : 'CA',
    'Texas'      : 'TX',
    'new york'   : 'NY' 
};

UPPERCASE_KEYS.toUpperCaseKeys(object);
//=> { 'CALIFORNIA' : 'CA', 'TEXAS' : 'TX', 'NEW YORK' : 'NY' }

var days = {
    'sunday'    : 0,
    'monday'    : 1,
    'tuesday'   : 2,
    'wednesday' : 3
};

UPPERCASE_KEYS.toUpperCaseKeys(days);
//=> { 'SUNDAY': 0, 'MONDAY' : 1, 'TUESDAY' : 2, 'WEDNESDAY' : 3 }

Clone the repo

$ git clone https://github.com/luthraG/object-upperkeys.git

API

toUpperCaseKeys(obj, options)

This API takes two parameters: 1. Object whose keys to be converted to uppercase and 2. options object. This argument is optional

Options

Various options supported by this API are :

  • deep - To specify if nested keys should also be converted to uppercase. Default is false.

Example with options

var UPPERCASE_KEYS = require('object-upperkeys');

var days = {
    'Sunday'    : 0,
    'Monday'    : 1,
    'tuesday'   : 2,
    'wednesday' : 3,
    'weekend'  : {
        'Sunday' : 'Fun day',
        'Saturday' : {
            'Code' : {
                'Abbr' : 'sat'
            }
        }
    }
};

UPPERCASE_KEYS.toUpperCaseKeys(days, { deep : true});
//=> { 'SUNDAY': 0, 'MONDAY' : 1, 'TUESDAY' : 2, 'WEDNESDAY' : 3, 'WEEKEND' : 'SUNDAY' : 'Fun day', 'SATURDAY' : { 'CODE' : { 'ABBR' : 'sat' } } }

Related projects

You might also be interested in these projects:

Author

Gaurav Luthra

License

MIT © Gaurav Luthra