Giter Club home page Giter Club logo

data-helper's Introduction

data-helper

复杂业务下,复杂接口对应的大量数据,取值、维护存在较大困难。 抽象,封装库来简化工作复杂度

  • 别名(批量获取中使用)
    • 适用于多个不同数据源 / 多个入口进入时,数据统一处理
  • 遍历复杂对象
    • 数据处理
  • 扁平化
  • 序列化
  • key匹配 / 数组匹配 / 结构匹配
    • 批量 取值/赋值
  • deepGet
    • 防止对象不存在时取子元素报错
    • 设置默认值,获取不到采用默认值
  • 批量取值
    • 生成对象 或者 数组
    • 目前是扁平化的,后续考虑 key/key 层级分割
  • 重复 key 处理
    • 如果取值采用 key 匹配模式,需要考虑重复 key 情况
  • deep copy
    • 防止修改引用类型的数据报错、引发不可知问题
  • 容错处理

在处理复杂数据的时候,有什么痛点?

  1. 路径是否存在判断
    • 获取 a.b.c,但是没有 a.b,导致报错
  2. 默认值
    • 获取 a.b.c,c 不存在时,赋默认值
  3. 引用数据类型 莫名其妙被改变(deepClone)问题
    • 在需要改变数据的场景,直接全部采用 deepClone
  4. 别名
    • 调用公共接口,所需数据从多个接口获取,key 不统一,需要重命名

deepGet

DEMO

batchDeepGet

DEMO

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.