Closed LastDragon-ru closed 5 years ago
This doesn't look good. First, there's code duplication. Second, it's unclear why would you require typings for JSON.
Second, it's unclear why would you require typings for JSON.
I need custom metadata in angular app, without typings is not possible to use it => https://github.com/catamphetamine/libphonenumber-js/issues/239#issuecomment-494474677
This doesn't look good.
yes, maybe will be better move MetadataJson
into types
import {MetadataJson} from './types';
export const metadata: MetadataJson;
export default metadata;
but IMHO convertor should generate these files.
I need custom metadata in angular app, without typings is not possible to use it
No need to import
the json file: use the /mobile
subpackage for that.
No need to import the json file: use the /mobile subpackage for that.
but mobile will use metadata.mobile.json.js
, right? I need full
and I also need direct access to metadata
public getCountryCallingCode(country: Country | string): string | null {
const data = this.metadata.countries[this.getCountryCode(country)] || null;
const code = data ? data[0] : null;
return code;
}
mobile will use metadata.mobile.json.js, right?
It will.
and I also need direct access to metadata
That's your issues.
That's your issues.
Nope. Without these typings custom metadata cannot be used in ts.
Nope. Without these typings custom metadata cannot be used in ts.
Show how it can't be used and what's the error message.
Show how it can't be used and what's the error message.
Error will be the same as https://github.com/catamphetamine/libphonenumber-js/issues/239#issuecomment-494474677
Typescript cannot import js without definitions. Of course, it can be solved by hand but much better when you no need additional work to use the library.
Typescript cannot import js without definitions.
So MetadataJson
(and ExamplesJson
) type required in any case. The *.json.d.ts
probably will be better to generate while json->js conversion.
Paste the code that results in the error.
Paste the code that results in the error.
import { Component } from '@angular/core';
import {parsePhoneNumberFromString} from 'libphonenumber-js/core';
import metadata from 'libphonenumber-js/metadata.min.json.js';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
test() {
const parsed = parsePhoneNumberFromString('+7 495 441 12 34', metadata);
const valid = parsed != null && parsed.isValid();
return valid;
}
}
Full source angular-1saffi.zip
Why would you import metadata.min.json
manually.
There's no need, use the /min
package.
Why would you import metadata.min.json manually.
Because I need some additional data from metadata? Eg country calling code to output it for user.
Use this instead.
Ok, thanks. Any way to access to country_calling_codes
to find a country by one number? ("+1" - US, "+7" - RU, etc)
Any way to access to country_calling_codes to find a country by one number? ("+1" - US, "+7" - RU, etc)
Multiple countries have the same prefixes.
Multiple countries have the same prefixes.
I know. But I need same behavior like https://intl-tel-input.com/ (+7 will ru, not kz)
I know. But I need same behavior like https://intl-tel-input.com/ (+7 will ru, not kz)
+7
is both for RU and KZ.
+7 is both for RU and KZ.
Check the example please
Check the example please
No, you check.
Not sure that this is the best way, maybe will be better create
d.ts
files automatically while json to js conversion, unfortunately, I'm not sure how to implement this.