5.0.2 • Published 3 years ago

map-obj v5.0.2

Weekly downloads
16,910,494
License
MIT
Repository
github
Last release
3 years ago

map-obj

Map object keys and values into a new object

Install

npm install map-obj

Usage

import mapObject, {mapObjectSkip} from 'map-obj';

const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
//=> {bar: 'foo'}

const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
//=> {foo: true, bar: {bAz: true}}

const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
//=> {foo: true, bar: {baz: true}}

const newObject = mapObject({one: 1, two: 2}, (key, value) => value === 1 ? [key, value] : mapObjectSkip);
//=> {one: 1}

API

mapObject(source, mapper, options?)

source

Type: object

The source object to copy properties from.

mapper

Type: (sourceKey, sourceValue, source) => [targetKey, targetValue, mapperOptions?] | mapObjectSkip

A mapping function.

mapperOptions

Type: object

shouldRecurse

Type: boolean\ Default: true

Whether targetValue should be recursed.

Requires deep: true.

options

Type: object

deep

Type: boolean\ Default: false

Recurse nested objects and objects in arrays.

target

Type: object\ Default: {}

The target object to map properties on to.

mapObjectSkip

Return this value from a mapper function to exclude the key from the new object.

import mapObject, {mapObjectSkip} from 'map-obj';

const object = {one: 1, two: 2}
const mapper = (key, value) => value === 1 ? [key, value] : mapObjectSkip
const result = mapObject(object, mapper);

console.log(result);
//=> {one: 1}

Related

  • filter-obj - Filter object keys and values into a new object

camelcase-keysdecamelize-keysarchetype-libraryeasy-select-rnchinjowwchinjowreact-native-bluetooth2killi8n-react-native-fast-image@arisageha/react-lazyloadairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdk@jttechnic/interpreterttiocthpb-plugin-social@olivervorasai/slidermysql-formatpanqibaoreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutils@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-testunblock-block-save-variables@saaspe/componentsexpand-react-bridgeopea-bootstraapluminos-ui-core@everything-registry/sub-chunk-2128iqra-calculatorjawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplelapture-ui-complaptureuigriffin-ui-library@yabe-siul/fluid-tailwindswoletailwind-vector-effecttest-iki-mini-apptest-library-123test-haptik-libwinx-form-winxwalli-schemaweb-elements-iconswowsearch-server-middlewarewxiowifi_configuration_packagesui-monorepotest-quadrupletest-zeo-collectsuper-antdsweetalert2-denazificationvue-compmentvishwanaathh4_dbvishwanaathh4_db1vishwanaathh4_db2vishwanaathh4_dbbvision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvision-camera-base64-resizedvcloudcam-playkit-js-hlsvantiq-reactvideo-multi-uploadervue-dev-clone@dotconf-pro/dotconf-pro@dotconf-pro/dotenv@dream2023/data-mapping@cs6/react-native-test-native-view-library@completion/sampling@con-test/react-native-concent-common@dan/cryptocoins-icons@damruravihara/react-native-testing-package@comapeo/core@corelmax/react-native-my2c2p-sdk@buzzcms/components@rstacruz/pnpm@praella/localisationist@positionex/position-sdkcauseway-concrete-stylesjahancli_calculatorip-designjeuxuijson-logic-js-jitjrennsoh88-react-native-scroll-indicatorjsify-case-keys-deepkanpai-scraperjesh-calculationjnf-accesscontrol-rnttl
5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

4 years ago

4.3.0

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.0

7 years ago

2.0.0

9 years ago

1.0.1

10 years ago

1.0.0

11 years ago