catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.77k stars 218 forks source link

Alternate (npx-pkg compatible) way to use max scope? #414

Open berndnoll opened 2 years ago

berndnoll commented 2 years ago

Hi there, great library, your work is very much appreciated! I have an issue with packaging the library into a standalone executable. (pkg)

const LPN = require("libphonenumber-js/max")

When I execute it gives me

pkg/prelude/bootstrap.js:1697 throw error; ^ Error: Cannot find module 'libphonenumber-js/max' According to pkg logs it does include all the files in subdirectory max. Not sure if this is specific to this lib or a general pkg problem. Any advice on how to use the max version in a pkg package? Any workarounds?

Thanks Bernd

catamphetamine commented 2 years ago

Hi.

Any advice on how to use the max version in a pkg package?

I guess none. I haven't ever hear of that "pkg" thing.

berndnoll commented 2 years ago

What about using max as a default instead of min?

catamphetamine commented 2 years ago

What about using max as a default instead of min?

What?

berndnoll commented 2 years ago

I am talking about the metadata set. Why not make "max" the default metadata set instead of "min". Or is there any other way to use the "max" set without using require("libphonenumber-js/max")?

Documentation I refer to: `This library provides different "metadata" sets, "metadata" being a list of phone number parsing and formatting rules for all countries. The complete list of those rules is huge, so this library provides a way to optimize bundle size by choosing between max, min, mobile and "custom" metadata:

max — The complete metadata set, is about 145 kilobytes in size (libphonenumber-js/metadata.full.json). Choose this when you need the most strict version of isValid(), or if you need to detect phone number type ("fixed line", "mobile", etc).`

catamphetamine commented 2 years ago

Why not make "max" the default metadata set instead of "min".

Because of the size. See the readme.

Or is there any other way to use the "max" set without using require("libphonenumber-js/max")?

No.

gabriellett commented 2 years ago

I'm facing the same issue when trying to use this library submodules with pkg. It seems like pkg is not packaging it correctly.

Could be something with the way submodules were setup here, because with other libraries, like lodash it works when importing submodules.