@cumulus/pvl
Parse and serialize Parameter Value Language, a data markup language used by NASA
Last updated 3 days ago by cumuluspublisher .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @cumulus/pvl 
SYNC missed versions from official npm registry.

@cumulus/pvl

Build Status

What is Cumulus?

Cumulus is a cloud-based data ingest, archive, distribution and management prototype for NASA's future Earth science data streams.

Cumulus Documentation

PVL

A JS module to parse and serialize Parameter Value Language, a data markup language used by NASA.

How-to

Parse!

> const pvl = require('./pvl/index.js')

> const input = (`
ORIGINATING_SYSTEM = "ASTER_FTP";
OBJECT = "FILE_GROUP";
    DATA_TYPE = "AST_L1A";
    OBJECT = "FILE_SPEC";
        FILE_ID = "pg-PR1A0000-2017040601_000_001";
        FILE_TYPE = "SCIENCE";
        FILE_SIZE = 116503123;
    END_OBJECT = "FILE_SPEC";
    OBJECT = "FILE_SPEC";
        FILE_ID = "pg-BR1A0000-2017040601_000_001";
        FILE_TYPE = "BROWSE";
        FILE_SIZE = 166428;
    END_OBJECT = "FILE_SPEC";
END_OBJECT = "FILE_GROUP"
`)

> const parsed = pvl.pvlToJS(input)

> parsed
PVLRoot {
  store: [ [ 'ORIGINATING_SYSTEM', [Object] ], [ 'OBJECT', [Object] ] ],
  type: 'ROOT',
  depth: 0 }

> JSON.stringify(parsed)
'{"store":[["ORIGINATING_SYSTEM",{"value":"ASTER_FTP","type":"text string"}],["OBJECT",{"store":[["DATA_TYPE",{"value":"AST_L1A","type":"text string"}],["OBJECT",{"store":[["FILE_ID",{"value":"pg-PR1A0000-2017040601_000_001","type":"text string"}],["FILE_TYPE",{"value":"SCIENCE","type":"text string"}],["FILE_SIZE",{"value":116503123,"type":"numeric"}]],"identifier":"FILE_SPEC","type":"OBJECT"}],["OBJECT",{"store":[["FILE_ID",{"value":"pg-BR1A0000-2017040601_000_001","type":"text string"}],["FILE_TYPE",{"value":"BROWSE","type":"text string"}],["FILE_SIZE",{"value":166428,"type":"numeric"}]],"identifier":"FILE_SPEC","type":"OBJECT"}]],"identifier":"FILE_GROUP","type":"OBJECT"}]],"type":"ROOT","depth":0}'

Serialize!

...
> const serialized = pvl.jsToPVL(parsed)

> console.log(serialized)
ORIGINATING_SYSTEM = "ASTER_FTP";
OBJECT = FILE_GROUP;
  DATA_TYPE = "AST_L1A";
  OBJECT = FILE_SPEC;
    FILE_ID = "pg-PR1A0000-2017040601_000_001";
    FILE_TYPE = "SCIENCE";
    FILE_SIZE = 116503123;
  END_OBJECT = FILE_SPEC;
  OBJECT = FILE_SPEC;
    FILE_ID = "pg-BR1A0000-2017040601_000_001";
    FILE_TYPE = "BROWSE";
    FILE_SIZE = 166428;
  END_OBJECT = FILE_SPEC;
END_OBJECT = FILE_GROUP;

Traverse the object and get values!

...
> parsed.get('ORIGINATING_SYSTEM')  // Get the item with the given key
PVLTextString { value: 'ASTER_FTP', type: 'text string' }

> parsed.get('ORIGINATING_SYSTEM').value  // Access its value
'ASTER_FTP'

> parsed.getAll('ORIGINATING_SYSTEM')  // Since PVL allows duplicate keys
[ PVLTextString { value: 'ASTER_FTP', type: 'text string' } ]

> parsed.aggregates()  // Get all OBJECTs and GROUPs
[ PVLObject {
    store: [ [Object], [Object], [Object] ],
    identifier: 'FILE_GROUP',
    type: 'OBJECT' } ]

> parsed.objects()  // Get all OBJECTs
[ PVLObject {
    store: [ [Object], [Object], [Object] ],
    identifier: 'FILE_GROUP',
    type: 'OBJECT' } ]

> parsed.objects('FILE_GROUP')  // Get all OBJECTs with a given name
[ PVLObject {
    store: [ [Object], [Object], [Object] ],
    identifier: 'FILE_GROUP',
    type: 'OBJECT' } ]

> parsed.aggregates()[0].aggregates()[1].get('FILE_ID').value  // Dig deep
'pg-BR1A0000-2017040601_000_001'

Roll your own!

