Skip to content

Commit da47ed2

Browse files
authored
Merge pull request #3 from AlshehriAli0/feat/consolidate-api
feat!: consolidate API to VersionCheck object with consistent options
2 parents 6b04ff6 + d1c1d1f commit da47ed2

File tree

28 files changed

+983
-209
lines changed

28 files changed

+983
-209
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ jobs:
1616
- uses: oven-sh/setup-bun@v2
1717

1818
- run: bun install --frozen-lockfile
19+
working-directory: ./package
1920

2021
- run: bun run lint
22+
working-directory: ./package
2123

2224
- run: bun run typecheck
25+
working-directory: ./package
26+
27+
test:
28+
name: Test Suite
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- uses: oven-sh/setup-bun@v2
34+
35+
- run: bun install --frozen-lockfile
36+
working-directory: ./package
37+
38+
- run: bun run test:coverage
39+
working-directory: ./package

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ lib/
6464
.cache
6565
*.tsbuildinfo
6666

67+
# Test coverage and Jest
68+
coverage/
69+
package/coverage/
70+
.jest-cache/
71+
72+
# Claude Code
73+
.claude/
74+
6775
# Docusaurus
6876
docs/.docusaurus/
6977
docs/build/

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
## Example
1616

1717
```ts
18-
import { VersionCheck, needsUpdate, getStoreUrl } from 'react-native-nitro-version-check'
18+
import { VersionCheck } from 'react-native-nitro-version-check'
1919

2020
// Sync — no bridge, no async
2121
VersionCheck.version // "1.2.0"
2222
VersionCheck.buildNumber // "42"
2323
VersionCheck.packageName // "com.example.app"
2424
VersionCheck.installSource // "appstore" | "testflight" | "playstore" | undefined
2525

26+
// Or destructure properties
27+
const { version, buildNumber, packageName, installSource } = VersionCheck
28+
2629
// Check for updates
27-
if (await needsUpdate()) {
28-
Linking.openURL(await getStoreUrl())
30+
if (await VersionCheck.needsUpdate()) {
31+
Linking.openURL(await VersionCheck.getStoreUrl())
2932
}
3033
```
3134

