Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

mapper-json

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapper-json

json 对象转换

latest
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Mapper-JSON

将一个json 通过 规则定义,生产两一个 json

使用方式

import MapperJson from 'mapper-json'

// 数据
const source = {
  foo: 'bar',
  t1: 1,
  t2: 't2',
  numstr: '12.1',
  str_arr: '1|2|1|3',
  category: 'shehui',
};

// 规则
const rules = {
  baz: 'foo',
  arr: ['t1', 't2'],
  switch: [
    {
      op: 'switch',
      options: [
        {
          result: '社会',
          leftSelect: 'category',
          operation: 'eq',
          rightValue: 'shehui'
        }
      ]
    },
  ],
}

// 转换
const result = MapperJson.tranWithRules(source, rules);

// or
const mapperJsonInstance = new MapperJson(rules);
const result = mapperJsonInstance.trans(source);

// const result = {
//   baz: 'bar',
//   arr: [1, 't2'],
//   switch: ['社会']
// };


FAQs

Package last updated on 14 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts