All files / utils position.ts

81.81% Statements 9/11
100% Branches 0/0
0% Functions 0/2
77.77% Lines 7/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42        94x 94x             94x           94x                 94x                 94x   94x      
/**
 * @module Utils
 */
 
import * as MC from "@lisn/globals/minification-constants";
import * as MH from "@lisn/globals/minification-helpers";
 
import { Position } from "@lisn/globals/types";
 
/**
 * @category Validation
 */
export const isValidPosition = (position: string): position is Position =>
  MH.includes(POSITIONS as readonly string[], position);
 
/**
 * @category Validation
 */
export const isValidTwoFoldPosition = (
  position: string,
): position is `${Position}-${Position}` =>
  position.match(TWO_FOLD_POSITION_REGEX) !== null;
 
/**
 * @ignore
 * @internal
 */
export const POSITIONS = [
  MC.S_TOP,
  MC.S_BOTTOM,
  MC.S_LEFT,
  MC.S_RIGHT,
] as const;
 
// --------------------
 
const POSITIONS_OPTIONS_STR = "(" + POSITIONS.join("|") + ")";
 
const TWO_FOLD_POSITION_REGEX = RegExp(
  `^${POSITIONS_OPTIONS_STR}-${POSITIONS_OPTIONS_STR}$`,
);