...
> const PVLRoot = pvl.models.PVLRoot
> const PVLTextString = pvl.models.PVLTextString
> const PVLGroup = pvl.models.PVLGroup

> const simple = new PVLRoot().add('FOO', new PVLTextString('BAR')).add('BAZ', new PVLTextString('QUX'))

> simple
PVLRoot {
  store: [ [ 'FOO', [Object] ], [ 'BAZ', [Object] ] ],
  type: 'ROOT',
  depth: 0 }

> console.log(pvl.jsToPVL(simple))
FOO = "BAR";
BAZ = "QUX";

> const complex = new PVLRoot().addAggregate(new PVLGroup('FOO').add('BAR', new PVLTextString('BAZ'))).addAggregate(new PVLGroup('QUX').add('BAR', new PVLTextString('FIZZ')))

> complex
PVLRoot {
  store: [ [ 'GROUP', [Object] ], [ 'GROUP', [Object] ] ],
  type: 'ROOT',
  depth: 0 }

> console.log(pvl.jsToPVL(complex))
GROUP = FOO;
  BAR = "BAZ";
END_GROUP = FOO;
GROUP = QUX;
  BAR = "FIZZ";
END_GROUP = QUX;

Tests

Run tests with npm test.

Language specs

Contributing

See Cumulus README

Current Tags

  • 1.0.0-beta.4610474d                                ...           canary (a year ago)
  • 1.13.0                                ...           latest (3 days ago)
  • 1.7.1                                ...           patch-1.7.1 (10 months ago)
  • 1.10.1-1                                ...           release-v1.10.1-1 (6 months ago)

67 Versions

  • 1.13.0                                ...           3 days ago
  • 1.12.1                                ...           2 months ago
  • 1.12.0                                ...           2 months ago
  • 1.11.3                                ...           3 months ago
  • 1.11.2                                ...           3 months ago
  • 1.11.1                                ...           5 months ago
  • 1.11.0                                ...           6 months ago
  • 1.10.4                                ...           6 months ago
  • 1.10.1-1                                ...           6 months ago
  • 1.10.3                                ...           7 months ago
  • 1.10.2                                ...           7 months ago
  • 1.10.1                                ...           9 months ago
  • 1.10.0                                ...           9 months ago
  • 1.9.1                                ...           9 months ago
  • 1.9.0                                ...           10 months ago
  • 1.8.1                                ...           10 months ago
  • 1.7.1                                ...           10 months ago
  • 1.8.0                                ...           10 months ago
  • 1.7.0                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.5                                ...           a year ago
  • 1.5.4                                ...           a year ago
  • 1.5.3                                ...           a year ago
  • 1.5.2                                ...           a year ago
  • 1.5.1                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.1                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.4                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 1.0.0-beta.20                                ...           a year ago
  • 1.0.0-beta.19                                ...           a year ago
  • 1.0.0-beta.18                                ...           a year ago
  • 1.0.0-beta.17.2.0                                ...           a year ago
  • 1.0.0-beta.17                                ...           a year ago
  • 1.0.0-beta.16                                ...           a year ago
  • 1.0.0-beta.15                                ...           a year ago
  • 1.0.0-beta.14                                ...           a year ago
  • 1.0.0-beta.13                                ...           a year ago
  • 1.0.0-beta.12                                ...           a year ago
  • 1.0.0-beta.11                                ...           a year ago
  • 1.0.0-beta.10                                ...           a year ago
  • 1.0.0-1.0.0-beta.9.1                                ...           a year ago
  • 1.0.0-1.0.0-beta.9.0                                ...           a year ago
  • 1.0.0-beta.8.3                                ...           a year ago
  • 1.0.0-beta.8                                ...           a year ago
  • 1.0.0-beta.7                                ...           a year ago
  • 1.0.0-beta.6                                ...           a year ago
  • 1.0.0-beta.4                                ...           a year ago
  • 1.0.0-beta.3                                ...           a year ago
  • 1.0.0-beta.2                                ...           a year ago
  • 1.0.0-beta.581d33f2                                ...           a year ago
  • 1.0.0-beta.581d31f2                                ...           a year ago
  • 1.0.0-beta.4610474d                                ...           a year ago
  • 1.0.0-beta.581d31f4                                ...           a year ago
  • 1.2.0-alpha.95df4cc6                                ...           a year ago
  • 1.4.0-alpha.95df4cc6                                ...           a year ago
  • 1.3.0-alpha.c0ebdcd8                                ...           a year ago
  • 1.2.0-alpha.c0ebdcd8                                ...           a year ago
  • 1.1.0-alpha.c0ebdcd8                                ...           a year ago
  • 1.0.0-beta.259fee54                                ...           a year ago
Downloads
Today 0
This Week 23
This Month 90
Last Day 0
Last Week 66
Last Month 38
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |