npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-file-contents-to-keys

v2.0.0

Published

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

Downloads

12

Readme

gulp-file-contents-to-keys

NPM package page

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
    └── deep
        └── d.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.

How to Use (with GULP)

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'))
});

Output example:

export default 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>",
        "deep": {
            "d": "<p>deepest</p>"
        }
    }
};

Settings

Name | Type | Default | Info ------------------ | ---------- | -----------------| -------------------------------------------------------------------------- name | String | var temlpates | the name which points to the created Object. For example: export default templates if you want to import it using ES6 modules fileName | String | | example: '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 minify | Boolean | true | minify the files' content (removes new lines & whitespaces between HTML tags) removeFileTypes | Boolean | true | don't include in the Objects keys the file types (disregard .html for example)