@ldrick/trade-indicators
Version:
Trade Indicators
14 lines (13 loc) • 500 B
JavaScript
import { Big } from 'big.js';
import { either as E } from 'fp-ts';
import { NotPositiveIntegerError } from '../errors/NotPositiveIntegerError.js';
/**
* Safely convert `number` to `Big`.
* @internal
*/
export const toBig = (value) => E.tryCatch(() => new Big(value), (error) => E.toError(error));
/**
* Validate positive Integer.
* @internal
*/
export const validatePositiveInteger = (period) => period > 0 && Number.isInteger(period) ? E.right(period) : E.left(new NotPositiveIntegerError());