包详细信息

type-analyzer

uber-web17.6kMIT0.4.0

Infer types from columns in JSON

自述文件

type-analyzer

Infer data types from CSV columns.

Overview

This package provides a single interface for generating the datatype for a given row-column formatted dataset. We support the following datatypes:

  • DATE
  • TIME
  • DATETIME
  • NUMBER
  • INT
  • FLOAT
  • CURRENCY
  • PERCENT
  • STRING
  • ARRAY
  • OBJECT
  • ZIPCODE
  • BOOLEAN
  • GEOMETRY
  • GEOMETRY_FROM_STRING
  • PAIR_GEOMETRY_FROM_STRING
  • NONE

Installation

npm install type-analyzer

Usage

Analyzer.computeColMeta(data, rules, options) (Function)

Parameters

  • data Array required An array of row object
  • rules Array optional An array of custom regex rules
  • options Object optional Option object
  • options.ignoreDataTypes Array optional Data types to ignore
var Analyzer = require('type-analyzer').Analyzer;
var data = [
    {
        "ST_AsText": "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))",
        "name": "san_francisco",
        "lat": "37.7749295",
        "lng": "-122.4194155",
        "launch_date": "2010-06-05",
        "added_at": "2010-06-05 12:00"
    },
    {
        "ST_AsText": "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))",
        "name": "paris",
        "lat": "48.856666",
        "lng": "2.3509871",
        "launch_date": "2011-12-04",
        "added_at": "2010-06-05 12:00"
    },
]
var colMeta = Analyzer.computeColMeta(data);
  • rules

You can pass in an array of custom rules. For example. if you want to ensure that a column full of ids represented as numbers is identified as a column of strings. Rules can be matched with either exact name of the column, or regex used to match names. Note: Analyzer prefers rules using name over regex since better performance.

var Analyzer = require('type-analyzer').Analyzer;

var colMeta = Analyzer.computeColMeta(data, [{name: 'id', dataType: 'STRING'}]);
// or
var colMeta = Analyzer.computeColMeta(data, [{regex: /id/, dataType: 'STRING'}]);
  • options.ignoreDataTypes

You can also pass in ignoreDataTypes to ignore certain types. This will improve your type checking performance.

var DATA_TYPES = require('type-analyzer').DATA_TYPES;

var colMeta = Analyzer.computeColMeta(arr, [], {ignoredDataTypes: DATA_TYPES.CURRENCY})[0].type,

And it will short cut around the usual analysis system and give you back the column formatted as you'd expect.

DATA_TYPES

You can import all availale types as a constant.

Update

Breaking changes with v1.0.0: Regex has moved into src, but can more easily be accessed from the module.exports from the root. As part of a larger clean up many extraneous util files were removed.

更新日志

Change Log

All notable changes to kepler.gl will be documented in this file.

[0.2.5] - Jan 25 2020

dd0361f Treat mixed int/float columns as float

[0.2.4] - Jan 08 2020 (3ab0fb8)

2cf038e Treat large numeric columns as numbers

[0.2.3] - Oct 08 2019 (371f641)

986ce5c [Enhancement] Add support for Array and Object data type)

[0.2.2] - Oct 07 2019 (b913061)

37de75d add eslint and prettier 0f10ab9 [Doc] Update README to add ignoredDataTypes 3e0134e remove TYPE city all together 2cf641b port internal type-analyzer commits over (currently at 1.5.0)

[0.2.1] - Jan 03 2019 (c6fb704)

4c2a767 Add CHANGELOG.md f676778 Don't attempt to analyze missing columns. 94c97a9 Correct use of 'correctly' 7ea8360 Add tests, DRY up test util 460947e Fix: Don't attempt to analyze missing columns.

[0.2.0] - Apr 03 2018 (2eb75ca)

02989de 1 and 0 should be detected as int instead of boolean

[0.1.4] - Apr 03 2018 (f581c65)

fe0827b Added new date format regex: YYYY/M/D 40c1923 Added new date format regex

[0.1.3] - Feb 28 2018 (08741f6)

626a819 avoid detect time format in every type check

[0.1.2] - Jan 19 2018 (edcfcd9)

56810e3 recognize space in point pair, check geometry.type exist before calling .toUppercase

[0.1.1] Dec 18 2018 (e665758)

5376d1c add unix timestamp tests c0734c9 added unix time format a796a7b update readme, make year regex recognize 2 digit year 3d0fa1a from git@github.com:uber-web/type-analyzer.git