Notable Pseudocode Mashups

    @antv/dw-transform
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.7 • Public • Published

    Transform

    Install

    npm

    npm install @antv/dw-transform

    yarn

    yarn add @antv/dw-transform

    Schema

    {
      "groupBy": [...],
      "actions": [
        {
          "type": ...,
          "field": ...,
          "as": ...,
          "options": {
            ...,
          }
        }
      ]
    }

    Usage

    autoTransform

    The autoTransform function generates transform schemas to aggregate data fields in a default way.

    const data = [
      { gender: 'Male', height: 180 },
      { gender: 'Female', height: 165 },
      { gender: 'Male', height: 170 },
    ];
    
    const { result, schemas } = autoTransform(data);
    
    console.log(schemas);
    // [
    //   {
    //     groupBy: ['gender'],
    //     actions: [
    //       {
    //         type: 'sum',
    //         field: 'height',
    //         as: 'SUM(height)',
    //       },
    //     ],
    //   },
    // ]
    
    console.log(result);
    // [
    //   { gender: 'Male', 'SUM(height)': 350 },
    //   { gender: 'Female', 'SUM(height)': 165 },
    // ]

    renameOption

    The renameOption parameter of the autoTransform function defines how the created aggregation field would be named.

    Say, field title is field1 and aggregation type is sum:

    renameOption as
    'brackets' (default)
    true
    'SUM(field1)'
    'underline' 'SUM_field1'
    'origin'
    false
    'field1'
    function f(a,b) f('field1', 'sum')
    const data = [
      { gender: 'Male', height: 180 },
      { gender: 'Female', height: 165 },
      { gender: 'Male', height: 170 },
    ];
    
    const { result, schemas } = autoTransform(data, false);
    
    console.log(schemas);
    // [
    //   {
    //     groupBy: ['gender'],
    //     actions: [
    //       {
    //         type: 'sum',
    //         field: 'height',
    //         as: 'height',        // as origin
    //       },
    //     ],
    //   },
    // ]
    
    console.log(result);
    // [
    //   { gender: 'Male', 'height': 350 },         // as origin
    //   { gender: 'Female', 'height': 165 },       // as origin
    // ]

    parse

    If you already have a dataset and a transform schema for it, you can use the function parse to get the result.

    const data = [
      { id: '1', height: 10.5, weight: 60 },
      { id: '2', height: null, weight: 40 },
      { id: '3', height: 9.5, weight: null },
      { id: '', height: 9.5, weight: 80 },
      { id: '5', height: 9.5 },
    ];
    
    const schema = {
      actions: [
        {
          type: 'removeNull',
          field: 'id',
          as: null,
        },
      ],
    }
    
    const result = parse(data, schema);
    // [
    //   { id: '1', height: 10.5, weight: 60 },
    //   { id: '2', height: null, weight: 40 },
    //   { id: '3', height: 9.5, weight: null },
    //   { id: '5', height: 9.5 },
    // ]

    Keywords

    none

    Install

    npm i @antv/dw-transform

    DownloadsWeekly Downloads

    11

    Version

    1.1.7

    License

    MIT

    Unpacked Size

    428 kB

    Total Files

    50

    Last publish

    Collaborators

    • basketduck
    • biupiubiupiu
    • flash1
    • dreammy23
    • laixingui.lxg
    • zhangjunjie-loki
    • rainy25ghz
    • zeyuwang
    • yanxiong
    • susiwen8
    • freestyle21
    • soundquiet
    • elaine.q.10
    • sturuby
    • lviser
    • sakuya223
    • serializedowen
    • xdzhao
    • yangzhanmei
    • wjgogogo
    • leungwensen
    • dori
    • iaaron
    • yard
    • simaq
    • dxq613
    • intchous
    • susan_ann
    • jinke.li
    • lzxue
    • army8735
    • atool
    • baizn
    • dengfuping
    • neoddish
    • jeffy2012
    • zqlu
    • afc163
    • pomelo-nwu
    • kopiluwaky
    • ccnuzindex
    • panyuqi
    • bubkoo
    • zengyue
    • kasmine
    • boyu.zlj
    • l1ud0ngq1
    • newbyvector
    • winniexing
    • chenluli
    • kn9117
    • xdddst
    • semious2020
    • esora
    • nadia_liu
    • bbsqq
    • mxz96102
    • openwayne
    • pearmini
    • pddpd
    • yiqianyao
    • zhanba
    • cxxxxxn