@strong-roots-capital/is-tradingview-format
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

is-tradingview-format

Build status NPM Package Code Coverage Dependencies

Test to determine if session is denoted in valid Trading View format

Trading View format of timeframes is hereby defined as follows:

  • Minutes are expressible by an integer from 1 to 1440
  • Hours are expressible by an integer from 1 to 24, followed by a capital H
  • Days are expressible by an integer from 1 to 365, followed by a capital D
  • Weeks are expressible by an integer from 1 to 52, followed by a capital W
  • Months expressible by an integer from 1 to 12, followed by a capital M
  • Hours, Days, Weeks, Months may all have an implicit quantifier of 1, e.g. H is equivalent to 1H

Any other string is not a timeframe in Trading View format.

Install

npm install @strong-roots-capital/is-tradingview-format

Use

Binary validation

import isTradingviewFormat from '@strong-roots-capital/is-tradingview-format'

isTradingviewFormat('H')
//=> true

isTradingviewFormat('1H')
//=> true

isTradingviewFormat('25H')
//=> false

Specific validation

Functions are also provided for testing if a session is a timeframe expressed in minutes, in hours, in days, in weeks, or in months

import isTradingviewFormat, {
    isTradingviewFormatMonths,
    isTradingviewFormatWeeks,
    isTradingviewFormatDays,
    isTradingviewFormatHours,
    isTradingviewFormatMinutes
} from '@strong-roots-capital/is-tradingview-format'

isTradingviewFormatHours('H')
//=> true

isTradingviewFormatHours('10')
//=> false

isTradingviewFormatHours('1D')
//=> false

Input validation with ow

A convenience function is provided for validating input with ow

import ow from 'ow'
import { inTradingviewFormat } from '@strong-roots-capital/is-tradingview-format'

ow(session, ow.string.is(inTradingviewFormat))

If session is not in valid Trading View format, this line will throw an error with a message like the following

ArgumentError: (string) Expected session `not-a-real-timeframe` to be in Trading View format

Package Sidebar

Install

npm i @strong-roots-capital/is-tradingview-format

Weekly Downloads

12

Version

1.2.4

License

ISC

Unpacked Size

12.9 kB

Total Files

4

Last publish

Collaborators

  • amchelle
  • hamroctopus