Created
June 13, 2022 12:02
-
-
Save HenriqueSilverio/580ce4a970041bb621d1b7777c3d8a8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run(opts) { | |
const result = {} | |
if (isPlainObject(opts?.tags) === false || isPlainEmptyObject(opts?.tags)) { | |
result.tags = {} | |
result.tags.latest = null | |
} else { | |
if (opts.tags.latest === undefined) { | |
result.tags = { | |
latest: null, | |
...opts.tags, | |
} | |
} | |
} | |
return result | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPlainObject(value) { | |
if (!value) return false | |
return Object.getPrototypeOf(value) === Object.prototype | |
} | |
function isPlainEmptyObject(value) { | |
if (!isPlainObject(value)) return false | |
if (Object.keys(value).length === 0) return true | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment