marlun78 / number-to-words

Converts a number to words
MIT License
225 stars 76 forks source link

ES6 module? #19

Open OmgImAlexis opened 6 years ago

OmgImAlexis commented 6 years ago

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

silentsilas commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

@tchaffee you don’t need to rename default.

import x from “package” imports the default already.

tchaffee commented 4 years ago

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