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

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 791 bytes
Line 
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.