Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assemble-yaml

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assemble-yaml - npm Package Compare versions

Comparing version 0.1.3 to 0.1.5

docs/getting-started.md

13

bower.json
{
"name": "assemble-yaml",
"version": "0.1.3",
"version": "0.1.5",
"repo": "https://github.com/assemble/assemble-yaml.git",

@@ -9,7 +9,6 @@ "main": [

"dependencies": {
"lodash": "~1.3.1",
"js-yaml": "~2.1.0"
"js-yaml": "~2.1.0",
"lodash": "~1.3.1"
},
"devDependencies": {
"grunt-mocha-test": "~0.6.2",
"chai": "~1.7.2",

@@ -19,6 +18,6 @@ "grunt": "~0.4.1",

"grunt-contrib-watch": "~0.5.1",
"assemble-internal": "~0.2.0",
"grunt-sync-pkg": "~0.1.0",
"grunt-readme": "~0.1.3"
"grunt-mocha-test": "~0.6.2",
"grunt-readme": "~0.1.3",
"grunt-sync-pkg": "~0.1.0"
}
}

@@ -1,30 +0,31 @@

# {%= name %} [![NPM version](https://badge.fury.io/js/{%= name %}.png)](http://badge.fury.io/js/{%= name %}) [![Build Status](http://github.com/assemble/{%= name %}.png?branch=master)](http://github.com/assemble/{%= name %})
---
username: doowb
---
# {%= name %} [![NPM version](https://badge.fury.io/js/{%= name %}.png)](http://badge.fury.io/js/{%= name %}) {% if (travis) { %} [![Build Status]({%= travis %}.png)]({%= travis %}){% } %}
> Utility library for working with YAML front matter.
> {%= description %}
Visit [Assemble's documentation](http://assemble.io) for many more examples and pointers on getting started.
## Getting Started
{%= _.doc('getting-started.md') %}
```shell
npm install {%= name %} --save
```
## Methods
{%= _.doc('methods.md') %}
and use it as follows:
{% if (changelog) { %}
## Release History
{%= _.include("docs-changelog.md") %} {% } %}
```js
var yfm = require('{%= name %}');
var data = yfm.extract("./file.hbs");
```
## Author
+ [github.com/{%= username %}](https://github.com/{%= username %})
+ [twitter.com/{%= username %}](http://twitter.com/{%= username %})
## Release History
## License
{%= copyright %}
{%= license %}
* 2013-08-11   v0.1.0   Initial setup - Migrated from main Assemble repo
***
Project authored by [Brian Woodward](https://github.com/doowb/).
_This file was generated on Mon Sep 02 2013 09:44:51._

@@ -0,1 +1,10 @@

/*
* assemble-yaml
* https://github.com/assemble/assemble-yaml
*
* Copyright (c) 2013 Brian Woodward, contributors.
* Licensed under the MIT license.
*/
/*global module:false*/

@@ -13,3 +22,3 @@ module.exports = function(grunt) {

lib_test: {
src: ['lib/**/*.js', 'test/**/*.js']
src: ['lib/*.js', 'test/*.js']
}

@@ -49,6 +58,4 @@ },

grunt.registerTask('docs', ['assemble-internal']);
// Default task.
grunt.registerTask('default', ['jshint', 'test', 'readme', 'sync']);
};

@@ -1,59 +0,95 @@

var fs = require('fs'),
_ = require('lodash'),
yaml = require('js-yaml');
/*
* assemble-yaml
* https://github.com/assemble/assemble-yaml
*
* Copyright (c) 2013 Brian Woodward, contributors.
* Licensed under the MIT license.
*/
'use strict';
var yaml = require('js-yaml');
var fs = require('fs');
var _ = require('lodash');
var yamlOptions = ['filename', 'strict', 'schema'];
var yfm = {
extract: function(src, opts) {
/**
* Extract YAML front matter and content from files.
* @param {String} src The file to read.
* @param {Object} opts Options to pass to js-yaml
* @return {Object} Object with three properties
* {
* "context": {} // Object. Stringified JSON from YAML front matter
* "content": "" // String. File content, stripped of YAML front matter
* "originalContent": "" // String. Both content and YAML front matter.
* }
*/
exports.extract = function (src, opts) {
var options = _.extend({fromFile: true}, opts);
var data = {
originalContent: '',
content: '',
context: {}
};
var options = _.extend({}, {fromFile: true}, opts);
var delim = '---';
var data = {
originalContent: '',
content: '',
context: {}
};
if(options.fromFile) {
if(!fs.existsSync(src)) {
console.log('File: ' + src + ' not found.');
return false;
}
// Default delimiter
var delim = '---';
// read in file
data.originalContent = fs.readFileSync(src, 'utf8');
} else {
data.originalContent = src;
if (options.fromFile) {
if (!fs.existsSync(src)) {
console.log('File: ' + src + ' not found.');
return false;
}
// find front matter
if(data.originalContent.indexOf(delim) !== 0) {
data.content = data.originalContent;
return data;
}
// Read in file
data.originalContent = fs.readFileSync(src, 'utf8');
} else {
data.originalContent = src;
}
// end of yaml
var eoy = data.originalContent.indexOf(delim, delim.length);
var yamlText = '';
if(eoy === -1) {
yamlText = data.originalContent;
} else {
yamlText = data.originalContent.substring(0, eoy);
}
// Extract YAML front matter
if (data.originalContent.indexOf(delim) !== 0) {
data.content = data.originalContent;
return data;
}
try {
data.context = _.extend(data.context, yaml.load(yamlText, _.pick(options, yamlOptions)));
} catch(e) {
console.log(e);
return false;
}
// Identify end of YAML front matter
var eoy = data.originalContent.indexOf(delim, delim.length);
data.content = data.originalContent.substring(eoy + delim.length);
return data;
var yamlText = '';
if (eoy === -1) {
yamlText = data.originalContent;
} else {
yamlText = data.originalContent.substring(0, eoy);
}
try {
data.context = _.extend(data.context, yaml.load(yamlText, _.pick(options, yamlOptions)));
} catch (e) {
console.log(e);
return false;
}
data.content = data.originalContent.substring(eoy + delim.length).replace(/^(\s*)/, '');
return data;
};
module.exports = exports = yfm;
/**
* Convenience method for extracting YAML front matter only.
*/
exports.extractJSON = function(src, opts) {
return exports.extract(src, opts).context;
};
/**
* Convenience method for returning the content of the file,
* with YFM stipped.
*/
exports.stripYFM = function(src, opts) {
return exports.extract(src, opts).content;
};
{
"name": "assemble-yaml",
"version": "0.1.3",
"description": "Utility library for working with YAML front matter.",
"repository": {
"type": "git",
"url": "git://github.com/assemble/assemble-yaml.git"
},
"version": "0.1.5",
"description": "Utility library for working with YAML front matter. Works with or without Assemble.",
"author": {

@@ -13,2 +9,3 @@ "name": "Brian Woodward",

},
"homepage": "https://github.com/assemble/assemble-yaml",
"contributors": [

@@ -27,5 +24,9 @@ {

"type": "MIT",
"url": "https://github.com/assemble/assemble/blob/master/LICENSE-MIT"
"url": "https://github.com/assemble/assemble-yaml/blob/master/LICENSE-MIT"
}
],
"repository": {
"type": "git",
"url": "https://github.com/assemble/assemble-yaml.git"
},
"bugs": {

@@ -39,3 +40,2 @@ "url": "https://github.com/assemble/assemble-yaml/issues"

"devDependencies": {
"grunt-mocha-test": "~0.6.2",
"chai": "~1.7.2",

@@ -45,16 +45,17 @@ "grunt": "~0.4.1",

"grunt-contrib-watch": "~0.5.1",
"assemble-internal": "~0.2.0",
"grunt-sync-pkg": "~0.1.0",
"grunt-readme": "~0.1.3"
"grunt-mocha-test": "~0.6.2",
"grunt-readme": "~0.1.3",
"grunt-sync-pkg": "~0.1.0"
},
"dependencies": {
"lodash": "~1.3.1",
"js-yaml": "~2.1.0"
"js-yaml": "~2.1.0",
"lodash": "~1.3.1"
},
"keywords": [
"assemble",
"yaml front matter",
"front matter",
"jekyll",
"metadata",
"static site generator",
"jekyll",
"yaml front matter",
"yaml",

@@ -61,0 +62,0 @@ "yfm"

@@ -1,10 +0,8 @@

# assemble-yaml [![NPM version](https://badge.fury.io/js/assemble-yaml.png)](http://badge.fury.io/js/assemble-yaml) [![Build Status](http://github.com/assemble/assemble-yaml.png?branch=master)](http://github.com/assemble/assemble-yaml)
# assemble-yaml [![NPM version](https://badge.fury.io/js/assemble-yaml.png)](http://badge.fury.io/js/assemble-yaml) [![Build Status](https://travis-ci.org/assemble/assemble-yaml.png)](https://travis-ci.org/assemble/assemble-yaml)
> Utility library for working with YAML front matter.
> Utility library for working with YAML front matter. Works with or without Assemble.
Visit [Assemble's documentation](http://assemble.io) for many more examples and pointers on getting started.
## Getting Started
```shell

@@ -18,14 +16,77 @@ npm install assemble-yaml --save

var yfm = require('assemble-yaml');
var data = yfm.extract("./file.hbs");
```
## Methods
#### extract
Extract YAML front matter and content from files.
```js
var raw = yfm.extract("./file.hbs", opts);
```
**Parameters**:
* `String`: The file to read.
* `Object`: The options object to pass to [js-yaml](https://github.com/nodeca/js-yaml)
**Returns**:
Object with three properties
```js
{
"context": {} // Object. YAML front matter returned as a JSON object.
"content": "" // String. File content, stripped of YAML front matter
"originalContent": "" // String. Both content and YAML front matter.
}
```
#### context
Return YAML front matter as a JSON object.
```js
var data = yfm.extract("./file.hbs").context;
```
Alias:
```js
var data = yfm.extractJSON("./file.hbs");
```
#### content
Return the content of a file, with YAML front matter removed.
```js
var content = yfm.extract("./file.hbs").content;
```
Alias:
```js
var data = yfm.stripYFM("./file.hbs");
```
## Release History
* 2013-09-27   v0.1.3   Adds extractJSON and stripYFM convenience methods. Add regex to strip extraneous newlines left over after YFM is removed from a file.
* 2013-09-22   v0.1.2   Adds grunt-readme and grunt-pkg-sync
* 2013-08-11   v0.1.0   Initial setup - Migrated from main Assemble repo
## Author
+ [github.com/doowb](https://github.com/doowb)
+ [twitter.com/doowb](http://twitter.com/doowb)
## License
Copyright (c) 2013 Brian Woodward, contributors.
Released under the MIT license
***
Project authored by [Brian Woodward](https://github.com/doowb/).
_This file was generated on Mon Sep 02 2013 09:44:51._

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc