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

template-utils

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

template-utils - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

lib/utils/defaultProps.js

47

lib/utils/toTemplate.js
'use strict';
var _ = require('lodash');
var path = require('path');
var extend = require('extend-shallow');
var matter = require('gray-matter');
var parsePath = require('parse-filepath');
var merge = require('merge-deep');
var pick = require('object.pick');
var vinylProps = require('./vinylProps');
var defaultProps = require('./defaultProps');

@@ -32,43 +33,11 @@ /**

} else if (Buffer.isBuffer(file.contents) || typeof file.contents === 'string') {
o = _.merge({}, o, matter(file.contents.toString()));
o = merge({}, o, matter(file.contents.toString()));
}
_.extend(o, _.pick(file, vinylProps.whitelisted));
extend(o, pick(file, vinylProps.whitelisted));
// setup default properties on the template
defaults(o, ['data', 'options', 'locals'], {});
// add default properties to the template
o.path = o.path || file.path;
o.ext = o.ext || path.extname(o.path);
defaults(o.options, ['engine'], o.ext);
defaults(o.data, ['src', 'dest'], {});
// add default `src` and `dest` properties to the `data` object
if (typeof o.path !== 'string') {
throw new Error('[template-utils] toTemplate expects `.path` to be a string');
}
// Parse `file.path` into an object
var parsed = parsePath(o.path);
for (var prop in parsed) {
if (Boolean(parsed[prop])) {
defaults(o.data.src, [prop], parsed[prop]);
defaults(o.data.dest, [prop], parsed[prop]);
}
}
defaults(o.data.src, ['path'], o.path);
defaults(o.data.dest, ['path'], o.data.src.path);
defaults(o.data.dest, ['ext'], parsed.extname);
defaultProps(o);
return o;
};
function defaults(o, props, fallback) {
var len = props.length;
var i = 0;
while (len--) {
var prop = props[i++];
o[prop] = o[prop] || fallback;
}
}

@@ -5,4 +5,2 @@ 'use strict';

var File = require('vinyl');
var _ = require('lodash');
var extend = _.extend;

@@ -22,3 +20,3 @@ /**

module.exports = function toVinyl(template, options) {
module.exports = function toVinyl(template) {
debug('toVinyl: %j', arguments);

@@ -25,0 +23,0 @@ template.locals = template.locals || {};

{
"name": "template-utils",
"description": "Utils for [Template](https://github.com/jonschlinkert/template).",
"version": "0.2.0",
"version": "0.3.0",
"homepage": "https://github.com/jonschlinkert/template-utils",

@@ -17,8 +17,6 @@ "author": {

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/template-utils/blob/master/LICENSE-MIT"
}
],
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/template-utils/blob/master/LICENSE-MIT"
},
"main": "index.js",

@@ -33,20 +31,17 @@ "engines": {

"async": "^0.9.0",
"chalk": "^0.5.1",
"debug": "^2.1.0",
"escape-delims": "^0.4.0",
"export-files": "^0.1.4",
"extend-shallow": "^0.1.1",
"extend-shallow": "^0.2.0",
"extract-gfm": "^0.1.0",
"globby": "^1.0.0",
"gray-matter": "^0.6.1",
"js-comments": "^0.3.4",
"lodash": "^2.4.1",
"lookup-deps": "^0.2.5",
"gray-matter": "^1.0.2",
"merge-deep": "^0.1.3",
"object.pick": "^1.1.0",
"parse-filepath": "^0.5.0",
"pretty-hrtime": "^0.2.2",
"vinyl": "^0.4.5"
"vinyl": "^0.4.6"
},
"devDependencies": {
"mocha": "*",
"should": "*"
"should": "*",
"verb": "^0.3.9"
},

@@ -53,0 +48,0 @@ "keywords": [

@@ -28,2 +28,8 @@ # template-utils [![NPM version](https://badge.fury.io/js/template-utils.svg)](http://badge.fury.io/js/template-utils)

### [.defaultProps](lib/utils/defaultProps.js#L14)
* `template` **{Object}**: Template Object to add properties to.
Setup default properties and objects on a template object.
### [.headings](lib/utils/headings.js#L22)

@@ -45,5 +51,10 @@

### [.parsePath](lib/utils/parsePath.js#L15)
### [.toTemplate](lib/utils/toTemplate.js#L22)
* `template` **{Object}**: Template object
Add parsed `src` and `dest` path properties to the `data` object.
### [.toTemplate](lib/utils/toTemplate.js#L23)
Convert a Vinyl file object to a non-vinyl template object.

@@ -58,3 +69,3 @@

### [.toVinyl](lib/utils/toVinyl.js#L21)
### [.toVinyl](lib/utils/toVinyl.js#L19)

@@ -72,3 +83,2 @@ Convert a `template` object to a Vinyl file object.

## Contributing

@@ -90,2 +100,2 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/template-utils/issues)

_This file was generated by [verb](https://github.com/assemble/verb) on December 03, 2014._
_This file was generated by [verb](https://github.com/assemble/verb) on December 20, 2014._

@@ -12,3 +12,3 @@ 'use strict';

basename: 'README.md',
dirname: process.cwd().toLowerCase(),
dirname: process.cwd(),
ext: '.md',

@@ -23,3 +23,3 @@ extSegments: ['.md'],

basename: 'README.md',
dirname: process.cwd().toLowerCase(),
dirname: process.cwd(),
ext: '.md',

@@ -37,3 +37,3 @@ extSegments: ['.md'],

basename: 'README.md',
dirname: process.cwd().toLowerCase(),
dirname: process.cwd(),
ext: '.md',

@@ -48,3 +48,3 @@ extSegments: ['.md'],

basename: 'README.md',
dirname: process.cwd().toLowerCase(),
dirname: process.cwd(),
ext: '.md',

@@ -51,0 +51,0 @@ extSegments: ['.md'],

@@ -36,16 +36,5 @@ /*!

describe('.toVinyl()', function () {
// compare the full fixture and expected objects in these tests
// to ensure that we catch any changes to the file object
it('should create a vinyl file object:', function () {
var file = utils.toVinyl({});
file.should.eql({
_contents: null,
base: process.cwd(),
cwd: process.cwd(),
data: {},
history: [],
locals: {},
options: {},
stat: null
});
file.should.have.properties(['_contents', 'base', 'cwd', 'data', 'locals']);
});

@@ -52,0 +41,0 @@

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