String.prototype which returns unmodified string ignoring arguments passed

wscourge Source

I exported my .env variable to production environment correctly, and attending the issue this way in dev environment I found myself writing redundant code today:

const secret_1 = process.env.NODE_ENV !== 'production' ? process.env.SECRET.replace(/\\n/g, '\n') : process.env.SECRET;

As you can see, I repeat process.env.SECRET twice, let's assume it is unforgivable. It got me thinking: Is there any Object or String prototype, to which I can pass arguments and:

let string = "testing"; // it should not matter
let beTrue = string.prototyped(a, b, c) === string;

Will it evaluate the beTrue to true?

Real world example (probably with the cleaner workaround possible, but still):

const magic    = '?';
const method   = process.env.NODE_ENV !== 'production' ? 'replace' : magic;
const secret_2 = process.env.SECRET[method]((/\\n/g, '\n'));

What I am looking for is the value of magic, for which secret_1 === secret_2.



comments powered by Disqus