Skip to content

Commit

Permalink
fix: Formatting and test generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Leeds committed Feb 16, 2021
1 parent 7f16790 commit 8e429f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"arrowParens": "avoid",
"trailingComma": "all",
"singleQuote": true
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/jest": "^25.1.4",
"@types/yup": "^0.26.33",
"husky": "^4.2.3",
"prettier": "^2.2.1",
"tsdx": "^0.13.0",
"tslib": "^1.11.1",
"typescript": "^3.8.3",
Expand Down
8 changes: 5 additions & 3 deletions src/Trusted.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Schema } from 'yup';

export interface TrustedOptions {
namespace?: string;
}

export interface TrustedAccessorOptions<T> {
key: string;
defaultValue?: T;
yupSchema?: any;
yupSchema?: Schema<T>;
validate?: (value: T) => boolean;
skipRegistration?: boolean;
unmarshal?: (localValue: string) => T;
Expand Down Expand Up @@ -127,7 +129,7 @@ export class Trusted {
return defaultValue;
}
},
set: value => {
set: (value) => {
if (
validate &&
value !== undefined &&
Expand Down Expand Up @@ -281,7 +283,7 @@ export class Trusted {
date<T extends Date>(accessorOptions: TrustedAccessorOptions<T>) {
return this.accessor<T>({
...accessorOptions,
marshal: value => value.toISOString(),
marshal: (value) => value.toISOString(),
unmarshal: (localString: string) => new Date(localString) as T,
});
}
Expand Down
6 changes: 3 additions & 3 deletions test/Trusted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test('Trusted does nothing when setting an invalid value', () => {
});

test('Trusted string can set and get strings', () => {
const testString = new Trusted().string({
const testString = new Trusted().string<string>({
key: 'test',
defaultValue: 'hello world',
yupSchema: Yup.string().matches(/world/i),
Expand All @@ -107,7 +107,7 @@ test('Trusted string can set and get strings', () => {
});

test('Trusted boolean can set and get booleans', () => {
const testBoolean = new Trusted().boolean({
const testBoolean = new Trusted().boolean<boolean>({
key: 'test',
defaultValue: true,
yupSchema: Yup.boolean().oneOf([true]),
Expand All @@ -122,7 +122,7 @@ test('Trusted boolean can set and get booleans', () => {
});

test('Trusted number can set and get numbers', () => {
const testNumber = new Trusted().number({
const testNumber = new Trusted().number<number>({
key: 'test',
defaultValue: 42,
yupSchema: Yup.number().oneOf([7, 42]),
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4591,6 +4591,11 @@ prettier@^1.19.1:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==

pretty-format@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
Expand Down

0 comments on commit 8e429f1

Please sign in to comment.