Needlessly Provoking Marsupials
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    requipublic

    Build Status Dependencies Status Gittip

    NPM Status

    Requi

    Requi is a simple require on steroids, featuring custom engines, recursive require, filters, renaming and other features.

    How to use

    Install it on your project with npm install --save requi, required it and you are ready to go.

    // Require all .js and .json files inside ./lib folder. 
    var requi = require('requi');
    var allMyLibs = requi('./lib');

    Now image that the folder lib contains the fallowing structure:

    - lib
      - libA.js
      - libB.js
      - config.json

    You are now able to acess your libraries inside the allMyLibs variables using allMyLibs.libA, or maybe allMyLibs.config, if you had a subfolder inside lib folder and you activated recursive : true, than you can access it like allMyLibs['subfolder/otherLib'].

    Custom Engines

    By default Requi only allow .js and .json files to be required, but you can use it to require other kind of files, let's se how we can require text files :)

    var fs = require('fs');
    var requi = require('requi');
    var myTexts = requi('./texts', {
        recursive : true,
        whiteList : ['.txt'],
        engines : {
            '.txt' : function(path){
                return fs.readFileSync(path).toString();
            }
        }
    });

    Now myTexts should contain an object whit all texts inside the folder, you can do this for YAML, CoffeeScript and all kind of files.

    Options

    You can pass an object with options as the second argument to Requi, here is a description with all options that you can use:

    • engines: an object with the extension name and a function to require files matching that extension. Default: {'.json' : require , '.js' : require}

    • whiteList: an array whit the extensions that can be required. Default: ['.json', '.js']

    • blackList: an array whit the extensions that cannot be required. Default: []

    • filter: A function that receive the path of the file and returns true or false, files that return false whon't be required. Default: null

    • rename: A function that receive the path of the file and need to return a string, that string will be the key of the required object at the end. Default: null

    • recursive: A boolean that indicates if Requi needs to be recursive or not. Default: false

    • clearPath: A boolean that indicates if Requi should cut off the path of the key name. Default: true

    • clearExt: A boolean that indicates if Requi should cut off the extension of the key name. Default: true

    License (MIT)

    The MIT License (MIT)

    Copyright (c) 2014 Cranic Tecnologia contato@cranic.com.br

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    Keywords

    none

    install

    npm i requi

    Downloadslast 7 days

    6

    version

    0.2.2

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar