Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dto4j

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dto4j

> data transform object for javascript

  • 0.1.2
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

dto4j

data transform object for javascript

API

dto4j(convert[, data])

var data = {
    name: '张三',
    age: '0',
    hello: {
        world: 1489470599650
    },
    list: [
        {a: 1},
        {b: 2},
        {c: 3}
    ]
}

// 可以通过 src 参数 或者 this 来获得 data,并且是深拷贝,不影响原对象
// 也可以直接传入 object path 来赋给一个新 key
var convert = {
    userName: 'name',
    age: function (src) {
        return parseInt(src.age)
    },
    helloWorld: function () {
        return new Date(this.hello.world)
    },
    hello_world: 'hello.world',
    array: 'list',
    arrayFirst: 'list[0]',
    foo: {
        bar: {
            baz: function () {
                return this.list[0].a * 666
            }
        }
    }
}

console.log(dto4j(convert, data))

// { 
//     userName: '张三',
//     age: 0,
//     helloWorld: 'Tue Mar 14 2017 13:49:59 GMT+0800 (CST)',
//     hello_world: 1489470599650,
//     array: [ { a: 1 }, { b: 2 }, { c: 3 } ],
//     arrayFirst: { a: 1 },
//     foo: { bar: { baz: 666 } }
// }

// 也可以传入一个参数,返回一个 dto 转换器,以便后面执行多次转换
var dto1 = dto4j(convert)
console.log(dto1(data))
// console.log(dto1(data2))
// console.log(dto1(data3))

导出以下 lodash api

dto4j.set(object, path, value)

dto4j.get(object, path, [defaultValue])

dto4j.cloneDeep(value)

FAQs

Package last updated on 14 Mar 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc