@codesign-eu/utils
v1.0.29
Published
Utility helpers for spatial, date/time, and Maidenhead grid operations used by Codesign applications.
Downloads
572
Maintainers
Readme
@codesign-eu/utils
Shared TypeScript utilities for Codesign applications.
The library currently focuses on three areas:
- date and time helpers
- spatial / coordinate formatting helpers
- Maidenhead (QTH) grid conversion helpers
Installation
npm install @codesign-eu/utilsUsage
import { dateTimeService, spatialService, GridLocationService, type LatLngBoundsLike } from '@codesign-eu/utils'
const day = dateTimeService.formatDay(new Date('2026-04-28T12:30:00Z'))
const parsed = dateTimeService.parseDate('20260428')
const pointLabel = spatialService.coordinatesGeoJsonToString({
type: 'Point',
coordinates: [21.0122, 52.2297],
})
const locator = GridLocationService.latLngToGrid(52.2297, 21.0122, 6)
const center = GridLocationService.gridToLatLng('KO02mf')
const bounds: LatLngBoundsLike = {
getNorth: () => 54,
getEast: () => 22,
getSouth: () => 52,
getWest: () => 20,
}
const viewportLocators = GridLocationService.locatorFeaturesForBounds(bounds, 4)
const boundsQuery = spatialService.leafletBoundsToString(bounds)
console.log(day, parsed, pointLabel, locator, center, viewportLocators[0]?.reference, boundsQuery)Public API
dateTimeService
Helpers for formatting and comparing dates:
formatDay(date)timestampToString(date, showSeconds?)parseDate('YYYYMMDD')daysBetweenToday(date)timeAgo(date)dateIsFromTheFuture(date)
spatialService
Helpers for coordinate formatting and nested coordinate structures:
LatLngBoundsLikeswapLatLng(coordinates)leafletBoundsToString(boundsLike)getPointFromPolygon(coordinates)coordinatesGeoJsonToString(point)coordinatesGeoJsonToDegreesString(point)
LatLngBoundsLike is the exported lightweight bounds contract for leafletBoundsToString.
leafletBoundsToString stays compatible with Leaflet bounds objects, but the library does not require Leaflet as a consumer dependency.
GridLocationService
Helpers for Maidenhead locator work:
latLngToGrid(lat, lng, precision?)gridToLatLng(locator)gridToPolygon(locator)locatorGridsForGeoJSON(feature, precision)locatorGridsForBounds(bounds, precision)locatorFeaturesForBounds(bounds, precision)
Supported precisions today:
2468
Development
npm install
npm run checkUseful commands:
npm run test
npm run build
npm run typecheck
npm run lintRelease Helpers
npm run version:patch
npm run version:minor
npm run version:majorPublishing uses prepack, so the package is rebuilt before npm publish.
