Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 module? #19

Open
OmgImAlexis opened this issue Sep 28, 2018 · 4 comments
Open

ES6 module? #19

OmgImAlexis opened this issue Sep 28, 2018 · 4 comments

Comments

@OmgImAlexis
Copy link

Hi, I've converted this package to an ES6 module and cleaned it up quite a bit. Thought you may want to add a link to the readme for users that need tree shaking, etc.

Ref: master...OmgImAlexis:master

@silentsilas
Copy link

Thank you for this, @OmgImAlexis . Could you also submit it as a pull request in case @marlun78 comes back online one of these days?

For anyone who stumbles upon this in the future, you can run npm install github:OmgImAlexis/number-to-words for the ES6 version. I may submit a pull request for typings in the future.

And a sidenote: I had an issue with importing.
import { toWords } from 'number-to-words'; says that the module does not have a toWords export.

Instead I had to run import * as numberToWords from 'number-to-words'; then numberToWords.default.toWords(someNumber); for it to work. Is it because I'm using an es6 transformer instead of directly importing in a <script type="module"> block?

@tchaffee
Copy link

This might help if you are looking to use the existing package as an ES6 import.

import { default as converter } from 'number-to-words';

converter.toWords(13); // => “thirteen”

@OmgImAlexis
Copy link
Author

@tchaffee you don’t need to rename default.

import x from “package” imports the default already.

@tchaffee
Copy link

@OmgImAlexis I was positive I had tried that and it didn't work... but yes, it does work. Thanks. Just so it's spelled out for anyone looking, this is working for me:

import converter from 'number-to-words';

converter.toWords(13); // => “thirteen”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants