Giter VIP home page Giter VIP logo

ducker-model's Introduction

Welcome to ducker 👋

Data converter, decoupling front and rear development, improving development efficiency 数据转换器,解耦前后端开发,提升开发效率

Motivation

✅ why we need ducker-model ? see the article

Install

NPM

Usage

// 1.初始一个model实例,传入数据结构属性定义
let userModel = new Model({
  id: {
    type: Number,
    property: "uuid",
    value: 0
  },
  name: {
    type: String,
    property: "buyer.shopinfo.nickname",
    value: ""
  },
  items: {
    type: String,
    property: "items"
  },
  age: {
    type: Number,
    property: "age"
  },
  lastLoginTime: {
    type: Date,
    property: "lastLoginTime"
  },
  price: {
    type: Number,
    unit: "B",
    property: "price"
  }
});

// 2.实例调用parse()方法解析数据
let userState = userModel.parse({
  uuid: 123,
  buyer: {
    shopinfo: {
      nickname: "张三"
    }
  },
  price: 1000,
  lastLoginTime: "1563897600000"
});
// userState--> {"id":123,"name":"张三","items":"","age":0,"lastLoginTime":"2019-07-24","price":10}

// --------或者----------

// 3.实例调用traverse()方法反向映射数据
let userParams = userModel.traverse({
  id: 234,
  name: "李四",
  age: null,
  lastLoginTime: "2019-07-24",
  price: 24
});
// userParams--> {"uuid":234,"buyer":{"shopinfo":{"nickname":"李四"}},"lastLoginTime":1563897600000,"price":2400}

Author

👤 skinner

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

ducker-model's People

Contributors

simplefeel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.