metalsmith-data
A metalsmith plugin to add namespaced global data objects from files.
Last updated 10 months ago by elcontraption .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-data 
SYNC missed versions from official npm registry.

metalsmith-data

A metalsmith plugin to add namespaced global data objects from files or dynamically from plain JS objects or functions.

Installation

$ npm install metalsmith-data

Usage

var metalsmith = require('Metalsmith')

metalsmith
  .use(data(
    {
      // Add data from file to the `data.test1` namespace:
      test1: './path/to/test/file.json',
  
      // Add nested property from file to the `data.test2` namespace:
      test2: {
        src: './path/to/test/file.json',
        property: 'propName',
        options: {
          ignoreMissingFile: true, //do not throw an error if the file is missing. Defaults to "false"
        }
      },

      // Add a plain JS object to the `data.test3` namespace:
      test3: {
        foo: 'bar'
      },


      // Add a plain JS object to the `data.test4` namespace, via a function:
      test4: function() {
          var bar = 1+2;
          return { foo: bar }
      },
      
      // Add options to use with a CSV file
      // See: https://csv.js.org/parse/options/
      test5: {
        src: './path/to/test/file.csv',
        options:{
          delimiter: ',', //Set the field delimiter. Defaults to ","
          columns: true, //Generate records as object literals instead of arrays
          trim: true, //ignore whitespace immediately around the delimiter
          cast: true //attempt to convert input string to native types
        }
      }
  }))

Contributing

See Contributing.

Current Tags

  • 0.3.1                                ...           latest (10 months ago)

7 Versions

  • 0.3.1                                ...           10 months ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |