@bsky.app/expo-guess-language 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/android/src/main/java/expo/modules/expoguesslanguage/ExpoGuessLanguageModule.kt +1 -1
- package/build/ExpoGuessLanguageModule.d.ts +2 -1
- package/build/ExpoGuessLanguageModule.d.ts.map +1 -1
- package/build/ExpoGuessLanguageModule.js.map +1 -1
- package/build/index.android.d.ts +2 -1
- package/build/index.android.d.ts.map +1 -1
- package/build/index.android.js +7 -10
- package/build/index.android.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -2
- package/build/index.js.map +1 -1
- package/build/index.web.d.ts +2 -1
- package/build/index.web.d.ts.map +1 -1
- package/build/index.web.js +4 -1
- package/build/index.web.js.map +1 -1
- package/ios/ExpoGuessLanguageModule.swift +24 -16
- package/package.json +1 -1
- package/src/ExpoGuessLanguageModule.ts +2 -1
- package/src/index.android.ts +11 -10
- package/src/index.ts +12 -2
- package/src/index.web.ts +8 -1
package/README.md
CHANGED
|
@@ -21,17 +21,30 @@ For bare React Native projects, run `npx pod-install` after installing.
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
+
### Async
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { guessLanguageAsync } from "@bsky.app/expo-guess-language";
|
|
28
|
+
|
|
29
|
+
const results = await guessLanguageAsync("Hello, world!");
|
|
30
|
+
// [{ language: "en", confidence: 0.98 }, ...]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Sync
|
|
34
|
+
|
|
24
35
|
```ts
|
|
25
|
-
import {
|
|
36
|
+
import { guessLanguageSync } from "@bsky.app/expo-guess-language";
|
|
26
37
|
|
|
27
|
-
const results =
|
|
38
|
+
const results = guessLanguageSync("Hello, world!");
|
|
28
39
|
// [{ language: "en", confidence: 0.98 }, ...]
|
|
29
40
|
```
|
|
30
41
|
|
|
42
|
+
On iOS, `guessLanguageSync` uses the native NaturalLanguage framework. On Android and web, it uses the [lande](https://github.com/nicklatkovich/lande) JS library.
|
|
43
|
+
|
|
31
44
|
### Options
|
|
32
45
|
|
|
33
46
|
```ts
|
|
34
|
-
const results = await
|
|
47
|
+
const results = await guessLanguageAsync("Bonjour le monde!", {
|
|
35
48
|
maxResults: 3, // default: 10
|
|
36
49
|
});
|
|
37
50
|
```
|
|
@@ -30,7 +30,7 @@ class ExpoGuessLanguageModule : Module() {
|
|
|
30
30
|
return@Property isPlayServicesAvailable
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
AsyncFunction("
|
|
33
|
+
AsyncFunction("guessLanguageAsync") { text: String, maxResults: Int ->
|
|
34
34
|
if (text.isBlank()) return@AsyncFunction emptyList<Bundle>()
|
|
35
35
|
|
|
36
36
|
val task = languageIdentifier.identifyPossibleLanguages(text)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { LanguageResult } from "./ExpoGuessLanguage.types";
|
|
2
2
|
declare class ExpoGuessLanguageModuleType {
|
|
3
3
|
isNativeAvailable: boolean;
|
|
4
|
-
|
|
4
|
+
guessLanguageAsync(text: string, maxResults: number): Promise<LanguageResult[]>;
|
|
5
|
+
guessLanguageSync(text: string, maxResults: number): LanguageResult[];
|
|
5
6
|
}
|
|
6
7
|
declare const _default: ExpoGuessLanguageModuleType;
|
|
7
8
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoGuessLanguageModule.d.ts","sourceRoot":"","sources":["../src/ExpoGuessLanguageModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,OAAO,2BAA2B;IACvC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,
|
|
1
|
+
{"version":3,"file":"ExpoGuessLanguageModule.d.ts","sourceRoot":"","sources":["../src/ExpoGuessLanguageModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,OAAO,2BAA2B;IACvC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC/E,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,EAAE;CACtE;;AAED,wBAEE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoGuessLanguageModule.js","sourceRoot":"","sources":["../src/ExpoGuessLanguageModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoGuessLanguageModule.js","sourceRoot":"","sources":["../src/ExpoGuessLanguageModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAU3C,eAAe,mBAAmB,CAChC,mBAAmB,CACpB,CAAC","sourcesContent":["import { requireNativeModule } from \"expo\";\n\nimport type { LanguageResult } from \"./ExpoGuessLanguage.types\";\n\ndeclare class ExpoGuessLanguageModuleType {\n isNativeAvailable: boolean;\n guessLanguageAsync(text: string, maxResults: number): Promise<LanguageResult[]>;\n guessLanguageSync(text: string, maxResults: number): LanguageResult[];\n}\n\nexport default requireNativeModule<ExpoGuessLanguageModuleType>(\n \"ExpoGuessLanguage\"\n);\n"]}
|
package/build/index.android.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
2
2
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function guessLanguageAsync(text: string, options?: GuessLanguageOptions): Promise<LanguageResult[]>;
|
|
4
|
+
export declare function guessLanguageSync(text: string, options?: GuessLanguageOptions): LanguageResult[];
|
|
4
5
|
//# sourceMappingURL=index.android.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.android.d.ts","sourceRoot":"","sources":["../src/index.android.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.android.d.ts","sourceRoot":"","sources":["../src/index.android.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,EAAE,CAAC,CAM3B;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,cAAc,EAAE,CAElB"}
|
package/build/index.android.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import ExpoGuessLanguageModule from "./ExpoGuessLanguageModule";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function getLandeDetect() {
|
|
5
|
-
if (!_landeDetect)
|
|
6
|
-
_landeDetect = require("./lande-detect");
|
|
7
|
-
return _landeDetect;
|
|
8
|
-
}
|
|
9
|
-
export function guessLanguage(text, options) {
|
|
2
|
+
import { detectWithLande } from "./lande-detect";
|
|
3
|
+
export function guessLanguageAsync(text, options) {
|
|
10
4
|
const maxResults = options?.maxResults ?? 10;
|
|
11
5
|
if (ExpoGuessLanguageModule.isNativeAvailable) {
|
|
12
|
-
return ExpoGuessLanguageModule.
|
|
6
|
+
return ExpoGuessLanguageModule.guessLanguageAsync(text, maxResults);
|
|
13
7
|
}
|
|
14
|
-
return Promise.resolve(
|
|
8
|
+
return Promise.resolve(detectWithLande(text, maxResults));
|
|
9
|
+
}
|
|
10
|
+
export function guessLanguageSync(text, options) {
|
|
11
|
+
return detectWithLande(text, options?.maxResults ?? 10);
|
|
15
12
|
}
|
|
16
13
|
//# sourceMappingURL=index.android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.android.js","sourceRoot":"","sources":["../src/index.android.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.android.js","sourceRoot":"","sources":["../src/index.android.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMjD,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,OAA8B;IAE9B,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC;IAC7C,IAAI,uBAAuB,CAAC,iBAAiB,EAAE,CAAC;QAC9C,OAAO,uBAAuB,CAAC,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,OAA8B;IAE9B,OAAO,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import ExpoGuessLanguageModule from \"./ExpoGuessLanguageModule\";\nimport { detectWithLande } from \"./lande-detect\";\n\nimport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport function guessLanguageAsync(\n text: string,\n options?: GuessLanguageOptions\n): Promise<LanguageResult[]> {\n const maxResults = options?.maxResults ?? 10;\n if (ExpoGuessLanguageModule.isNativeAvailable) {\n return ExpoGuessLanguageModule.guessLanguageAsync(text, maxResults);\n }\n return Promise.resolve(detectWithLande(text, maxResults));\n}\n\nexport function guessLanguageSync(\n text: string,\n options?: GuessLanguageOptions\n): LanguageResult[] {\n return detectWithLande(text, options?.maxResults ?? 10);\n}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
2
2
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function guessLanguageAsync(text: string, options?: GuessLanguageOptions): Promise<LanguageResult[]>;
|
|
4
|
+
export declare function guessLanguageSync(text: string, options?: GuessLanguageOptions): LanguageResult[];
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,wBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,EAAE,CAAC,CAK3B;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,cAAc,EAAE,CAKlB"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import ExpoGuessLanguageModule from "./ExpoGuessLanguageModule";
|
|
2
|
-
export function
|
|
3
|
-
return ExpoGuessLanguageModule.
|
|
2
|
+
export function guessLanguageAsync(text, options) {
|
|
3
|
+
return ExpoGuessLanguageModule.guessLanguageAsync(text, options?.maxResults ?? 10);
|
|
4
|
+
}
|
|
5
|
+
export function guessLanguageSync(text, options) {
|
|
6
|
+
return ExpoGuessLanguageModule.guessLanguageSync(text, options?.maxResults ?? 10);
|
|
4
7
|
}
|
|
5
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAMhE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAMhE,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,OAA8B;IAE9B,OAAO,uBAAuB,CAAC,kBAAkB,CAC/C,IAAI,EACJ,OAAO,EAAE,UAAU,IAAI,EAAE,CAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,OAA8B;IAE9B,OAAO,uBAAuB,CAAC,iBAAiB,CAC9C,IAAI,EACJ,OAAO,EAAE,UAAU,IAAI,EAAE,CAC1B,CAAC;AACJ,CAAC","sourcesContent":["import ExpoGuessLanguageModule from \"./ExpoGuessLanguageModule\";\n\nimport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport function guessLanguageAsync(\n text: string,\n options?: GuessLanguageOptions\n): Promise<LanguageResult[]> {\n return ExpoGuessLanguageModule.guessLanguageAsync(\n text,\n options?.maxResults ?? 10\n );\n}\n\nexport function guessLanguageSync(\n text: string,\n options?: GuessLanguageOptions\n): LanguageResult[] {\n return ExpoGuessLanguageModule.guessLanguageSync(\n text,\n options?.maxResults ?? 10\n );\n}\n"]}
|
package/build/index.web.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
2
2
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function guessLanguageAsync(text: string, options?: GuessLanguageOptions): Promise<LanguageResult[]>;
|
|
4
|
+
export declare function guessLanguageSync(text: string, options?: GuessLanguageOptions): LanguageResult[];
|
|
4
5
|
//# sourceMappingURL=index.web.d.ts.map
|
package/build/index.web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../src/index.web.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,wBAAgB,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../src/index.web.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEtF,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,EAAE,CAAC,CAE3B;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,cAAc,EAAE,CAElB"}
|
package/build/index.web.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { detectWithLande } from "./lande-detect";
|
|
2
|
-
export function
|
|
2
|
+
export function guessLanguageAsync(text, options) {
|
|
3
3
|
return Promise.resolve(detectWithLande(text, options?.maxResults ?? 10));
|
|
4
4
|
}
|
|
5
|
+
export function guessLanguageSync(text, options) {
|
|
6
|
+
return detectWithLande(text, options?.maxResults ?? 10);
|
|
7
|
+
}
|
|
5
8
|
//# sourceMappingURL=index.web.js.map
|
package/build/index.web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.js","sourceRoot":"","sources":["../src/index.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMjD,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"index.web.js","sourceRoot":"","sources":["../src/index.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMjD,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,OAA8B;IAE9B,OAAO,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,OAA8B;IAE9B,OAAO,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { detectWithLande } from \"./lande-detect\";\n\nimport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport type { GuessLanguageOptions, LanguageResult } from \"./ExpoGuessLanguage.types\";\n\nexport function guessLanguageAsync(\n text: string,\n options?: GuessLanguageOptions\n): Promise<LanguageResult[]> {\n return Promise.resolve(detectWithLande(text, options?.maxResults ?? 10));\n}\n\nexport function guessLanguageSync(\n text: string,\n options?: GuessLanguageOptions\n): LanguageResult[] {\n return detectWithLande(text, options?.maxResults ?? 10);\n}\n"]}
|
|
@@ -9,22 +9,30 @@ public class ExpoGuessLanguageModule: Module {
|
|
|
9
9
|
return true
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
guard !trimmed.isEmpty else { return [] }
|
|
15
|
-
|
|
16
|
-
let recognizer = NLLanguageRecognizer()
|
|
17
|
-
recognizer.processString(text)
|
|
18
|
-
let hypotheses = recognizer.languageHypotheses(withMaximum: maxResults)
|
|
19
|
-
recognizer.reset()
|
|
20
|
-
|
|
21
|
-
let results = hypotheses
|
|
22
|
-
.filter { $0.key != .undetermined }
|
|
23
|
-
.sorted { $0.value > $1.value }
|
|
24
|
-
.prefix(maxResults)
|
|
25
|
-
.map { ["language": $0.key.rawValue, "confidence": $0.value] as [String: Any] }
|
|
26
|
-
|
|
27
|
-
return Array(results)
|
|
12
|
+
Function("guessLanguageSync") { (text: String, maxResults: Int) -> [[String: Any]] in
|
|
13
|
+
return Self.detect(text: text, maxResults: maxResults)
|
|
28
14
|
}
|
|
15
|
+
|
|
16
|
+
AsyncFunction("guessLanguageAsync") { (text: String, maxResults: Int) -> [[String: Any]] in
|
|
17
|
+
return Self.detect(text: text, maxResults: maxResults)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private static func detect(text: String, maxResults: Int) -> [[String: Any]] {
|
|
22
|
+
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
23
|
+
guard !trimmed.isEmpty else { return [] }
|
|
24
|
+
|
|
25
|
+
let recognizer = NLLanguageRecognizer()
|
|
26
|
+
recognizer.processString(text)
|
|
27
|
+
let hypotheses = recognizer.languageHypotheses(withMaximum: maxResults)
|
|
28
|
+
recognizer.reset()
|
|
29
|
+
|
|
30
|
+
let results = hypotheses
|
|
31
|
+
.filter { $0.key != .undetermined }
|
|
32
|
+
.sorted { $0.value > $1.value }
|
|
33
|
+
.prefix(maxResults)
|
|
34
|
+
.map { ["language": $0.key.rawValue, "confidence": $0.value] as [String: Any] }
|
|
35
|
+
|
|
36
|
+
return Array(results)
|
|
29
37
|
}
|
|
30
38
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@ import type { LanguageResult } from "./ExpoGuessLanguage.types";
|
|
|
4
4
|
|
|
5
5
|
declare class ExpoGuessLanguageModuleType {
|
|
6
6
|
isNativeAvailable: boolean;
|
|
7
|
-
|
|
7
|
+
guessLanguageAsync(text: string, maxResults: number): Promise<LanguageResult[]>;
|
|
8
|
+
guessLanguageSync(text: string, maxResults: number): LanguageResult[];
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export default requireNativeModule<ExpoGuessLanguageModuleType>(
|
package/src/index.android.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import ExpoGuessLanguageModule from "./ExpoGuessLanguageModule";
|
|
2
|
+
import { detectWithLande } from "./lande-detect";
|
|
2
3
|
|
|
3
4
|
import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
4
5
|
|
|
5
6
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
let _landeDetect: typeof import("./lande-detect") | undefined;
|
|
9
|
-
function getLandeDetect() {
|
|
10
|
-
if (!_landeDetect) _landeDetect = require("./lande-detect");
|
|
11
|
-
return _landeDetect!;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function guessLanguage(
|
|
8
|
+
export function guessLanguageAsync(
|
|
15
9
|
text: string,
|
|
16
10
|
options?: GuessLanguageOptions
|
|
17
11
|
): Promise<LanguageResult[]> {
|
|
18
12
|
const maxResults = options?.maxResults ?? 10;
|
|
19
13
|
if (ExpoGuessLanguageModule.isNativeAvailable) {
|
|
20
|
-
return ExpoGuessLanguageModule.
|
|
14
|
+
return ExpoGuessLanguageModule.guessLanguageAsync(text, maxResults);
|
|
21
15
|
}
|
|
22
|
-
return Promise.resolve(
|
|
16
|
+
return Promise.resolve(detectWithLande(text, maxResults));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function guessLanguageSync(
|
|
20
|
+
text: string,
|
|
21
|
+
options?: GuessLanguageOptions
|
|
22
|
+
): LanguageResult[] {
|
|
23
|
+
return detectWithLande(text, options?.maxResults ?? 10);
|
|
23
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,11 +4,21 @@ import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.t
|
|
|
4
4
|
|
|
5
5
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function guessLanguageAsync(
|
|
8
8
|
text: string,
|
|
9
9
|
options?: GuessLanguageOptions
|
|
10
10
|
): Promise<LanguageResult[]> {
|
|
11
|
-
return ExpoGuessLanguageModule.
|
|
11
|
+
return ExpoGuessLanguageModule.guessLanguageAsync(
|
|
12
|
+
text,
|
|
13
|
+
options?.maxResults ?? 10
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function guessLanguageSync(
|
|
18
|
+
text: string,
|
|
19
|
+
options?: GuessLanguageOptions
|
|
20
|
+
): LanguageResult[] {
|
|
21
|
+
return ExpoGuessLanguageModule.guessLanguageSync(
|
|
12
22
|
text,
|
|
13
23
|
options?.maxResults ?? 10
|
|
14
24
|
);
|
package/src/index.web.ts
CHANGED
|
@@ -4,9 +4,16 @@ import type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.t
|
|
|
4
4
|
|
|
5
5
|
export type { GuessLanguageOptions, LanguageResult } from "./ExpoGuessLanguage.types";
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function guessLanguageAsync(
|
|
8
8
|
text: string,
|
|
9
9
|
options?: GuessLanguageOptions
|
|
10
10
|
): Promise<LanguageResult[]> {
|
|
11
11
|
return Promise.resolve(detectWithLande(text, options?.maxResults ?? 10));
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
export function guessLanguageSync(
|
|
15
|
+
text: string,
|
|
16
|
+
options?: GuessLanguageOptions
|
|
17
|
+
): LanguageResult[] {
|
|
18
|
+
return detectWithLande(text, options?.maxResults ?? 10);
|
|
19
|
+
}
|