GithubHelp home page GithubHelp logo

careteenl / match Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 28 KB

对象/数组属性映射,主要解决前后端并行开发或前端先行开发带来的命名不统一问题

License: MIT License

JavaScript 92.44% HTML 7.56%

match's Introduction

license Build Status npm NPM downloads

English Document

对象/数组属性映射 主要解决前后端并行开发或前端先行开发带来的命名不统一问题

快速使用

NPM

npm i -D @careteen/match
import Match from '@careteen/match'
import { isEqual } from '@careteen/is'
let preData = {
  name: 'careteen',
  age: 22
}
let expectData = {
  realName: 'careteen',
  realAge: 22
}
let actualData = Match(preData, {
  'realName': '{{name}}',
  'realAge': '{{age}}'
})

isEqual(actualData, expectData) // true

or CDN

<script src='https://unpkg.com/@careteen/match/dist/index.js'></script>
<script src='https://unpkg.com/@careteen/is/dist/index.js'></script>
<script>
  var Is = window['@careteen/is']
  var Match = window['@careteen/match']

  var preData = {
    name: 'careteen',
    age: 22
  }
  var expectData = {
    realName: 'careteen',
    realAge: 22
  }
  var actualData = Match(preData, {
    'realName': '{{name}}',
    'realAge': '{{age}}'
  })

  Is.isEqual(actualData, expectData) // true  
</script>

更详细使用请查看API

兼容性

IE9+

使用文档

issue模板

贡献者及指南

clone仓库并引入依赖

git clone [email protected]:careteenL/match.git
npm install

开始开发:)

...

编写详细使用文档介绍功能,可在本地查看http://127.0.0.1:8880

npm run doc

请编写单元测试覆盖所加功能

npm run test

启动本地服务器编写示例

npm run example

修改package.json README.md CHANGELOG.md版本号,再发布

npm run release

更新日志

计划

match's People

Contributors

careteenl avatar

Stargazers

 avatar

match's Issues

第二个参数期望支持函数自定义匹配

import Match from '@careteen/match'
// 原始值
let preData = [{
  name: 'careteen',
  age: 22
},{
  name: '',
  age: null
}]
// 期望当某一项某个字段为空时,不要这一项
let expectData = [{
  realName: 'careteen',
  realAge: 22
}]
// 期望的写法 类似于Array.prototype.filter()方法
let actualData = Match(preData, (item, index) => {
 return item.name && item.age
})

原数据为对象数组,当转换规则为函数自定义转换时,期望为$scope新增下标标识当前为第几项

原数据为对象数组,当转换规则为函数自定义转换时,期望为$scope新增下标标识当前为第几项

import Match from '@careteen/match'
var preData = [
  {
    name:  'careteen',
    age:  '23'
  },
  {
    name:  'lanlan',
    age:  '23'
  }
]
let expectData = Match(preData, {
  'name': '{{name}}',
  'age': '{{age}}',
  // 期望新增一个下标_index 
  'isFirst': $scope => {
    return $scope._index === 0
  }
})

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.