New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

luxon-parser

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luxon-parser - npm Package Compare versions

Comparing version 0.9.4 to 1.0.0

dist/index.cjs

2

LICENSE.md
ISC License (ISC)
Copyright 2021 Ken Snyder
Copyright 2021-2024 Ken Snyder

@@ -5,0 +5,0 @@ Permission to use, copy, modify, and/or distribute this software for any purpose

{
"name": "luxon-parser",
"version": "0.9.4",
"description": "Add DateTime.fromHuman() and DateTime.fromAny() functions to Luxon that can parse a wide range of date formats including human-input dates",
"keywords": [
"luxon",
"date",
"datetime",
"parse",
"parser",
"date parser",
"parse date",
"human"
],
"main": "index.js",
"scripts": {
"test": "sh ./test/run-jest.sh",
"watch": "sh ./test/run-jest.sh --watch",
"coverage": "sh ./test/run-jest.sh --coverage"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kensnyder/luxon-parser.git"
},
"author": {
"name": "Ken Snyder",
"email": "kendsnyder@gmail.com"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/kensnyder/luxon-parser/issues"
},
"homepage": "https://github.com/kensnyder/luxon-parser#readme",
"dependencies": {
"any-date-parser": "1.5.3"
},
"peerDependencies": {
"luxon": ">=1.28.0"
},
"devDependencies": {
"eslint": "8.32.0",
"jest": "29.3.1",
"prettier": "2.8.3"
}
"name": "luxon-parser",
"version": "1.0.0",
"description": "Add DateTime.fromHuman() and DateTime.fromAny() functions to Luxon that can parse a wide range of date formats including human-input dates",
"keywords": [
"luxon",
"date",
"datetime",
"parse",
"parser",
"date parser",
"parse date",
"human"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist",
"README.md",
"LICENSE.md"
],
"scripts": {
"test": "./scripts/test.sh run",
"test-watch": "./scripts/test.sh",
"build": "npm run build:clean && npm run build:dts && npm run build:esm && npm run build:cjs",
"build:clean": "rimraf dist/ && mkdir dist",
"build:dts": "yes | npx dts-bundle-generator -o dist/index.d.ts src/luxon-parser.ts",
"build:esm": "yes | npx esbuild src/luxon-parser.ts --bundle --external:any-date-parser --external:luxon --platform=node --format=esm --outfile=dist/index.mjs",
"build:cjs": "yes | npx esbuild src/luxon-parser.ts --bundle --external:any-date-parser --external:luxon --platform=node --format=cjs --outfile=dist/index.cjs",
"coverage": "./scripts/test.sh run --coverage",
"view-coverage": "open ./coverage/lcov-report/index.html"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kensnyder/luxon-parser.git"
},
"author": {
"name": "Ken Snyder",
"email": "kendsnyder@gmail.com"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/kensnyder/luxon-parser/issues"
},
"homepage": "https://github.com/kensnyder/luxon-parser#readme",
"dependencies": {
"any-date-parser": "2.0.0"
},
"peerDependencies": {
"luxon": ">=1.28.0"
},
"devDependencies": {
"@types/luxon": "^3.4.2",
"@types/node": "22.9.0",
"@vitest/coverage-v8": "2.1.4",
"dayjs": "1.11.13",
"eslint": "8.16.0",
"prettier": "3.3.3",
"prettier-plugin-organize-imports": "4.1.0",
"rimraf": "6.0.1",
"typescript": "5.6.3",
"vitest": "2.1.4"
}
}
# luxon-parser
[![NPM Link](https://img.shields.io/npm/v/luxon-parser?v=0.9.4)](https://npmjs.com/package/luxon-parser)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/kensnyder/luxon-parser?branch=master&svg=true&v=0.9.4)](https://ci.appveyor.com/project/kensnyder/luxon-parser/branch/master)
[![Code Coverage](https://codecov.io/gh/kensnyder/luxon-parser/branch/master/graph/badge.svg?v=0.9.4)](https://codecov.io/gh/kensnyder/luxon-parser)
[![ISC License](https://img.shields.io/npm/l/luxon-parser.svg?v=0.9.4)](https://opensource.org/licenses/ISC)
[![NPM Link](https://img.shields.io/npm/v/luxon-parser?v=1.0.0)](https://npmjs.com/package/luxon-parser)
[![Build Status](https://github.com/kensnyder/luxon-parser/actions/workflows/workflow.yml/badge.svg?v=2.0.0-rc.1)](https://github.com/kensnyder/luxon-parser/actions)
[![Code Coverage](https://codecov.io/gh/kensnyder/luxon-parser/branch/main/graph/badge.svg?v=2.0.0-rc.1)](https://codecov.io/gh/kensnyder/luxon-parser)
[![Language: TypeScript](https://badgen.net/static/language/TS?v=1.0.0)](https://github.com/search?q=repo:kensnyder/luxon-parser++language:TypeScript&type=code)
[![ISC License](https://badgen.net/github/license/kensnyder/luxon-parser?v=1.0.0)](https://opensource.org/licenses/ISC)
A comprehensive and extensible date parsing plugin for
[Luxon](https://moment.github.io/luxon/docs/). It allows passing a wide variety
of date formats to new functions `DateTime.fromHuman()` and
`DateTime.fromAny()`. Most locales are supported automatically.
The most comprehensive and accurate date parser for Node and browsers. It uses
`Intl` to provide parsing support for all installed locales. This plugin
connects the capabilities of
[any-date-parser](https://npmjs.com/package/dany-date-parser) to
[luxon](https://moment.github.io/luxon/docs/).
It uses [any-date-parser](https://npmjs.com/package/any-date-parser) for parsing
date strings.
It allows parsing every imaginable date format to a Luxon `DateTime` object.
Most locales are supported automatically.

@@ -21,4 +23,3 @@ ## Table of Contents

- [Usage](#usage)
- [Recognized Formats](#recognized-formats)
- [Adding Custom Formats](#adding-custom-formats)
- [Recognized Formats](https://www.npmjs.com/package/any-date-parser#exhaustive-list-of-date-formats)
- [Locale Support](#locale-support)

@@ -45,82 +46,33 @@ - [Sister Packages](#sister-packages)

```js
const { DateTime } = require('luxon');
require('luxon-parser');
Option 1: import functions (recommended)
```ts
import { dateTimeFromHuman, dateTimeFromAny } from 'luxon-parser';
const date1 = dateTimeFromHuman('March 5th, 2016 at 7:05pm');
const date2 = dateTimeFromHuman('9 days ago');
const date3 = dateTimeFromHuman('2016-03-05 23:59:59 CST');
const date4 = dateTimeFromAny(new Date());
```
Option 2: use new functions on `DateTime` object
```ts
import { DateTime } from 'luxon';
import 'luxon-parser';
const date1 = DateTime.fromHuman('March 5th, 2016 at 7:05pm');
const date2 = DateTime.fromHuman('9 days ago');
const date3 = DateTime.fromHuman('2016-03-05 23:59:59 CST');
const date4 = DateTime.fromAny(new Date());
```
### DateTime.fromHuman(string, options)
### dateTimeFromHuman(string, options) : DateTime
Create a DateTime from any given String. Equivalent to auto choosing the right
from\*() function:
Create a `DateTime` from any given string.
- DateTime.fromFormat()
- DateTime.fromHTTP()
- DateTime.fromISO()
- DateTime.fromRFC2822()
- DateTime.fromSQL()
- DateTime.fromString()
### dateTimeFromAny(any, options) : DateTime
### DateTime.fromAny(any, options)
Create a `DateTime` from string, milliseconds, object, `DateTime`, or `Date`.
Create a DateTime from any given type. Equivalent to auto choosing the right
from\*() function:
- DateTime.now()
- DateTime.fromFormat()
- DateTime.fromHTTP()
- DateTime.fromISO()
- DateTime.fromJSDate()
- DateTime.fromMillis()
- DateTime.fromObject()
- DateTime.fromRFC2822()
- DateTime.fromSQL()
- DateTime.fromString()
## Recognized Formats
- 24 hour time
- 12 hour time
- timezone offsets
- timezone abbreviations
- year month day
- year monthname day
- month day year
- monthname day year
- day month year
- day monthname year
- +/-/ago periods
- now/today/yesterday/tomorrow
- Twitter
`luxon-parser` relies on
[any-date-parser](https://www.npmjs.com/package/any-date-parser) which supports
even more formats. See the
[exhaustive list](https://www.npmjs.com/package/any-date-parser#exhaustive-list-of-date-formats).
## Adding Custom Formats
See
[any-date-parser's instructions](https://www.npmjs.com/package/any-date-parser#adding-custom-formats).
Example:
```js
const parser = require('luxon-parser');
parser.addFormat(
new parser.Format({
matcher: /^Q([1-4]) (\d{4})$/,
handler: function ([, quarter, year]) {
const monthByQuarter = { 1: 1, 2: 4, 3: 7, 4: 10 };
const month = monthByQuarter[quarter];
return { year, month };
},
})
);
```
## Locale Support

@@ -130,4 +82,7 @@

```js
const date = DateTime.fromAny('15 septembre 2015', { locale: 'fr' });
```ts
import { dateTimeFromHuman, dateTimeFromAny } from 'luxon-parser';
const date1 = dateTimeFromHuman('15 septembre 2015', { locale: 'fr' });
const date2 = dateTimeFromAny('15 septembre 2015', { locale: 'fr' });
```

@@ -137,7 +92,9 @@

[Luxon docs on locales](https://moment.github.io/luxon/docs/manual/intl.html)
and the example non-English dates that
[any-date-parser](https://www.npmjs.com/package/any-date-parser#locale-support)
can parse.
## Sister Packages
- Standalone Parser:
[any-date-parser](http://npmjs.com/packages/any-date-parser)
- Standalone Parser: [any-date-parser](http://npmjs.com/package/any-date-parser)
- DayJS Parser: [dayjs-parser](http://npmjs.com/package/dayjs-parser)

@@ -154,3 +111,4 @@ - Moment Parser: [moment-parseplus](http://npmjs.com/package/moment-parseplus)

Unit tests require a global install of `full-icu` and `luxon`. The test runner
will attempt to install these if absent.
will attempt to install these if absent. It tests compatibility with Luxon
version 1.x, 2.x and 3.x

@@ -157,0 +115,0 @@ ## Contributing

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc