diff options
Diffstat (limited to 'app/utils')
-rw-r--r-- | app/utils/delay.ts | 3 | ||||
-rw-r--r-- | app/utils/ignore-warnings.ts | 2 | ||||
-rw-r--r-- | app/utils/keychain.ts | 10 | ||||
-rw-r--r-- | app/utils/storage/index.ts | 2 | ||||
-rw-r--r-- | app/utils/storage/storage.test.ts | 38 | ||||
-rw-r--r-- | app/utils/storage/storage.ts | 2 | ||||
-rw-r--r-- | app/utils/validate.ts | 16 |
7 files changed, 45 insertions, 28 deletions
diff --git a/app/utils/delay.ts b/app/utils/delay.ts index 6a2ef8d..66c404f 100644 --- a/app/utils/delay.ts +++ b/app/utils/delay.ts @@ -3,4 +3,5 @@ * * @param ms The number of milliseconds to wait. */ -export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) +export const delay = (ms: number) => + new Promise((resolve) => setTimeout(resolve, ms)) diff --git a/app/utils/ignore-warnings.ts b/app/utils/ignore-warnings.ts index 18802fe..3d02efd 100644 --- a/app/utils/ignore-warnings.ts +++ b/app/utils/ignore-warnings.ts @@ -2,7 +2,7 @@ * Ignore some yellowbox warnings. Some of these are for deprecated functions * that we haven't gotten around to replacing yet. */ -import { LogBox } from "react-native" +import { LogBox } from 'react-native' // prettier-ignore LogBox.ignoreLogs([ diff --git a/app/utils/keychain.ts b/app/utils/keychain.ts index 34774bb..86fae6f 100644 --- a/app/utils/keychain.ts +++ b/app/utils/keychain.ts @@ -1,4 +1,4 @@ -import * as ReactNativeKeychain from "react-native-keychain" +import * as ReactNativeKeychain from 'react-native-keychain' /** * Saves some credentials securely. @@ -7,7 +7,11 @@ import * as ReactNativeKeychain from "react-native-keychain" * @param password The password * @param server The server these creds are for. */ -export async function save(username: string, password: string, server?: string) { +export async function save( + username: string, + password: string, + server?: string, +) { if (server) { await ReactNativeKeychain.setInternetCredentials(server, username, password) return true @@ -31,7 +35,7 @@ export async function load(server?: string) { } } else { const creds = await ReactNativeKeychain.getGenericPassword() - if (typeof creds === "object") { + if (typeof creds === 'object') { return { username: creds.username, password: creds.password, diff --git a/app/utils/storage/index.ts b/app/utils/storage/index.ts index ff88148..69b61ec 100644 --- a/app/utils/storage/index.ts +++ b/app/utils/storage/index.ts @@ -1 +1 @@ -export * from "./storage" +export * from './storage' diff --git a/app/utils/storage/storage.test.ts b/app/utils/storage/storage.test.ts index d5cd977..b8cf732 100644 --- a/app/utils/storage/storage.test.ts +++ b/app/utils/storage/storage.test.ts @@ -1,39 +1,43 @@ -import AsyncStorage from "@react-native-async-storage/async-storage" -import { load, loadString, save, saveString, clear, remove } from "./storage" +import AsyncStorage from '@react-native-async-storage/async-storage' +import { load, loadString, save, saveString, clear, remove } from './storage' // fixtures const VALUE_OBJECT = { x: 1 } const VALUE_STRING = JSON.stringify(VALUE_OBJECT) -beforeEach(() => (AsyncStorage.getItem as jest.Mock).mockReturnValue(Promise.resolve(VALUE_STRING))) +beforeEach(() => + (AsyncStorage.getItem as jest.Mock).mockReturnValue( + Promise.resolve(VALUE_STRING), + ), +) afterEach(() => jest.clearAllMocks()) -test("load", async () => { - const value = await load("something") +test('load', async () => { + const value = await load('something') expect(value).toEqual(JSON.parse(VALUE_STRING)) }) -test("loadString", async () => { - const value = await loadString("something") +test('loadString', async () => { + const value = await loadString('something') expect(value).toEqual(VALUE_STRING) }) -test("save", async () => { - await save("something", VALUE_OBJECT) - expect(AsyncStorage.setItem).toHaveBeenCalledWith("something", VALUE_STRING) +test('save', async () => { + await save('something', VALUE_OBJECT) + expect(AsyncStorage.setItem).toHaveBeenCalledWith('something', VALUE_STRING) }) -test("saveString", async () => { - await saveString("something", VALUE_STRING) - expect(AsyncStorage.setItem).toHaveBeenCalledWith("something", VALUE_STRING) +test('saveString', async () => { + await saveString('something', VALUE_STRING) + expect(AsyncStorage.setItem).toHaveBeenCalledWith('something', VALUE_STRING) }) -test("remove", async () => { - await remove("something") - expect(AsyncStorage.removeItem).toHaveBeenCalledWith("something") +test('remove', async () => { + await remove('something') + expect(AsyncStorage.removeItem).toHaveBeenCalledWith('something') }) -test("clear", async () => { +test('clear', async () => { await clear() expect(AsyncStorage.clear).toHaveBeenCalledWith() }) diff --git a/app/utils/storage/storage.ts b/app/utils/storage/storage.ts index 05c098a..659e738 100644 --- a/app/utils/storage/storage.ts +++ b/app/utils/storage/storage.ts @@ -1,4 +1,4 @@ -import AsyncStorage from "@react-native-async-storage/async-storage" +import AsyncStorage from '@react-native-async-storage/async-storage' /** * Loads a string from storage. diff --git a/app/utils/validate.ts b/app/utils/validate.ts index 91db9b6..862b2d0 100644 --- a/app/utils/validate.ts +++ b/app/utils/validate.ts @@ -1,4 +1,4 @@ -const ValidateJS = require("validate.js") +const ValidateJS = require('validate.js') // HACK(steve): wierd typescript situation because of strange typings const Validate: any = ValidateJS.default ? ValidateJS.default : ValidateJS @@ -6,7 +6,12 @@ const Validate: any = ValidateJS.default ? ValidateJS.default : ValidateJS /** * Validates that 1 attribute doesn't appear in another's attributes content. */ -Validate.validators.excludes = function custom(value, options, key, attributes) { +Validate.validators.excludes = function custom( + value, + options, + key, + attributes, +) { const list = attributes[options.attribute] || [] if (value && list.includes(value)) { return options.message || `${value} is in the list` @@ -69,8 +74,11 @@ export interface ValidationErrors { * @param rules The rules to apply. * @param data The object to validate. */ -export function validate(rules: ValidationRules, data: Record<string, unknown>): ValidationErrors { - if (typeof data !== "object") { +export function validate( + rules: ValidationRules, + data: Record<string, unknown>, +): ValidationErrors { + if (typeof data !== 'object') { return {} as ValidationErrors } return Validate(data, rules, { fullMessages: false }) || {} |