Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Objectify is a node.js module which walks a directory of text files and creates an object based on the directory and files names. The contents of each text file are loaded into properties on the returned objects.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

Objectify

Build Status

Objectify recurses over a directory and builds an object tree that matches the directory's structure while reading the contents of each file into a property on the tree.

npm install objectify

Usage

Assuming the following directory structure:

templates
    admin
        dashboard.html
    blog
        post
            create.html
            show.html
            edit.html
        comment
            create.html
            show.html
            edit.html

Then calling:

var objectify = require('objectify');

var result = objectify('./templates', { extensions: ['html'] });

Would populate the result variable with an object like so:

{
    admin: {
        dashboard: '' // populated with the contents of ./templates/admin/dashboard.html
    },
    blog: {
        post: {
            create: '', // populated with the contents of ./templates/post/create.html
            show: '', // populated with the contents of ./templates/post/show.html
            edit: '', // populated with the contents of ./templates/post/edit.html
        },
        comment: {
            create: '', // populated with the contents of ./templates/comment/create.html
            show: '', // populated with the contents of ./templates/comment/show.html
            edit: '', // populated with the contents of ./templates/comment/edit.html
        }
    }
}

Encoding

Objectify reads text files using utf8 encoding by default. You can specify encoding like so.

var objectify = require('objectify');

var result = objectify('./templates', { extensions: ['html'], encoding: 'ascii' });

Please note: All file operations are performed synchronously. As such, it's best to use objectify when your app starts.

Something went wrong with that request. Please try again.