Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved out code to lib/envious.js

  • Loading branch information...
commit 3af16d1ed3c31d0faedaeb18e6e148e70fe3ee1e 1 parent b7e2300
@markbao authored
Showing with 49 additions and 48 deletions.
  1. +48 −0 lib/envious.js
  2. +1 −48 main.js
View
48 lib/envious.js
@@ -0,0 +1,48 @@
+// Copyright 2011 Mark Bao
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+function envious () {
+
+ // apply the environment
+ // [param] strict: usually, giving an invalid environment name
+ // would fall back to default. make true to
+ // throw an error for an invalid env instead.
+ this.apply = function(options) {
+ if (!options) options = {}
+ env = process.env.NODE_ENV;
+ if (this[env]) {
+ // environment matched
+ return this[env];
+ } else {
+ // no environment matched
+ if (env && options.strict) {
+ // env defined, but not matched
+ throw new Error('envious: couldn\'t find environment `' + env + '`');
+ } else {
+ // env is undefined/empty
+ if (!this.default_env) {
+ throw new Error('envious: no default environment found');
+ } else if (this.default_env && !this[this.default_env]) {
+ // default not found
+ throw new Error('envious: no configuration found for default environment `' + this.default_env + '`');
+ } else if (this.default_env && this[this.default_env]) {
+ // return default
+ return this[this.default_env];
+ }
+ }
+ }
+ }
+}
+
+module.exports = new envious();
View
49 main.js
@@ -1,48 +1 @@
-// Copyright 2011 Mark Bao
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-function envious () {
-
- // apply the environment
- // [param] strict: usually, giving an invalid environment name
- // would fall back to default. make true to
- // throw an error for an invalid env instead.
- this.apply = function(options) {
- if (!options) options = {}
- env = process.env.NODE_ENV;
- if (this[env]) {
- // environment matched
- return this[env];
- } else {
- // no environment matched
- if (env && options.strict) {
- // env defined, but not matched
- throw new Error('envious: couldn\'t find environment `' + env + '`');
- } else {
- // env is undefined/empty
- if (!this.default_env) {
- throw new Error('envious: no default environment found');
- } else if (this.default_env && !this[this.default_env]) {
- // default not found
- throw new Error('envious: no configuration found for default environment `' + this.default_env + '`');
- } else if (this.default_env && this[this.default_env]) {
- // return default
- return this[this.default_env];
- }
- }
- }
- }
-}
-
-module.exports = new envious();
+module.exports = require('./lib/envious');
Please sign in to comment.
Something went wrong with that request. Please try again.