1.0.4 - Added "camelizeKeys" function

master
Tudor Stanciu 2023-03-29 18:48:23 +03:00
parent fd779d43e4
commit ca04938f92
5 changed files with 47 additions and 6 deletions

View File

@ -1,6 +1,10 @@
# js-utils # js-utils
## Install ## Introduction
js-utils is a collection of utilities that facilitate software development in a javascript environment.
## Package installation
```bash ```bash
// with npm // with npm
@ -13,8 +17,13 @@ yarn add @flare/js-utils --registry https://lab.code-rove.com/public-node-regist
## Usage ## Usage
```jsx ```jsx
import { typeValidator, localStorage } from "@flare/js-utils"; import { typeValidator, localStorage, camelizeKeys } from "@flare/js-utils";
``` ```
**1.0.0** ## Changelog
This version includes data type validators and local storage utils
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

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@flare/js-utils", "name": "@flare/js-utils",
"version": "1.0.3", "version": "1.0.4",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@flare/js-utils", "name": "@flare/js-utils",
"version": "1.0.3", "version": "1.0.4",
"description": "Javascript utils", "description": "Javascript utils",
"author": { "author": {
"name": "Tudor Stanciu", "name": "Tudor Stanciu",

31
src/data/camelizer.js Normal file
View File

@ -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 };

View File

@ -1,4 +1,5 @@
import * as typeValidator from "./data/typeValidator"; import * as typeValidator from "./data/typeValidator";
import * as localStorage from "./storage/localStorage"; import * as localStorage from "./storage/localStorage";
export * from "./data/camelizer";
export { typeValidator, localStorage }; export { typeValidator, localStorage };