Skip to content

Commit

Permalink
change the implementation of uniqueness to make use of sets
Browse files Browse the repository at this point in the history
  • Loading branch information
BolajiOlajide committed Apr 11, 2019
1 parent ebcb97c commit c178d93
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ typings/

dist
**/.rts*
sample.js
16 changes: 8 additions & 8 deletions lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const emptyObjProps = (obj: EnvObject) => {
return objCopy;
};

export const getUniqueVarsFromEnvs = (env: object, envExample: EnvObject) =>
getObjKeys(envExample)
.filter(key => {
const envHasKey = env.hasOwnProperty(key);
const keyValue = envExample[key];
return keyValue && envHasKey;
})
.map(key => ({ [key]: envExample[key] }));
export const getUniqueVarsFromEnvs = (env: object, envExample: EnvObject) => {
// making use of the .env because that should be the single source of truth
// the .env.example should be based off the .env and not otherwise
const uniqueKeys = new Set(getObjKeys(env));
const uniqueKeysArray: Array<string> = Array.from(uniqueKeys);
return uniqueKeysArray
.map(key => ({ [key]: envExample[key] || '' }));
}

export const removeStaleVarsFromEnv = (env: object, vars: EnvObject[]) => {
let envCopy: EnvObject = { ...env };
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c178d93

Please sign in to comment.