Skip to content

datastreamapp/datastreamjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataStream Logo
DataStreamJS

DataStream.org API helper. See API documentation for query string values and structure.

Install

npm install https://github.com/datastreamapp/datastreamjs

Use

This packages works in the browser and with NodeJS.

Example

import {
  setAPIKey,
  metadata,
  locations,
  records,
  observations
} from '@datastreamapp/datastreamjs'

setAPIKey('xxxxxxxxxx') // secrets should be injected securely

const observationsStream = await observations({
  $select:
    'DOI,ActivityType,ActivityMediaName,ActivityStartDate,ActivityStartTime,SampleCollectionEquipmentName,CharacteristicName,MethodSpeciation,ResultSampleFraction,ResultValue,ResultUnit,ResultValueType',
  $filter: `DOI eq '10.25976/xxxx-xx00'`,
  $top: 10000
})

for await (const observation of observationsStream) {
  // use record
}

Example: save to file

import { pipeline } from '@datastream/core'
import { csvFormatStream } from '@datastream/csv/format'
import { createWriteStream } from 'node:fs'

import {
  setAPIKey,
  metadata,
  locations,
  records,
  observations
} from '@datastreamapp/datastreamjs'

setAPIKey('xxxxxxxxxx') // secrets should be injected securely

const recordsStream = await records({
  $select:
    'DOI,ActivityType,ActivityMediaName,ActivityStartDate,ActivityStartTime,SampleCollectionEquipmentName,CharacteristicName,MethodSpeciation,ResultSampleFraction,ResultValue,ResultUnit,ResultValueType',
  $filter: `DOI eq '10.25976/xxxx-xx00'`,
  $top: 10000
})

await pipeline([
  recordsStream,
  csvFormatStream(),
  createWriteStream('/path/to/output.csv')
])

About

DataSteam API helper in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published