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

configly

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configly - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

docs/docco.css

145

index.js

@@ -0,1 +1,20 @@

// Configly
// ========
//
// This module aims to simplify site configurations. The only modules that this
// module depends on are core modules (`fs` and `path`), so the footprint is
// light.
//
// It provides an easy way to set up environment specific configurations without
// getting in your way.
//
// There some some Node hosting solutions that get some of that environment
// configuration (such as port, host, and other things) that are only available
// in the js runtime environment, which rules json out. Because of this, this
// module allows you to use either `.json` or `.js` extensions in your config
// files. You just have to make sure you export your config object through
// `module.exports` in your `.js` files.
//
// Read more below to see how this process works.
'use strict';

@@ -6,3 +25,3 @@

, DEFAULT_ENV = 'development'
, VALID_EXT = ['js', 'json']
, VALID_EXT = ['.js', '.json']
, fs = require('fs')

@@ -15,5 +34,8 @@ , path = require('path')

, camelCase
, jsFilter
, fileExtFilter
;
// If the path `process.cwd() + '/config'` doesn't exist, config will be an
// Error object, which can then be handled by the user how they would like.
if (!pathExists) {

@@ -23,14 +45,23 @@ config = new Error('The config folder does not exists');

// Get/set the node environment variable
// Get/set the node environment variable. The default environment variable is
// `development
process.env.NODE_ENV = process.env.NODE_ENV || DEFAULT_ENV;
/**
* processConfigFile
*
* @purpose
* to process a config file and attach it properly to the config object
*
* @parameters
* filepath: String - the filepath relative to CONFIG_PATH to the config file
*/
// processConfigFile
// -----------------
//
// Purpose is to process a config file and attach is properly to the config
// object.
//
// If the filename contains a `env.` prefix and the rest of the filename matches
// the environment name, then it gets put into `config.env`.
//
// All of the other non-environment specific get put in as properties of the
// config object. For example, a file by the name of `test-object.json` gets
// read and input as `config.testObject`. Note the camelCasification.
//
// ### Parameters
//
// * filepath (String): The name of the file within the config directory
processConfigFile = function (filepath) {

@@ -45,10 +76,19 @@

, configPath = CONFIG_PATH + '/' + filepath
, configObject
;
// Check to see that the require works. If it doesn't, make it return the
// exception instead.
try {
configObject = require(configPath);
} catch (exception) {
configObject = exception;
}
if (isEnv) {
if (isRightEnv) {
config.env = require(configPath);
config.env = configObject;
}
} else {
config[name] = require(configPath);
config[name] = configObject;
}

@@ -58,14 +98,19 @@

/**
* camelCase
*
* @purpose
* to convert a string to camelcase, first letter lowercase
*
* @parameters
* str: String - the string to convert
*
* @returns
* the given string (str) in camelCase
*/
// camelCase
// ---------
//
// The purpose is to convert a string (specifically a filename) to camelCase.
// This is used in order to convert a standard filename (which should be all
// all lowercase letters with words separated by hyphens) into camelCase to be
// used in the returned config object. Words can also be separated by
// underscores.
//
// ### Parameters
//
// * str (String): The filename (without the extension)
//
// ### Returns
//
// (String): The string that was inputed converted to camelCase
camelCase = function (str) {

@@ -88,26 +133,36 @@ var firstWord = true;

/**
* jsFilter
*
* @purpose
* to filter through filepaths to only get .js and .json files. Should be used
* with Array.prototype.filter()
*
* @parameters
* filepath: String - the filepath to check
*
* @returns
* true if it matches the .js or .json file extension
*/
jsFilter = function (filepath) {
var ext = filepath.split('.').pop()
, valid = VALID_EXT.indexOf(ext) > -1
;
return valid;
// fileExtFilter
// -------------
//
// filters through filepaths to only get .js and .json files. Shoule be used
// with Array.prototype.filter()
//
// ### Parameters
//
// * validExt (Array): an array of the file extensions to check
//
// ### Returns
//
// * (Function): The function takes in a string (filepath) and returns a
// boolean, true if the file's extension matches the given parameters, false
// if otherwise.
fileExtFilter = function (validExt) {
return function (filepath) {
var ext = path.extname(filepath)
, valid = validExt.indexOf(ext) > -1
;
return valid;
};
};
// Here is where the magic happens. It filters through all of the files found in
// the config directory, and returns the files that are valid. We then map
// through those and process the file accordingly.
files
.filter(jsFilter)
.filter(fileExtFilter(VALID_EXT))
.map(processConfigFile);
// Em fim, we export the config file
module.exports = config;
{
"name": "configly",
"version": "1.0.3",
"version": "1.0.4",
"description": "Provides an easy way to set up environmental configuration",

@@ -32,4 +32,5 @@ "main": "index.js",

"should": "~3.1.0",
"gulp-blanket-mocha": "0.0.4"
"gulp-blanket-mocha": "0.0.4",
"gulp-exec": "~1.0.4"
}
}

Sorry, the diff of this file is not supported yet

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