Last active
January 21, 2020 15:03
-
-
Save silicakes/6c235cc34ab4bcc27dd0acad5ddf5753 to your computer and use it in GitHub Desktop.
Extracts and returns all named imports from JS import statements i.e the things inside {} when doing: import { foo, bar } from 'some-lib'
This file contains 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
# Relies on ripgrep: https://github.com/BurntSushi/ripgrep | |
# | |
# Params: | |
# <library-name> a string with or without quotes | |
# | |
# Usage: | |
# $ ./extracAllNamedImports <library-name> | |
# Output | |
# $ ./getNamedImportsByLibrary.sh date-fns | |
# addDays | |
# addDaysformat | |
# addMonths | |
# addWeeks | |
# addWeeksformat | |
# addYearsformat | |
# compareDesc | |
rg -o "\{([^}]+)\} from '$1'" --no-filename | sed 's/^[^{]*{\([^{}]*\)}.*/\1/' | tr ',' '\n' | tr '[:space:]' '\n' | sort | uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment