Skip to content

datopian/frictionless-ckan-mapper-js

Repository files navigation

Frictionless CKAN Mapper for JS

Node.js CI

This is JS version of Frictionless CKAN Mapper.

A library for mapping CKAN metadata <=> Frictionless metadata.

Install

yarn add frictionless-ckan-mapper-js

or

npm i frictionless-ckan-mapper-js

If you use AMD, UMD, Commonjs or just need the script in browser then install via one of the above commands and then under node_modules/frictionless-ckan-mapper-js/dist/ folder you can find the appropriate frictionless-ckan-mapper.[TARGET NAME].js library. you can use frictionless-ckan-mapper.var.js to load it in the browser which brings frictionlessCkanMapper global variable

Use

In Node

const mapper = require('frictionless-ckan-mapper-js')

In Browser

<!DOCTYPE html>
<html>
  ...
  <script src="https://unpkg.com/frictionless-ckan-mapper-js/dist/frictionless-ckan-mapper.var.js"></script>
  <script>
    // ...
    // frictionlessCkanMapper library is available here
    // ...
  </script>
</html>

Examples

Converting frictionless dataset spec to ckan package spec

const frictionlessDataset = {
  name: 'data.csv',
  path: 'http://someplace.com/data.csv',
  bytes: 100,
  mediatype: 'text/csv',
}

const ckanDataset = mapper.resourceFrictionlessToCkan(frictionlessDataset)

console.log(ckanDataset)
/*
{
  name: 'data.csv',
  url: 'http://someplace.com/data.csv',
  size: 100,
  mimetype: 'text/csv'
}
*/

Converting frictionless package spec to ckan package spec

const frictionlessPackage = {
  name: 'gdp',
  description: 'Country, regional and world GDP in current USD.',
  homepage: 'https://datopian.com',
  title: 'Countries GDP',
  version: '1.0',
  newdict: { key1: 'dict_to_jsonify' },
  newint: 123,
  resources: [
    {
      name: 'data.csv',
      path: 'http://someplace.com/data.csv',
      bytes: 100,
    },
  ],
}

const ckanPackage = mapper.packageFrictionlessToCkan(frictionlessPackage)

console.log(ckanPackage)
/*
{
    name: 'gdp',
    notes: 'Country, regional and world GDP in current USD.',
    url: 'https://datopian.com',
    title: 'Countries GDP',
    version: '1.0',
    extras: [
      { key: 'newdict', value: [Object] },
      { key: 'newint', value: 123 }
    ],
    resources: [
      {
        name: 'data.csv',
        url: 'http://someplace.com/data.csv',
        size: 100
      }
    ]
  }
*/

Converting ckan package spec to frictionless package spec

const ckanPackage = {
  name: 'gdp',
  notes: 'Country, regional and world GDP in current USD.',
  url: 'https://datopian.com',
  title: 'Countries GDP',
  version: '1.0',
  extras: [
    { key: 'newdict', value: [Object] },
    { key: 'newint', value: 123 },
  ],
  resources: [
    {
      name: 'data.csv',
      url: 'http://someplace.com/data.csv',
      size: 100,
    },
  ],
}

const frictionlessPackage = mapper.packageCkanToFrictionless(ckanPackage)

console.log(frictionlessPackage)
/*
{
  name: 'gdp',
  description: 'Country, regional and world GDP in current USD.',
  homepage: 'https://datopian.com',
  title: 'Countries GDP',
  version: '1.0',
  newdict: [ [Function: Object] ],
  newint: 123,
  resources: [
    {
      name: 'data.csv',
      path: 'http://someplace.com/data.csv',
      bytes: 100
    }
  ]
}
*/

Converting ckan dataset spec to frictionless dataset spec

const ckanDataset = {
  name: 'data.csv',
  url: 'http://someplace.com/data.csv',
  size: 100,
  mimetype: 'text/csv',
}

const frictionlessDataset = mapper.resourceCkanToFrictionless(ckanDataset)

console.log(frictionlessDataset)
/*
{
  name: 'data.csv',
  path: 'http://someplace.com/data.csv',
  bytes: 100,
  mediatype: 'text/csv'
}
*/

Sources

Frictionless - Mappings from Other Formats to Frictionless both Profiles and Schemas

Contributing

Please make sure to read the CONTRIBUTING.md Guide before making a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details