parser-utils

Utilies for parser-cache and compatible parsers.

Usage no npm install needed!

<script type="module">
  import parserUtils from 'https://cdn.skypack.dev/parser-utils';
</script>

README

parser-utils NPM version

Utilies for parser-cache and compatible parsers.

Install

Install with npm:

npm i parser-utils --save-dev

Usage

var utils = require('parser-utils');

API

.fileKeys

  • returns {Array}: Array of keys.

Get the array of keys expected on normalized file objects.

.diffKeys

Get an array of keys that should not be on the root of a normalized file object.

  • obj {Object}: The object to inspect.
  • props {Array}: Array of properties to concat to the output.
  • returns {Array}: Array of keys

Example:

var utils = require('parser-utils');
var file = {a: 'a', b: 'b', path: 'a/b/c.md'};
console.log(utils.diffKeys(file));
//=> ['a', 'b']

.siftKeys

  • obj {Object}: The object to normalize.
  • props {Array}: Any additional properties to include.
  • returns {Object}: Normalized object.

Normalize the properties on the given obj.

.mergeData

  • obj {Object}: Object with data objects to merge.
  • locals {Object}: Optional object of data that should "win" over other data.
  • merge {Function}: Function to use for merging data.
  • returns {Object}: Object with a single data property.

Return an object composed only of data properties. If a locals object is supplied, properties in that object will override any properties on the data object. If a locals object is defined, and/or if the locals object has a nested locals property, both will be merged with the data property on the returned object.

.flattenObject

Merge nested properties into the root of the given object. Nested properties occur when, for instance, and options object - intended as locals, is also passed with an actual locals property.

  • obj {Object}: The object to flatten.
  • key {String}: The property to merge onto the root of the object.
  • merge {Function}: Function to use for merging data.
  • returns {Object}: Object with locals merged into the root.

Note that this will only merge properties one level deep.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on September 01, 2014.