Git Product home page Git Product logo

model's Introduction

vvpvvp

在给定的范围内返回一个随意值。

Install

npm install vvpvvp
npm install --save vvpvvp

Example

let a = vvpvvp([1, 2], 2);
//1.48
let a = vvpvvp([3], 3);
//3.123
let a = vvpvvp([-1, 3], 3);
//-0.123

API

params

vvpvvp([start, ], <toFixed = 2>)

License

MIT

model's People

Contributors

vvpvvp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

model's Issues

是否可以加入转义读取key的功能?

就是模型定义里面的 key 是 name, 而 服务端返回的数据里面就不按约定叫 name, 他给改成了 username, 而我们事先已经按照约定写了N多的业务逻辑,这时候去改模型定义的 name 显然是不合适的,但如果可以定义一个转义 key, 例如:

export default new Model({
    int: Number,
    date: {
        type: Date,
        format: 'YYYY-MM-DD'  //此处使用manba日期工具
    },
    money: {
        type: Number,
        unit: Model.W
    },
   name: {
      type: String,
      jsonKey: ‘username’
   }
})

然后可以按照转义 key username 去取值,这样就不需要到各种业务里面去把 name 改为 username 了,只需要在模型定义处定义一下就可以了

不知道我是否说清楚了

How to parse array

const target = [{a: 1}, {a: 2}],
How to define target as a Model, then I can use target.parse() to parse

parse 数据可以是定义吗

"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-core": "^6.26.0",
"chai": "^4.1.2",
"manba": "^1.0.1"

const __Model = require('../src/model');
let _dataM = new __Model({
a: Number,
b: String,
c: Date,
d: Boolean,
e: Array,
f: Object
});
let _r = _dataM.parse({
a: 'sdf12asd',
b: 12
});

parse 数据可以是这样的 吗
{ c: new Date, d: false, e: [], f: {}, a: 0, b: '12' }

parse 结果是 [object Object]

demo: https://codepen.io/anon/pen/qyXjyj

模型定义:

let User = new Model({
  id: 0,
  follower_num: 0,
  following_num: 0,
  is_following: false,
  type: String,
  real_name: String,
  avatar_url: String,
  title: String,
  introduction: String,
})

我发现把 type: String 改成 type1: String 就没问题了,问题可能出现在对属性名的判断上?

另外,请问能否支持Boolean类型的定义?默认false。

请问数组怎么设置默认值?

const banners = new Model({
  imgUrls: {
    type: [''],
    default: ['http://via.placeholder.com/750x306'],
  },
});

这样用的话会返回一个空数组

type: Array, parse 返回异常

import Model from 'js-model'

const modelTest = new Model({
  a: {
      type: Array,
      defalut: []
  }
})

console.log(modelTest.parse({}))

返回结果

{
    a: {
      type: null,
      defalut: Array(0)
    }
}

正常不应该是返回

{
    a: []
}

吗?

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.