@vect/object-mapper
Advanced tools
Comparing version 0.0.1 to 0.0.4
@@ -5,6 +5,6 @@ 'use strict'; | ||
const mapper = (jso, fn) => { | ||
const mapper = (o, fn) => { | ||
const ob = {}; | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) ob[k] = fn(jso[k]); | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) ob[k] = fn(o[k]); | ||
@@ -14,12 +14,12 @@ return ob; | ||
const mutate = (jso, fn) => { | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) jso[k] = fn(jso[k]); | ||
const mutate = (o, fn) => { | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) o[k] = fn(o[k]); | ||
return jso; | ||
return o; | ||
}; | ||
const mapKeys = (jso, fn) => { | ||
const mapKeys = (o, fn) => { | ||
const ob = {}; | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) ob[fn(k)] = jso[k]; | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) ob[fn(k)] = o[k]; | ||
@@ -29,9 +29,9 @@ return ob; | ||
function mapEntries(jso, fn, l) { | ||
function mapEntries(o, fn, l) { | ||
const ob = {}, | ||
ents = Object.entries(jso); | ||
ents = Object.entries(o); | ||
l = l || ents.length; | ||
for (let i = 0, k, v; i < l; i++) { | ||
[k, v] = fn(ents[i]); | ||
[k, v] = fn(ents[i], i); | ||
ob[k] = v; | ||
@@ -38,0 +38,0 @@ } |
@@ -1,5 +0,5 @@ | ||
const mapper = (jso, fn) => { | ||
const mapper = (o, fn) => { | ||
const ob = {}; | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) ob[k] = fn(jso[k]); | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) ob[k] = fn(o[k]); | ||
@@ -9,12 +9,12 @@ return ob; | ||
const mutate = (jso, fn) => { | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) jso[k] = fn(jso[k]); | ||
const mutate = (o, fn) => { | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) o[k] = fn(o[k]); | ||
return jso; | ||
return o; | ||
}; | ||
const mapKeys = (jso, fn) => { | ||
const mapKeys = (o, fn) => { | ||
const ob = {}; | ||
for (let k in jso) if (Object.hasOwnProperty.call(jso, k)) ob[fn(k)] = jso[k]; | ||
for (let k in o) if (Object.hasOwnProperty.call(o, k)) ob[fn(k)] = o[k]; | ||
@@ -24,9 +24,9 @@ return ob; | ||
function mapEntries(jso, fn, l) { | ||
function mapEntries(o, fn, l) { | ||
const ob = {}, | ||
ents = Object.entries(jso); | ||
ents = Object.entries(o); | ||
l = l || ents.length; | ||
for (let i = 0, k, v; i < l; i++) { | ||
[k, v] = fn(ents[i]); | ||
[k, v] = fn(ents[i], i); | ||
ob[k] = v; | ||
@@ -33,0 +33,0 @@ } |
{ | ||
"name": "@vect/object-mapper", | ||
"version": "0.0.1", | ||
"version": "0.0.4", | ||
"description": "A debugging tool", | ||
@@ -32,4 +32,3 @@ "main": "dist/index.cjs.js", | ||
}, | ||
"homepage": "https://github.com/hoyeungw/vect#readme", | ||
"gitHead": "7bf35257f5abceb6b873d4385cb0a0599cedf26c" | ||
"homepage": "https://github.com/hoyeungw/vect#readme" | ||
} |
@@ -1,2 +0,2 @@ | ||
# @vect/vector-mapper | ||
# @vect/object-mapper | ||
@@ -8,37 +8,53 @@ [![npm version][badge-npm-version]][url-npm] | ||
[![npm license][badge-npm-license]][url-npm] | ||
[![pp install size][badge-pp-install-size]][url-pp] | ||
[![github commit last][badge-github-last-commit]][url-github] | ||
[![github commit total][badge-github-commit-count]][url-github] | ||
[![pp install size][badge-pp-install-size]][url-pp] | ||
[//]: <> (Shields) | ||
[badge-npm-version]: https://flat.badgen.net/npm/v/@vect/vector-mapper | ||
[badge-npm-download-monthly]: https://flat.badgen.net/npm/dm/@vect/vector-mapper | ||
[badge-npm-download-total]:https://flat.badgen.net/npm/dt/@vect/vector-mapper | ||
[badge-npm-dependents]: https://flat.badgen.net/npm/dependents/@vect/vector-mapper | ||
[badge-npm-license]: https://flat.badgen.net/npm/license/@vect/vector-mapper | ||
[badge-github-last-commit]: https://flat.badgen.net/github/last-commit/hoyeungw/@vect/vector-mapper | ||
[badge-github-commit-count]: https://flat.badgen.net/github/commits/hoyeungw/@vect/vector-mapper | ||
[badge-pp-install-size]: https://flat.badgen.net/packagephobia/install/@vect/vector-mapper | ||
[badge-npm-version]: https://flat.badgen.net/npm/v/@vect/object-mapper | ||
[badge-npm-download-monthly]: https://flat.badgen.net/npm/dm/@vect/object-mapper | ||
[badge-npm-download-total]:https://flat.badgen.net/npm/dt/@vect/object-mapper | ||
[badge-npm-dependents]: https://flat.badgen.net/npm/dependents/@vect/object-mapper | ||
[badge-npm-license]: https://flat.badgen.net/npm/license/@vect/object-mapper | ||
[badge-pp-install-size]: https://flat.badgen.net/packagephobia/install/@vect/object-mapper | ||
[badge-github-last-commit]: https://flat.badgen.net/github/last-commit/hoyeungw/vect | ||
[badge-github-commit-count]: https://flat.badgen.net/github/commits/hoyeungw/vect | ||
[//]: <> (Link) | ||
[url-npm]: https://npmjs.org/package/@vect/vector-mapper | ||
[url-github]: https://github.com/hoyeungw/@vect/vector-mapper | ||
[url-pp]: https://packagephobia.now.sh/result?p=@vect/vector-mapper | ||
[url-npm]: https://npmjs.org/package/@vect/object-mapper | ||
[url-pp]: https://packagephobia.now.sh/result?p=@vect/object-mapper | ||
[url-github]: https://github.com/hoyeungw/vect | ||
##### Util for array | ||
#### Features | ||
- ES2015 syntax | ||
#### Install | ||
```console | ||
$ npm install @vect/vector-mapper | ||
$ npm install @vect/object-mapper | ||
``` | ||
#### Functions | ||
- **mapper** map object values and return a new object | ||
- **mutate** map object values and return the object itself | ||
- **mapKeys** map object keys and return a new object | ||
- **mapEntries** map object entries and return a new object | ||
#### Usage | ||
```js | ||
import { mapper, mutate, mapKeys, mapEntries } from '@vect/object-mapper' | ||
const ob = { | ||
AMEE: 'Red Planet', | ||
AMP: 'Avatar', | ||
Maximilian: 'The Black Hole', | ||
Terminatrix: 'Terminator 3', | ||
} | ||
mapper(ob, value => value.length) | ||
mapKeys(ob, key => key.slice(0, 4)) | ||
mapEntries(ob, ([key, value], i) => [`${key}_${i}`, value.length]) | ||
mutate(ob, value => value.length) | ||
``` | ||
#### Meta | ||
[LICENSE (MIT)](/LICENSE) | ||
[LICENSE (MIT)](LICENSE) |
5317
60