number-to-words icon indicating copy to clipboard operation
number-to-words copied to clipboard

ES6 module?

Open OmgImAlexis opened this issue 5 years ago • 4 comments

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: https://github.com/marlun78/number-to-words/compare/master...OmgImAlexis:master

OmgImAlexis avatar Sep 28 '18 06:09 OmgImAlexis

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?

silentsilas avatar Nov 06 '19 17:11 silentsilas

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”

tchaffee avatar Mar 26 '20 13:03 tchaffee

@tchaffee you don’t need to rename default.

import x from “package” imports the default already.

OmgImAlexis avatar Mar 26 '20 21:03 OmgImAlexis

@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”

tchaffee avatar Mar 29 '20 21:03 tchaffee