1.0.4 - Added "camelizeKeys" function
parent
fd779d43e4
commit
ca04938f92
17
README.md
17
README.md
|
@ -1,6 +1,10 @@
|
|||
# js-utils
|
||||
|
||||
## Install
|
||||
## Introduction
|
||||
|
||||
js-utils is a collection of utilities that facilitate software development in a javascript environment.
|
||||
|
||||
## Package installation
|
||||
|
||||
```bash
|
||||
// with npm
|
||||
|
@ -13,8 +17,13 @@ yarn add @flare/js-utils --registry https://lab.code-rove.com/public-node-regist
|
|||
## Usage
|
||||
|
||||
```jsx
|
||||
import { typeValidator, localStorage } from "@flare/js-utils";
|
||||
import { typeValidator, localStorage, camelizeKeys } from "@flare/js-utils";
|
||||
```
|
||||
|
||||
**1.0.0**
|
||||
This version includes data type validators and local storage utils
|
||||
## Changelog
|
||||
|
||||
1.0.0 - This version includes data type validators and local storage utils
|
||||
1.0.1 - Set new domain in configs
|
||||
1.0.2 - Utilities function export fix
|
||||
1.0.3 - Typescript warnings fix
|
||||
1.0.4 - Added "camelizeKeys" function
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@flare/js-utils",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@flare/js-utils",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "Javascript utils",
|
||||
"author": {
|
||||
"name": "Tudor Stanciu",
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
function camelizeKeys(o) {
|
||||
var newO, origKey, newKey, value;
|
||||
if (o instanceof Array) {
|
||||
return o.map(function (value) {
|
||||
if (typeof value === "object") {
|
||||
value = camelizeKeys(value);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
} else {
|
||||
newO = {};
|
||||
for (origKey in o) {
|
||||
if (Object.prototype.hasOwnProperty.call(o, origKey)) {
|
||||
newKey = (
|
||||
origKey.charAt(0).toLowerCase() + origKey.slice(1) || origKey
|
||||
).toString();
|
||||
value = o[origKey];
|
||||
if (
|
||||
value instanceof Array ||
|
||||
(value !== null && value.constructor === Object)
|
||||
) {
|
||||
value = camelizeKeys(value);
|
||||
}
|
||||
newO[newKey] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newO;
|
||||
}
|
||||
|
||||
export { camelizeKeys };
|
|
@ -1,4 +1,5 @@
|
|||
import * as typeValidator from "./data/typeValidator";
|
||||
import * as localStorage from "./storage/localStorage";
|
||||
|
||||
export * from "./data/camelizer";
|
||||
export { typeValidator, localStorage };
|
||||
|
|
Loading…
Reference in New Issue