Skip to content

Instantly share code, notes, and snippets.

@silicakes
Last active January 21, 2020 15:03
Show Gist options
  • Save silicakes/6c235cc34ab4bcc27dd0acad5ddf5753 to your computer and use it in GitHub Desktop.
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'
# 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