JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q32869F
  • License MIT

Walks a directory of text files and creates an object based on the directory and files names.

Package Exports

  • objectify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (objectify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.