Convert the values present in an object to uppercase
npm install uppercase-valuesInstall with npm:
``sh`
$ npm install uppercase-values --save
`javascript
var UPPER_CASE_VALUES = require('uppercase-values');
var object = {
'California' : 'ca',
'Texas' : 'tx',
'NEW YORK' : 'ny'
};
UPPER_CASE_VALUES.toUpperCaseValues(object);
//=> { 'California' : 'CA', 'Texas' : 'TX', 'NEW YORK' : 'NY' }
var days = {
'SUNDAY' : 'First',
'MONDAY' : 'Second',
'TUESDAY' : 'Third',
'WEDNESDAY' : 3
};
UPPER_CASE_VALUES.toUpperCaseValues(days);
//=> { 'SUNDAY': 'FIRST', 'MONDAY' : 'SECOND', 'TUESDAY' : 'THIRD', 'WEDNESDAY' : 3 }
`
`bash`
$ git clone https://github.com/luthraG/uppercase-values.git
#### toUpperCaseValues(obj, [options])
This API takes two parameters:
1. Object whose values 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 values of nested keys should also be converted to uppercase. Default is false.
Example with options
`javascript
var UPPER_CASE_VALUES = require('uppercase-values');
var days = {
'SUNDAY' : 'First',
'MONDAY' : 'Second',
'TUESDAY' : 'Third',
'WEDNESDAY' : 3,
'WEEK_END' : {
'SUNDAY' : {
'CODE' : {
'ABBR' : 'sat'
}
}
}
};
UPPER_CASE_VALUES.toUpperCaseValues(days, { deep : true});
//=> { 'SUNDAY': 'FIRST', 'MONDAY' : 'SECOND', 'TUESDAY' : 'THIRD', 'WEDNESDAY' : 3, 'WEEK_END' : { 'SUNDAY' : { 'CODE' : { 'ABBR' : 'SAT' } } } }
``
You might also be interested in these projects:
* lowercase-values: Convert the values of all the keys of an object into lowercase. | homepage
* object-upperkeys: Convert the keys of an object into uppercase. | homepage
* object-lowerkeys: Convert the keys of an object into lowercase. | homepage
* objectvalues: To get all the values of an object. It can also fetch the value of nested object of any depth. | homepage
Gaurav Luthra
MIT © Gaurav Luthra