1.1.9 • Published 1 year ago

rigel-tools v1.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Rigel.js

Rigel is a JavaScript library for transforming data tables by table declaration. It provides a concise, declarative table language to support a range of data transformation tasks.

Install

npm install rigel-tools

Usage

Demo

To try demo, use npm run test.

Basic usage

import * as rigel from "rigel-tools";
let spec = {
  data: [
    {
      name: "crime",
      values: [
        { state: "Alabama", year: 2004, crime: 4029.3 },
        { state: "Alabama", year: 2005, crime: 3900 },
        { state: "Alaska", crime: 3370.9, year: 2004 },
        { state: "Alaska", crime: 3615, year: 2005 },
      ],
    }
  ],
  target_table: [
    "(crime.state), (crime.year) => (crime.crime)",
  ],
};
var result = rigel.transform(spec);
console.log(rigel.prettyPrint(result)); // shape the result in readable form

//Output
[
  [
    [ null, 2004, 2005 ],
    [ 'Alabama', 4029.3, 3900 ],
    [ 'Alaska', 3370.9, 3615 ]
  ]
]

API

transform(spec: object)

Function

Transform the input raw tables into given forms according to specifications in the argument.

Argument

A valid argument of transform is an object containing keys including data and target_table, indicating the raw tables and specifications of target tables respectively. Details of the values corresponding to these keys are provided as follows.

data

A valid value for data field is an array consisting of objects representing raw tables. Each object should have a name field representing the table name and a values field representing the table contents.

target_table

A valid value for target_table field is a string indicating the specifications of target tables. The pattern of a specification is (row), (column) => (cell), where row, column and cell are expressions containing attribute(s) that will be mapped to the row, column and cell part of the target table. For example, when attribute state is mapped to row, year is mapped to column and crime is mapped to cell, the specification can be written as (state), (year) => (crime).

Output

The output of transform is a 3-dimensional array. Specifically, the output of transform is an array consisting of target tables, with each target table an 2-dimensional array. The element can be null if the corresponding cell is empty or an object representing the contents of the corresponding cell. The object has a value field indicating the real value in the corresponding cell and a source field indicating the source attribute that the real value originally belongs to.

prettyPrint(target: object)

Function

Print the output of transform in readable form.

Argument

An object with the same form as the output of transform.

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago