Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
robario committed Jun 29, 2021
1 parent 10d5897 commit 1b5ef31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/helpers/app-store.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { IAppleStoreInfos, IAppleStoreResult } from '../interfaces'
import { ResponseHelper } from './'

export class AppStoreHelper {
static getAppInfos(bundleID, countryCode?) {
static getAppInfos(bundleID: string, countryCode?: string): Promise<IAppleStoreResult | null> {
return AppStoreHelper._getLookupFile(bundleID, countryCode)
.then(ResponseHelper.handleErrorStatus)
.then(response => response.json())
.then(AppStoreHelper._parseResource)
}

private static _getLookupFile(bundleID, countryCode?) {
private static _getLookupFile(bundleID: string, countryCode?: string) {
return fetch(AppStoreHelper._getItunesLookupUrl(bundleID, countryCode))
}

private static _parseResource(resource: IAppleStoreInfos): IAppleStoreResult {
private static _parseResource(resource: IAppleStoreInfos): IAppleStoreResult | null {
if (resource.resultCount === 0) return null
return resource.results[0]
}

private static _getItunesLookupUrl(bundleId, countryCode?): string {
private static _getItunesLookupUrl(bundleId: string, countryCode?: string): string {
let url = `${AppStoreConstants.ITUNES_BASE_URL}/lookup?bundleId=${bundleId}`
if (countryCode) {
url += `&hl=${countryCode}`
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/google-play.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { IGoogleStoreResult } from '../interfaces'
import { ResponseHelper } from './'

export class GooglePlayHelper {
static getAppInfos(bundleId, countryCode?) {
static getAppInfos(bundleId: string, countryCode?: string): Promise<IGoogleStoreResult> {
return GooglePlayHelper._getAppPage(bundleId, countryCode)
.then(ResponseHelper.handleErrorStatus)
.then(response => response.text())
.then(GooglePlayHelper._parseResource)
}

private static _getAppPage(bundleId, countryCode?) {
private static _getAppPage(bundleId: string, countryCode?: string): Promise<Response> {
return fetch(GooglePlayHelper._getStoreAppUrl(bundleId, countryCode))
}

private static _parseResource(page): IGoogleStoreResult {
private static _parseResource(page: string): IGoogleStoreResult {
const infos: any = {}
Object.keys(GooglePlayConstants.REGEX).map(key => {
// we force a new regex creation to allow multiple calls on the same regex
const regEx = new RegExp(GooglePlayConstants.REGEX[key].source, 'gm').exec(page)
const regEx = new RegExp(GooglePlayConstants.REGEX[key as keyof typeof GooglePlayConstants.REGEX].source, 'gm').exec(page)
infos[key.toLowerCase()] = regEx ? regEx[1] : null
})
return infos
}

private static _getStoreAppUrl(bundleId, countryCode?): string {
private static _getStoreAppUrl(bundleId: string, countryCode?: string): string {
let url = `${GooglePlayConstants.PLAY_STORE_ROOT_WEB}?id=${bundleId}`
if (countryCode) {
url += `&hl=${countryCode}`
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/locales.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class LocalesHelper {
static currentLang = 'en'

private static _defaultLang = 'en'
private static _translations = {
private static _translations: { [langKey: string]: any; } = {
en: require('../i18n/en.json'),
fr: require('../i18n/fr.json'),
es: require('../i18n/es.json')
Expand Down

0 comments on commit 1b5ef31

Please sign in to comment.