biome.json

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"useGetterReturn": "error"
104104
}
105105
},
106-
"includes": ["package/src/**", "example/**", "!**/*.d.ts", "!**/node_modules/**"]
106+
"includes": ["package/src/**", "example/**", "!**/*.d.ts", "!**/node_modules/**", "!**/__tests__/**"]
107107
},
108108
"javascript": {
109109
"formatter": {
@@ -120,6 +120,39 @@
120120
},
121121
"html": { "formatter": { "selfCloseVoidElements": "always" } },
122122
"overrides": [
123+
{
124+
"includes": ["**/__tests__/**/*.{js,jsx,ts,tsx}"],
125+
"javascript": {
126+
"globals": [
127+
"require",
128+
"console",
129+
"setTimeout",
130+
"requestAnimationFrame",
131+
"setInterval",
132+
"process",
133+
"__DEV__",
134+
"cancelAnimationFrame",
135+
"fetch",
136+
"clearTimeout",
137+
"clearInterval",
138+
"jest",
139+
"describe",
140+
"it",
141+
"expect",
142+
"beforeEach",
143+
"afterEach",
144+
"beforeAll",
145+
"afterAll"
146+
]
147+
},
148+
"linter": {
149+
"rules": {
150+
"correctness": {
151+
"noUnusedVariables": "off"
152+
}
153+
}
154+
}
155+
},
123156
{
124157
"includes": ["**/*.{js,jsx,ts,tsx}"],
125158
"javascript": {

bun.lock

Lines changed: 236 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api-reference.md

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,62 +27,62 @@ import { VersionCheck } from 'react-native-nitro-version-check'
2727
| Method | Returns | Description |
2828
|--------|---------|-------------|
2929
| `getCountry()` | `string` | Device's 2-letter ISO country code (sync) |
30-
| `getStoreUrl()` | `Promise<string>` | App Store / Play Store URL |
31-
| `getLatestVersion()` | `Promise<string>` | Latest version available in the store |
32-
| `needsUpdate()` | `Promise<boolean>` | Whether an update is available |
30+
| `getStoreUrl(options?)` | `Promise<string>` | App Store / Play Store URL with optional country code |
31+
| `getLatestVersion(options?)` | `Promise<string>` | Latest version available in the store with optional country code |
32+
| `needsUpdate(options?)` | `Promise<boolean>` | Whether an update is available with optional level filtering |
3333

34-
## Standalone Exports
35-
36-
All methods are also available as individual named exports:
37-
38-
```ts
39-
import {
40-
getCountry,
41-
getStoreUrl,
42-
getLatestVersion,
43-
needsUpdate,
44-
compareVersions,
45-
} from 'react-native-nitro-version-check'
46-
```
47-
48-
### `getCountry()`
34+
### `VersionCheck.getCountry()`
4935

5036
Returns the device's current 2-letter ISO country code. This is a **synchronous** call.
5137

5238
```ts
53-
const country = getCountry() // "US"
39+
const country = VersionCheck.getCountry() // "US"
5440
```
5541

56-
### `getStoreUrl()`
42+
### `VersionCheck.getStoreUrl(options?)`
5743

5844
Returns the store URL for this app. Automatically resolves to the App Store on iOS and Play Store on Android.
5945

6046
```ts
61-
const url = await getStoreUrl()
47+
const url = await VersionCheck.getStoreUrl()
48+
const urlUS = await VersionCheck.getStoreUrl({ countryCode: 'US' })
6249
Linking.openURL(url)
6350
```
6451

65-
### `getLatestVersion()`
52+
#### Options
53+
54+
| Option | Type | Default | Description |
55+
|--------|------|---------|-------------|
56+
| `countryCode` | `string` | device country | 2-letter ISO country code (iOS only, ignored on Android) |
57+
58+
### `VersionCheck.getLatestVersion(options?)`
6659

6760
Fetches the latest version of this app available in the store. Queries the iTunes API on iOS and the Play Store on Android.
6861

6962
```ts
70-
const latest = await getLatestVersion() // "1.3.0"
63+
const latest = await VersionCheck.getLatestVersion() // "1.3.0"
64+
const latestUS = await VersionCheck.getLatestVersion({ countryCode: 'US' })
7165
```
7266

73-
### `needsUpdate(options?)`
67+
#### Options
68+
69+
| Option | Type | Default | Description |
70+
|--------|------|---------|-------------|
71+
| `countryCode` | `string` | device country | 2-letter ISO country code (iOS only, ignored on Android) |
72+
73+
### `VersionCheck.needsUpdate(options?)`
7474

7575
Checks whether an app update is available using semantic version comparison.
7676

7777
```ts
7878
// Any version increase
79-
if (await needsUpdate()) {
80-
const url = await getStoreUrl()
79+
if (await VersionCheck.needsUpdate()) {
80+
const url = await VersionCheck.getStoreUrl()
8181
Linking.openURL(url)
8282
}
8383

8484
// Only prompt for major updates (1.x → 2.x)
85-
if (await needsUpdate({ level: 'major' })) {
85+
if (await VersionCheck.needsUpdate({ level: 'major' })) {
8686
// ...
8787
}
8888
```
@@ -97,16 +97,14 @@ if (await needsUpdate({ level: 'major' })) {
9797
- `"minor"` — returns `true` for major or minor bumps
9898
- `"patch"` — returns `true` for any version increase (default)
9999

100-
### `compareVersions(v1, v2)`
100+
### `VersionCheck.compareVersions(v1, v2)`
101101

102-
Compare two semver strings. Returns `-1`, `0`, or `1`.
102+
Compare two semantic version strings. Returns `-1` (first is older), `0` (equal), or `1` (first is newer).
103103

104104
```ts
105-
import { compareVersions } from 'react-native-nitro-version-check'
106-
107-
compareVersions('1.0.0', '1.0.1') // -1
108-
compareVersions('2.0.0', '2.0.0') // 0
109-
compareVersions('3.0.0', '2.9.9') // 1
105+
VersionCheck.compareVersions('1.0.0', '1.0.1') // -1
106+
VersionCheck.compareVersions('2.0.0', '2.0.0') // 0
107+
VersionCheck.compareVersions('3.0.0', '2.9.9') // 1
110108
```
111109

112110
## Types

docs/docs/getting-started.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ Benchmarked against [`react-native-version-check`](https://github.com/kimxogus/r
3434
First, [install the package](/docs/installation).
3535

3636
```ts
37-
import {
38-
VersionCheck,
39-
getCountry,
40-
getStoreUrl,
41-
getLatestVersion,
42-
needsUpdate,
43-
} from 'react-native-nitro-version-check'
44-
45-
// Sync properties — no await needed
37+
import { VersionCheck } from 'react-native-nitro-version-check'
38+
39+
// Direct access
4640
console.log(VersionCheck.version) // "1.2.0"
4741
console.log(VersionCheck.buildNumber) // "42"
4842
console.log(VersionCheck.packageName) // "com.example.app"
4943
console.log(VersionCheck.installSource) // "appstore" | "testflight" | "playstore" | undefined
50-
console.log(getCountry()) // "US"
44+
console.log(VersionCheck.getCountry()) // "US"
45+
46+
// Or destructure properties
47+
const { version, buildNumber, packageName, installSource } = VersionCheck
5148

5249
// Async operations
53-
const url = await getStoreUrl() // App Store / Play Store URL
54-
const latest = await getLatestVersion() // "1.3.0"
50+
const url = await VersionCheck.getStoreUrl() // App Store / Play Store URL
51+
const latest = await VersionCheck.getLatestVersion() // "1.3.0" (uses device country)
52+
53+
// Specify a different region for version lookup (iOS only)
54+
const latestUS = await VersionCheck.getLatestVersion({ countryCode: 'US' })
5555

5656
// Check for updates
57-
if (await needsUpdate()) {
58-
Linking.openURL(await getStoreUrl())
57+
if (await VersionCheck.needsUpdate()) {
58+
Linking.openURL(await VersionCheck.getStoreUrl())
5959
}
6060
```
6161

docs/docs/migration-guide.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ const update = await VersionCheck.needUpdate()
6161
// diff-remove
6262
if (update.isNeeded) { ... }
6363
// diff-add
64-
if (await needsUpdate()) { ... }
64+
if (await VersionCheck.needsUpdate()) { ... }
6565

6666
// Granular update level (new!)
6767
// diff-add
68-
if (await needsUpdate({ level: 'major' })) { ... }
68+
if (await VersionCheck.needsUpdate({ level: 'major' })) { ... }
6969
```
7070

7171
### Country code
@@ -74,7 +74,7 @@ if (await needsUpdate({ level: 'major' })) { ... }
7474
// diff-remove
7575
const country = await VersionCheck.getCountry()
7676
// diff-add
77-
const country = getCountry() // sync!
77+
const country = VersionCheck.getCountry() // sync!
7878
```
7979

8080
## 4. New features
@@ -85,6 +85,7 @@ These are new and have no equivalent in the old library:
8585
|---------|-----|
8686
| Install source detection | `VersionCheck.installSource` |
8787
| Granular update levels | `needsUpdate({ level: 'major' })` |
88+
| Region-specific version lookups | `getLatestVersion({ countryCode: 'US' })` |
8889
| Version comparison utility | `compareVersions(v1, v2)` |
8990

9091
## 5. Rebuild

0 commit comments

Comments
 (0)