-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.ts
44 lines (38 loc) · 1.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { NativeModules, Platform } from 'react-native';
export interface IdentifiedLanguage {
/**
* The [BCP-47 language code](https://en.wikipedia.org/wiki/IETF_language_tag)
*/
language: string;
confidence: number;
}
interface IIdentifyLanguages {
/**
* Identify the language of text
*
* @returns [BCP-47 language code](https://en.wikipedia.org/wiki/IETF_language_tag) or `und` if language not known
*/
identify: (text: string) => Promise<string>;
/**
* Identify text language possiblities
*
* @returns Array of `IdentifiedLanguage`
*/
identifyPossible: (text: string) => Promise<IdentifiedLanguage[]>;
}
const LINKING_ERROR =
`The package '@react-native-ml-kit/identify-languages' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
const IdentifyLanguage: IIdentifyLanguages = NativeModules.IdentifyLanguages
? NativeModules.IdentifyLanguages
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
export default IdentifyLanguage;