Socket
Book a DemoInstallSign in
Socket

luxon-jsonata

Package Overview
Dependencies
Maintainers
11
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luxon-jsonata

Simple Luxon object bindings for JSONata

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
72
-43.75%
Maintainers
11
Weekly downloads
 
Created
Source

luxon-jsonata

JSONata bindings for the Luxon date library.

NPM version NPM downloads

JSONata is a great tool for transforming JSON data, but the date and time manipulation functions that it provides are lacklustre. This package adds a simple binding for Luxon's DateTime, Duration and Interval objects so they can be used directly in JSONata expressions.

Getting Started

import addLuxon from "luxon-jsonata";
import jsonata from "jsonata";

const expr = jsonata(
  '$Duration.fromISO("P2M").plus({"months":3, "days":10}).toISO()'
);

addLuxon(expr);

console.log(expr.evaluate({}));

// Result is "P5M10D"

Caveats

Not all methods are going to work. In particular, methods that themselves take functions, or require a standard Date object are a bit awkward to use in JSONata. Perhaps in future we can dynamically remove these from the bound objects.

For Luxon member functions that themselves take functions, like Duration.mapUnits, you can assign a Javascript function to the expression that takes the object and performs the operation you need:

const double = (x: Duration) => x.mapUnits((u) => u * 2);

const expr = jsonata(
  "$double($Duration.fromObject({ 'hours': 1, 'minutes': 30 })).toObject()"
);

addLuxon(expr);
expr.assign("double", double);

console.log(expr.evaluate({}));

// Result is { hours: 2, minutes: 60 }

Supporters

This package is supported by SaaSquatch.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

luxon

FAQs

Package last updated on 20 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.