All Projects → simplefeel → ducker-model

simplefeel / ducker-model

Licence: MIT license
🚗 数据转换器,解耦前后端开发,提升开发效率 https://mp.weixin.qq.com/s/q6xybux0fhrUz5HE5TY0aA

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ducker-model

datagent
一个用于模块化管理前端请求的工具
Stars: ✭ 41 (-45.33%)
Mutual labels:  model, data-model
TeslaKit
Elegant Tesla API in Swift
Stars: ✭ 47 (-37.33%)
Mutual labels:  model
Model
Angular Model - Simple state management with minimalist API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 242 (+222.67%)
Mutual labels:  model
sym
A Mathematica package for generating symbolic models from data
Stars: ✭ 46 (-38.67%)
Mutual labels:  model
MaskRCNN-Modanet-Fashion-Segmentation-and-Classification
Using modanet fashion dataset, the clothes images were classified under 5 season (summer,winter,spring,autumn,all).
Stars: ✭ 55 (-26.67%)
Mutual labels:  model
rPBR
Physically based rendering (PBR) for raylib
Stars: ✭ 72 (-4%)
Mutual labels:  model
Django Colorfield
color field for django models with a nice color-picker in the admin. 🎨
Stars: ✭ 238 (+217.33%)
Mutual labels:  model
paramak
Create parametric 3D fusion reactor CAD and neutronics models
Stars: ✭ 40 (-46.67%)
Mutual labels:  model
AWESOME-LDraw
LDraw — awesome software, file format, parts library and model repository (3D models of LEGO® and LEGO-compatible bricks)
Stars: ✭ 30 (-60%)
Mutual labels:  model
eloquent-filemaker
A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
Stars: ✭ 38 (-49.33%)
Mutual labels:  model
createml-playgrounds
Create ML playgrounds for building machine learning models. For developers and data scientists.
Stars: ✭ 82 (+9.33%)
Mutual labels:  model
sdkmesh-to-obj
sdkmesh decoder
Stars: ✭ 17 (-77.33%)
Mutual labels:  model
sequence tagging
Named Entity Recognition (LSTM + CRF + FastText) with models for [historic] German
Stars: ✭ 25 (-66.67%)
Mutual labels:  model
Whc model
iOS平台高效转换引擎json->model,model->json,model->Dictionary,支持模型类继承其他模型类,支持指定路径转换,不区分json的key和模型属性名称大小写,自动处理json中null
Stars: ✭ 244 (+225.33%)
Mutual labels:  model
modeling-website
Landing page for project sites
Stars: ✭ 16 (-78.67%)
Mutual labels:  model
Live2dmodel
页面上加载的模型
Stars: ✭ 241 (+221.33%)
Mutual labels:  model
menthor-editor
Menthor Editor
Stars: ✭ 31 (-58.67%)
Mutual labels:  model
ZXDataHandle
简单易用的数据转换和存储框架,支持一行代码将模型、模型数组、Json字符串、字典互转;支持模型映射到sqlite3数据库,无需书写sql
Stars: ✭ 13 (-82.67%)
Mutual labels:  model
source-engine-model-loader
Three.js loader for parsing Valve's Source Engine models
Stars: ✭ 54 (-28%)
Mutual labels:  model
common-osint-model
Converting data from services like Censys and Shodan to a common data model
Stars: ✭ 35 (-53.33%)
Mutual labels:  model

Welcome to ducker 👋

数据转换器,解耦前后端开发,提升开发效率

Motivation

why we need ducker-model ? see the article

Install

NPM

Base Usage

import Model from 'ducker-model'
// 1.定义property
const property = {
    id: String,
    name: Number,
    avatar: Object,
}
// 2.实例化model
const instanceModel = new Model(property)
// 3.定义数据源
const dataSource = {
    id: 123,
    name: 'cuiyuteng',
    avatar: {uri:'http://xxxx.png'}
}
// 4.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"id":"","name":0,"avatar":{uri:'http://xxxx.png'}}

Usage ReplacedKeyFromPropertyName

import Model from 'ducker-model'
// 1.定义property
const property = {
  id: String,
  name: String,
  avatar: String,
  loginTime: String,
  price: String,
  info: {
    sex: Number,
    real: {
      real_name: String
    }
  }
}
// 2.定义replacedKeyFromPropertyName
const replacedKeyFromPropertyName = {
  id: {
    property: "uuid",
    defaultValue: '100'
  },
  name: "buyer.shopinfo.nickname",
  loginTime: {
    property: "loginTime",
    format: "l"
  },
  price: {
    property: "price",
    unit: 'B'
  },
  avatar: {
    property: [
      "avatar", "file.avatar"
    ],
    computed: ([a0, a1]) => {
      return a0 || a1 || ''
    }
  },
  info: {
    sex: {
      property: "file.sex"
    },
    real: {
      real_name: {
        property: "file.real.real_name"
      }
    }
  }
}
// 3.实例化model
const instanceModel = new Model(property,replacedKeyFromPropertyName)
// 4.定义数据源
const dataSource = {
  uuid: 123,
  buyer: {
    shopinfo: {
      nickname: "张三"
    }
  },
  loginTime: "1566978591904",
  price: "12300",
  avatar: 'http://a.png',
  file: {
    avatar: 'http://b.png',
    sex: 1,
    real: {
      real_name: 'P'
    }
  }
}
// 5.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"id":"100","name":"张三","avatar":"http://a.png","loginTime":"2019-08-28","price":"123.00","info":{"sex":1,"real":{"real_name":"P"}}}

Usage ValueForPath

