source: node_modules/loose-envify/loose-envify.js

Last change on this file was 47f4eaf, checked in by Marko <Marko@…>, 23 months ago

Final features implemented

  • Property mode set to 100644
File size: 791 bytes
RevLine 
[47f4eaf]1'use strict';
2
3var stream = require('stream');
4var util = require('util');
5var replace = require('./replace');
6
7var jsonExtRe = /\.json$/;
8
9module.exports = function(rootEnv) {
10 rootEnv = rootEnv || process.env;
11 return function (file, trOpts) {
12 if (jsonExtRe.test(file)) {
13 return stream.PassThrough();
14 }
15 var envs = trOpts ? [rootEnv, trOpts] : [rootEnv];
16 return new LooseEnvify(envs);
17 };
18};
19
20function LooseEnvify(envs) {
21 stream.Transform.call(this);
22 this._data = '';
23 this._envs = envs;
24}
25util.inherits(LooseEnvify, stream.Transform);
26
27LooseEnvify.prototype._transform = function(buf, enc, cb) {
28 this._data += buf;
29 cb();
30};
31
32LooseEnvify.prototype._flush = function(cb) {
33 var replaced = replace(this._data, this._envs);
34 this.push(replaced);
35 cb();
36};
Note: See TracBrowser for help on using the repository browser.