Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('happy with curry', () => {
const fn = defaultTo('foo')
const x = fn(undefined, 'bar', null); // $ExpectType string
x // $ExpectType string
const y = fn(undefined); // $ExpectType string
y // $ExpectType string
});
it('with two types', () => {
const x = defaultTo('foo',undefined, 1, null, 2, 'bar'); // $ExpectType string | number
x // $ExpectType string | number
});
});
it('with one type', () => {
const x = defaultTo('foo','bar'); // $ExpectType string
x // $ExpectType string
});
it('with two types', () => {
it('fallback', () => {
const x = defaultTo('foo',undefined); // $ExpectType "foo"
x // $ExpectType "foo"
const y = defaultTo('foo','bar'); // $ExpectType "foo" | "bar"
y // $ExpectType "foo" | "bar"
});
it('with one type', () => {
it('with two types', () => {
const x = defaultTo('foo',1); // $ExpectType string | number
x // $ExpectType string | number
});
});
it('happy', () => {
const x = defaultTo('foo',undefined, 'bar'); // $ExpectType string
x // $ExpectType string
});
it('fallback', () => {
const x = defaultTo('foo',undefined); // $ExpectType "foo"
x // $ExpectType "foo"
const y = defaultTo('foo','bar'); // $ExpectType "foo" | "bar"
y // $ExpectType "foo" | "bar"
});
it('with one type', () => {
export function getTimeByField(field: string = ''): (input: any) => number {
return R.ifElse(
R.has(field),
R.pipe(R.path(field), (input: any) => new Date(input).getTime()),
() => Date.now()
);
}
export const getErrorMessage: (error: i.ErrorLike) => string = R.pipe(
R.ifElse(
R.has('message'),
R.path('message'),
R.path('msg'),
),
R.defaultTo('Unknown Error'),
);
export const getErrorMessages: (errors: i.ErrorLike[]) => string = R.pipe(
// @ts-ignore
R.map(getErrorMessage),
R.join(', '),
);
export const getErrorType = R.pathOr('', ['error', 'type']);
export const getStatusCode: (error: i.ErrorLike) => number = R.pipe(
R.ifElse(
R.has('statusCode'),
R.path('statusCode'),
R.path('status')
),
export const getErrorMessages: (errors: i.ErrorLike[]) => string = R.pipe(
// @ts-ignore
R.map(getErrorMessage),
R.join(', '),
);
export const getErrorType = R.pathOr('', ['error', 'type']);
export const getStatusCode: (error: i.ErrorLike) => number = R.pipe(
R.ifElse(
R.has('statusCode'),
R.path('statusCode'),
R.path('status')
),
R.defaultTo(500)
);
type Shard = { primary: boolean, stage: string };
export function shardsPath(index: string): (stats: any) => Shard[] {
return R.pathOr([], [index, 'shards']);
}
export const verifyIndexShards: (shards: Shard[]) => boolean = R.pipe(
// @ts-ignore
R.filter((shard: Shard) => shard.primary),
R.all((shard: Shard) => shard.stage === 'DONE')
);
export const getRolloverFrequency = R.pathOr('monthly', ['indexSchema', 'rollover_frequency']);
const defaultErrorMsg = 'Unknown Error';
if (err && ts.isString(err)) {
return err;
}
const message: string = R.path(['message'], err) || R.pathOr(defaultErrorMsg, ['msg'], err);
const prefix = R.path(['dataPath'], err);
return `${prefix ? `${prefix} ` : ''}${message}`;
}
export const getErrorType = R.pathOr('', ['error', 'type']);
export const getStatusCode: (error: ErrorLike) => number = R.pipe(
R.ifElse(R.has('statusCode'), R.path(['statusCode']), R.path(['status'])),
R.defaultTo(500)
);
export type ErrorLike =
| {
message?: string;
msg?: string;
statusCode?: number;
status?: number;
}
| ajv.ErrorObject
| string;