import Model, { valueForPath } from 'ducker-model'
// 1.定义property
const property = {
    uid: valueForPath(Number, "user.id"),
}
// 2.实例化model
const instanceModel = new Model(property)
// 3.定义数据源
const dataSource = {
    user: {
        id: 123456
    },
}
// 4.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"uid":123456}

Usage Array & ObjectArrayWithKeyValuesArray

import Model from 'ducker-model'
// 1.定义property
const property = {
    id: String,
    name: String,
    avatar: String,
}
// 2.定义replacedKeyFromPropertyName
const replacedKeyFromPropertyName = {
    id: {
        property: "uuid",
    },
    name: "buyer.shopinfo.nickname",
    avatar: {
        property: "file.url"
    },
}
// 3.实例化model
const instanceModel = new Model(property,replacedKeyFromPropertyName)
// 4.定义数据源
const dataSource = {
    uuid: '123456',
    buyer:{
        shopinfo:{
            nickname: 'xxx'
        }
    },
    file: {
        url:'http://xxxx'
    },
}
// 5.调用objectArrayWithKeyValuesArray方法解析数据
const modelData = instanceModel.objectArrayWithKeyValuesArray([dataSource,dataSource,dataSource])
// modelData--> [{"id":"123456","name":"xxx","avatar":"http://xxxx"},{"id":"123456","name":"xxx","avatar":"http://xxxx"},{"id":"123456","name":"xxx","avatar":"http://xxxx"}]

Usage Object & ValueWithArray

import Model, { valueWithArray } from 'ducker-model'
// 1.定义property
const property = {
    data: valueWithArray({
        time: String,
        to: Number
    }),
    source: valueWithArray(String),
    object: valueWithArray(Object),
}
// 2.定义replacedKeyFromPropertyName
const replacedKeyFromPropertyName = {
    data: {
        property: "data",
        children: {
            time: {
                property: "time",
            },
            to: {
                property: "to",
            },
        }
    },
    source: {
        property: "datasource",
    },
    object: {
        property: "objectDataSource",
    },
}
// 3.实例化model
const instanceModel = new Model(property,replacedKeyFromPropertyName)
// 4.定义数据源
const dataSource = {
    data: [{
        time: '1231512313',
        to: 'troila'
    }],
    datasource: ['1', '2', '3'],
    objectDataSource: [{ a: 1 }, { b: 2 }],
}
// 5.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"data":[{"time":"1231512313","to":0}],"source":["1","2","3"],"object":[{ "a": 1 }, { "b": 2 }]}

Usage ValueForPathWithArray

import Model, { valueForPathWithArray } from 'ducker-model'
// 1.定义property
const property = {
    test: valueForPathWithArray(Number, "testDataSource"),
}
// 3.实例化model
const instanceModel = new Model(property)
// 4.定义数据源
const dataSource = {
    testDataSource: [4, 5, 6],
}
// 5.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"test":[4,5,6]}

Usage Object & ValueWithArray & ValueWithArray

import Model, { valueWithArray } from 'ducker-model'
// 1.定义property
const property = {
    lastTest: valueWithArray({
        title: String,
        data: valueWithArray({
            price: Number,
            content: String
        })
    }),
}
// 2.定义replacedKeyFromPropertyName
const replacedKeyFromPropertyName = {
    lastTest: {
        property: "order",
        children: {
            title: {
                property: "title"
            },
            data: {
                property: "dataSource",
                children: {
                    price: {
                        property: "Price",
                    },
                    content: {
                        property: "mrk",
                    },
                }
            }
        },
    }
}
// 3.实例化model
const instanceModel = new Model(property,replacedKeyFromPropertyName)
// 4.定义数据源
const dataSource = {
    order: [{
        title: 'order-1',
        dataSource: [{
            Price: 100,
            mrk: '这是订单1'
        }, {
            Price: 200,
            mrk: '这是订单2'
        }]
    }]
}
// 5.调用objectWithKeyValues方法解析数据
const modelData = instanceModel.objectWithKeyValues(dataSource)
// modelData--> {"lastTest":[{"title":"order-1",data:[{"price":100,"content":"这是订单1"},{"price":200,"content":"这是订单2"}]}]}

Instance Model Method

  • objectWithKeyValues
    • params: Object
    • return: Object
     const modelData = instanceModel.objectWithKeyValues(dataSource)
  • objectArrayWithKeyValuesArray
    • params: Array
    • return: Array
     const modelData = instanceModel.objectArrayWithKeyValuesArray([dataSource,dataSource,dataSource])

TIPS

  1. typeDate的属性,增加format字段,支持多种内置数据格式,默认为"l",可以选择的格式如下:

    • "l": "YYYY-MM-DD",
    • "ll": "YYYY 年 MM 月 DD 日",
    • "k": "YYYY-MM-DD hh:mm",
    • "kk": "YYYY 年 MM 月 DD 日 hh 点 mm 分",
    • "kkk": "YYYY 年 MM 月 DD 日 hh 点 mm 分 q",
    • "f": "YYYY-MM-DD hh:mm:ss",
    • "ff": "YYYY 年 MM 月 DD 日 hh 点 mm 分 ss 秒",
    • "fff": "YYYY 年 MM 月 DD 日 hh 点 mm 分 ss 秒 星期 w",
    • "n": "MM-DD",
    • "nn": "MM 月 DD 日"
  2. 添加了unit字段的,代表该属性值表示一个价格,模型内置十、百、千、万单位,可以快捷的将价格字段进行转换,例如1000 -> 100

  3. 属性定义增加computed,值为函数,可以用来自定义数据格式化处理

  4. property,值可以为一个数组,传入多个路径,此时可以通过定义 computed 方法来组合计算值

Author

👤 skinner

Show your support

Give a ⭐️ if this project helped you!

Contributors

Thanks goes to these wonderful people (emoji key):

李杰
李杰

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].