All files / core/systems/plusCode system.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8

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 43 44 45 46                  14x       2058x     14x 7017x       1001x 1001x                       14x               1x      
import { Option, pipe } from 'effect'
 
import { cellBox } from '../cell'
import { compact, makeParser } from '../parser'
import { singleReading } from '../reading'
import type { Formatter, Grid, Parser } from '../types'
import { plusCodeCellOutline, plusCodeGrid } from './grid'
import { fromPlusCode, isFullPlusCode, toPlusCode } from './plusCode'
 
export const formatter: Formatter = {
  id: 'PlusCode',
  label: 'Plus Code',
  maybeGridId: Option.some('PlusCode'),
  format: point => singleReading(toPlusCode(point), 'about 14 m'),
}
 
export const parser: Parser = makeParser('Plus Code', text =>
  pipe(
    compact(text),
    Option.liftPredicate(isFullPlusCode),
    Option.map(code => {
      const cell = fromPlusCode(code)
      return {
        kind: 'Plus Code',
        point: {
          lat: (cell.south + cell.north) / 2,
          lon: (cell.west + cell.east) / 2,
        },
        maybeBounds: Option.some(cellBox(cell)),
      }
    }),
  ),
)
 
export const grid: Grid = {
  id: 'PlusCode',
  label: 'Plus Codes',
  description: 'Plus Code cells, finer as you zoom in',
  colors: { onDark: [190, 140, 255, 140], onLight: [120, 60, 200, 160] },
  isEnabledByDefault: false,
  build: plusCodeGrid,
  maybeCueOutline: Option.some(point =>
    Option.some(plusCodeCellOutline(toPlusCode(point))),
  ),
}