Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type annotations for strict #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/helpers/response.helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference lib="dom" />
export class ResponseHelper {
static handleErrorStatus(response: Response): Response {
if (response.status >= 400) {
Expand Down