Last active
August 25, 2022 08:09
-
-
Save bsitruk/1a6858cb5e90e79103cd24d37830321d to your computer and use it in GitHub Desktop.
ZX Script to build TypeScript Pick type.
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
#!/usr/bin/env zx | |
# usage | |
#./keys-to-enum.mjs "{ 220ms Thu Aug 25 11:04:52 2022 | |
# attributeName, | |
# fieldName, | |
# fullyQualifiedName, | |
# attributeType, | |
# scannerTypeGroup, | |
# }: GetRecordFindingsDto" | |
# Output: {attributeName,fieldName,fullyQualifiedName,attributeType,scannerTypeGroup,}: Pick<GetRecordFindingsDto, 'attributeName'|'fieldName'|'fullyQualifiedName'|'attributeType'|'scannerTypeGroup'> | |
let content = process.argv.at(-1); | |
let cleanedContent = content.replace(/\n\s+/g, ""); | |
let [keys, type] = cleanedContent.split(":"); | |
type = type.trim(); | |
let union = keys | |
.slice(1, -1) | |
.replace(/,$/, "") | |
.split(",") | |
.map((s) => `'${s}'`) | |
.join("|"); | |
let pick = `Pick<${type}, ${union}>`; | |
let final = `${keys}: ${pick}`; | |
echo`${final}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment