Mercurial
comparison third_party/bun/node_modules/loose-envify/loose-envify.js @ 12:de54585a40f1
Adding bun and node modules.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 02 Oct 2025 14:39:48 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 11:f33d9ff8b6e8 | 12:de54585a40f1 |
|---|---|
| 1 'use strict'; | |
| 2 | |
| 3 var stream = require('stream'); | |
| 4 var util = require('util'); | |
| 5 var replace = require('./replace'); | |
| 6 | |
| 7 var jsonExtRe = /\.json$/; | |
| 8 | |
| 9 module.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 | |
| 20 function LooseEnvify(envs) { | |
| 21 stream.Transform.call(this); | |
| 22 this._data = ''; | |
| 23 this._envs = envs; | |
| 24 } | |
| 25 util.inherits(LooseEnvify, stream.Transform); | |
| 26 | |
| 27 LooseEnvify.prototype._transform = function(buf, enc, cb) { | |
| 28 this._data += buf; | |
| 29 cb(); | |
| 30 }; | |
| 31 | |
| 32 LooseEnvify.prototype._flush = function(cb) { | |
| 33 var replaced = replace(this._data, this._envs); | |
| 34 this.push(replaced); | |
| 35 cb(); | |
| 36 }; |