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

gulp-file-contents-to-keys

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-file-contents-to-keys

convert files into key/value objects where key is filename, value is the content

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

gulp-file-contents-to-keys

NPM package pagh

Input some files, outputs a javascript Object with keys as file names and values as their content (escaped string) Very helpful when working with HTML template files and you want to import them all in an easy way.

See my other related packaged:

gulp-file-contents-to-modules

Compiles templates files (lodash/underscore) to ES6 exports, in a single file

gulp-template-compile-es6

Input template files, output a single file with exports as variables (file name) and values as file contents.

Install

$ npm install gulp-file-contents-to-keys

How it works

Given a nested directory of files like so,

my-files
├── a.html
├── a.html
└── some folder-c
    └── c.html

gulp-file-contents-to-keys reads each file, and outputs a single file representing the contents of each file. The output is an Object (keys/values) and can have a configurable varable name.

Output example:

var templates = {
  "a": "<div>file a</div>",
  "b": "<p style=\"color:red\">file b</p>",
  "some folder-c|c": "<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>"
};

How to Use

var gulp        = require('gulp');
var filesTokeys = require('gulp-file-contents-to-keys');

gulp.task('default', function() {
    gulp.src('./templates/**/*.html')
        .pipe(filesTokeys(
            {
                name            : 'export default templates',
                fileName        : 'output.js',
                minify          : true,
                removeFileTypes : true,
                folderDelimiter : '|',
            }
        ))
        .pipe(gulp.dest('./test/output'))
});

Settings

NameTypeDefaultInfo
nameStringvar temlpatesthe name which points to the created Object. For example: export default templates if you want to import it using ES6 modules
folderDelimiterString|delimiter in Object key, for deep files within folders
fileNameStringexample: 'output.js' will output that file to the stream. it is an optional and the output of the plugin can also be used (within the gulp task) with gulp-concat to output to anywhere
minifyBooleantrueminify the files' content (removes new lines & whitespaces between HTML tags)
removeFileTypesBooleantruedon't include in the Objects keys the file types (disregard .html for example)

FAQs

Package last updated on 29 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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