Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Refactor to TypeScript, Improved Test Coverage, and Bug Fixes #323

Open
wants to merge 111 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
000f595
WIP - Phase 1 of converting to TypeScript is mostly complete
MichaelLeeHobbs Apr 23, 2023
4d1e56b
WIP - Phase 1 of converting to TypeScript is mostly complete
MichaelLeeHobbs Apr 23, 2023
5a69ad9
WIP - refactored compactField into CronFields. Clean up on other files
MichaelLeeHobbs Apr 23, 2023
078fe83
WIP: cleanup types
MichaelLeeHobbs Apr 23, 2023
36271a6
WIP: cleanup types
MichaelLeeHobbs Apr 23, 2023
036fca9
WIP: refactored findSchedule in to multiple smaller functions
MichaelLeeHobbs Apr 23, 2023
b9e6bac
WIP: refactored findSchedule in to multiple smaller functions
MichaelLeeHobbs Apr 23, 2023
a332968
WIP: refactored shiftTimezone on to CronDate
MichaelLeeHobbs Apr 24, 2023
6d8a85f
WIP: refactored file names. Testing install from github
MichaelLeeHobbs Apr 24, 2023
281efe9
added prepare script
MichaelLeeHobbs Apr 24, 2023
81a8800
updated library packaging
MichaelLeeHobbs Apr 24, 2023
14a40ef
updated the default export to match the current library
MichaelLeeHobbs Apr 24, 2023
d0cb09f
updated exports for compatible with CommonJS-style require
MichaelLeeHobbs Apr 24, 2023
391e9e7
attempt 2 at cjs combability
MichaelLeeHobbs Apr 24, 2023
805a27b
attempt 3 at cjs compatability
MichaelLeeHobbs Apr 24, 2023
0cc6b80
some clean up
MichaelLeeHobbs Apr 24, 2023
2795eed
wip - cleaner support for CJS and ESM
MichaelLeeHobbs Apr 24, 2023
730921a
wip - looks like we still need the index.cjs.js to support cjs even w…
MichaelLeeHobbs Apr 24, 2023
1feeabc
wip - added notes, and general cleanup
MichaelLeeHobbs Apr 24, 2023
2231615
wip - added note
MichaelLeeHobbs Apr 24, 2023
d16bc5d
wip - init jest setup/work
MichaelLeeHobbs Apr 24, 2023
6eea54b
WIP - testing precommit lint
MichaelLeeHobbs Apr 24, 2023
b6794a1
WIP - testing precommit lint
MichaelLeeHobbs Apr 24, 2023
1a90deb
wip - testing pre-commit hook
MichaelLeeHobbs Apr 24, 2023
2710da0
wip - formatted code
MichaelLeeHobbs Apr 24, 2023
7743b58
wip - refactoring test...
MichaelLeeHobbs Apr 25, 2023
184744a
wip - refactoring test...
MichaelLeeHobbs Apr 25, 2023
060bab9
wip - refactored CronParser stringify test
MichaelLeeHobbs Apr 25, 2023
d338492
wip - Test conversion complete. Overall coverage is at 91%. Lost lots…
MichaelLeeHobbs Apr 26, 2023
7ef341a
wip - types cleanup
MichaelLeeHobbs Apr 27, 2023
94a0add
wip - cleanup
MichaelLeeHobbs Apr 27, 2023
722df4b
wip - simplified code
MichaelLeeHobbs Apr 27, 2023
c12e6e4
wip - simplified code
MichaelLeeHobbs Apr 27, 2023
3184fdc
wip - fixes #153 and #299. Adds test for #156
MichaelLeeHobbs Apr 28, 2023
b073cfe
wip - Adds fix for #156 in the form of toString vs stringify as it'd …
MichaelLeeHobbs Apr 28, 2023
fa910fa
wip - Adds fix for #244 in the form of strict mode which defaults to …
MichaelLeeHobbs Apr 28, 2023
7fc1773
wip - working on a fix for 284
MichaelLeeHobbs Apr 29, 2023
61ee67a
wip - working on a fix for 284
MichaelLeeHobbs Apr 29, 2023
672df08
wip - fixed 284, major cleanup
MichaelLeeHobbs Apr 29, 2023
eca418a
wip - 99.5% code coverage and mostly documented
MichaelLeeHobbs Apr 30, 2023
75eba12
wip - code analysis clean up
MichaelLeeHobbs Apr 30, 2023
24d0d1d
wip - add documentation
MichaelLeeHobbs Apr 30, 2023
2eb4fc2
wip - updated notes
MichaelLeeHobbs Apr 30, 2023
a7ecb58
wip - basically done
MichaelLeeHobbs Apr 30, 2023
e717cef
Done for now
MichaelLeeHobbs Apr 30, 2023
5ad2f4f
fixed typos
MichaelLeeHobbs Apr 30, 2023
095916e
removed tsx
MichaelLeeHobbs May 4, 2023
3ca6ef3
removed npx from scripts calling jest
MichaelLeeHobbs May 4, 2023
9c5762f
removed old_typesVersions
MichaelLeeHobbs May 4, 2023
204ffbd
update requires node version
MichaelLeeHobbs May 4, 2023
fd78774
Remove .run folder from repository
MichaelLeeHobbs May 4, 2023
04d3071
Remove GPT4 PROMPTS from repository
MichaelLeeHobbs May 4, 2023
b780f77
cleaned up .gitignore
MichaelLeeHobbs May 4, 2023
71db6bb
cleaned up .npmignore
MichaelLeeHobbs May 4, 2023
330ec94
cleaned up .eslintrc.cjs
MichaelLeeHobbs May 4, 2023
3a06e5b
Update src/CronDate.ts
MichaelLeeHobbs May 4, 2023
9b6f51f
renamed applyDateOperation and made hoursLength optional
MichaelLeeHobbs May 4, 2023
10eef40
renamed handleMathOp to invokeDateOperation
MichaelLeeHobbs May 4, 2023
4849100
cleaned up predefined expressions
MichaelLeeHobbs May 4, 2023
a721e08
cleaned up Predefined Expressions
MichaelLeeHobbs May 4, 2023
ad81072
removed pointless defensive code
MichaelLeeHobbs May 4, 2023
29f2b65
added types RawCronFields and SerializedCronFields
MichaelLeeHobbs May 4, 2023
5f9d8ac
cleaned up asserts on getRawFields
MichaelLeeHobbs May 4, 2023
33443c3
fixed test
MichaelLeeHobbs May 4, 2023
67a4c2b
cleaned up parse options
MichaelLeeHobbs May 4, 2023
2cc95e2
cleaned up handleSingleRange, handleMultipleRanges
MichaelLeeHobbs May 4, 2023
6ec7d1a
commented compactField
MichaelLeeHobbs May 4, 2023
f393744
changed output dir to dist
MichaelLeeHobbs May 4, 2023
09c57f4
cleaned up PredefinedExpressionsEnum
MichaelLeeHobbs May 5, 2023
d9b67fa
cleaned up assert
MichaelLeeHobbs May 5, 2023
2925327
Merge remote-tracking branch 'origin/master'
MichaelLeeHobbs May 5, 2023
d0352a1
removed collect coverage from .js
MichaelLeeHobbs May 5, 2023
6e4607b
added prettier as a dev dependencies and added object-curly-spacing t…
MichaelLeeHobbs May 5, 2023
172641c
Renamed enums using PascalCase
MichaelLeeHobbs May 5, 2023
3ec3ddc
removed prettier, having eslint and prettier at the same time was a b…
MichaelLeeHobbs May 5, 2023
6a4fa5d
refactored out CronConstants.ts and refactored constraints into the f…
MichaelLeeHobbs May 5, 2023
2d96b49
disabled failing test that are allowed by current behavior. It's upto…
MichaelLeeHobbs May 5, 2023
c315950
fixed comment
MichaelLeeHobbs May 5, 2023
9681153
Fixed bugs for dual builds which broke the tests. Fixed the tests
MichaelLeeHobbs May 7, 2023
e0e909e
refactored casing on enums
MichaelLeeHobbs May 8, 2023
de8d623
removed debug
MichaelLeeHobbs May 8, 2023
59566a0
renamed interfaces and cleaned up some code
MichaelLeeHobbs May 8, 2023
467fdef
freeze instead of cloning to prevent mutation
MichaelLeeHobbs May 8, 2023
91a1e2c
optimized applyDateOperation
MichaelLeeHobbs May 20, 2023
5cc4170
renamed CronFields to CronFieldCollection
MichaelLeeHobbs May 20, 2023
484e302
removed archive
MichaelLeeHobbs May 20, 2023
ce0048a
fixed github build based on suggestion from harrisiirak
MichaelLeeHobbs May 20, 2023
b2cfbff
this commit is to capture DaysInMonth changes before removing it so w…
MichaelLeeHobbs May 20, 2023
e6835fa
refactored out DaysInMonth enum, we had to do silly things to make it…
MichaelLeeHobbs May 20, 2023
c3ebd04
cleaned up enum names
MichaelLeeHobbs May 20, 2023
6f91fb5
cleaned up unneeded mutation protection
MichaelLeeHobbs May 20, 2023
b0c1a68
cleaned up tests
MichaelLeeHobbs May 20, 2023
6f0129f
cleaned up var naming
MichaelLeeHobbs May 20, 2023
c1812c8
clean up old todos
MichaelLeeHobbs May 22, 2023
05d4f6c
cleaned up unneeded mutation protection
MichaelLeeHobbs May 22, 2023
d0ee50c
added documentation for strict mode
MichaelLeeHobbs May 22, 2023
72c3e36
cleaned up the project, 100% coverage, fixed broken test, replaced sp…
MichaelLeeHobbs May 22, 2023
0ea8af3
clean up
MichaelLeeHobbs May 23, 2023
6e8a8c4
remove unsupported Node.js versions from the build matrix.
MichaelLeeHobbs May 28, 2023
76827ec
removed notes
MichaelLeeHobbs May 28, 2023
b0ed594
removed redundant utc option
MichaelLeeHobbs May 28, 2023
4f6593a
cleaned up comments
MichaelLeeHobbs May 28, 2023
aa36aae
renamed DayOfTheMonthRange to DayOfMonthRange
MichaelLeeHobbs May 28, 2023
e9c43f5
renamed DayOfTheWeekRange to DayOfWeekRange
MichaelLeeHobbs May 28, 2023
ff10ea8
renamed CronFieldTypes to CronFieldType
MichaelLeeHobbs May 28, 2023
650d7d9
Update src/wrapper-index.cjs
MichaelLeeHobbs May 28, 2023
25c4653
removed ESM support and updated documentation
MichaelLeeHobbs May 30, 2023
b3b5f11
Update src/fields/CronMonth.ts
MichaelLeeHobbs Jun 5, 2023
e950926
Update src/fields/CronMonth.ts
MichaelLeeHobbs Jun 5, 2023
d728f36
fixed bug where luxon represents sunday as 7 but the cron expression …
MichaelLeeHobbs Jul 1, 2024
68654a3
Merge remote-tracking branch 'origin/master'
MichaelLeeHobbs Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# .editorconfig
root = true

[*]
indent_style = space
indent_size = 2
max_line_length = 160
harrisiirak marked this conversation as resolved.
Show resolved Hide resolved

[*.{js,ts}]
ij_typescript_spaces_within_imports = true
harrisiirak marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 49 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
MichaelLeeHobbs marked this conversation as resolved.
Show resolved Hide resolved
root: true,
env: {
browser: false,
es6: true,
node: true,
jest: true,
},
extends: [
'eslint:recommended'
],
ignorePatterns: [
'dist/**',
'**/*.json',
'coverage/**',
'docs/**',
'src/index.cjs.js',
],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
overrides: [
{
files: ['**/*.ts'],
env: { 'browser': false, 'es6': true, 'node': true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
indent: ['error', 2, { SwitchCase: 1 }],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/no-explicit-any': 0,
'object-curly-spacing': ['warn', 'always'],
'max-len': ['error', { code: 160 }],
harrisiirak marked this conversation as resolved.
Show resolved Hide resolved
}
}
]
};
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 15.x, 16.x, 17.x, 18.x, 19.x]
node-version: [15.14.x, 16.x, 17.x, 18.x, 19.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -22,4 +22,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm test
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/
node_modules
lib-cov
coverage
*.seed
Expand All @@ -12,10 +12,14 @@ coverage
pids
logs
results
dist
testing

npm-debug.log

.run
.idea
.history
.vscode
.nyc_output
yarn.lock

!coverage/*.svg
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run precommit
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@
.history
.nyc_output
node_modules
src
tsconfig.json
package-lock.json
yarn.lock
.github
docs
.run
.husky
tests
.editorconfig
.eslintrc.cjs
.gitignore
component.json
jest.config.js
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ cron-parser
================

[![Build Status](https://github.com/harrisiirak/cron-parser/actions/workflows/push.yml/badge.svg?branch=master)](https://github.com/harrisiirak/cron-parser/actions/workflows/push.yml)
[![NPM version](https://badge.fury.io/js/cron-parser.png)](http://badge.fury.io/js/cron-parser)
[![NPM version](https://badge.fury.io/js/cron-parser.png)](http://badge.fury.io/js/cron-parser)![Statements](./coverage/badge-statements.svg)

[//]: # (![Branches](./coverage/badge-branches.svg))

[//]: # (![Functions](./coverage/badge-functions.svg))

[//]: # (![Lines](./coverage/badge-lines.svg))



Node.js library for parsing and manipulating crontab instructions. It includes support for timezones and DST transitions.

Expand Down Expand Up @@ -111,21 +119,42 @@ try {
}
```

Manipulation
Manipulation

```javascript
var parser = require('cron-parser');

var interval = parser.parseExpression('0 7 * * 0-4');
var fields = JSON.parse(JSON.stringify(interval.fields)); // Fields is immutable
var fields = JSON.parse(JSON.stringify(interval.#fields)); // Fields is immutable
fields.hour = [8];
fields.minute = [29];
fields.dayOfWeek = [1,3,4,5,6,7];
fields.dayOfWeek = [1, 3, 4, 5, 6, 7];
var modifiedInterval = parser.fieldsToExpression(fields);
var cronString = modifiedInterval.stringify();
console.log(cronString); // "29 8 * * 1,3-7"
```

Strict Mode

In several implementations of CRON, it's ambiguous to specify both the Day Of Month and Day Of Week parameters simultaneously, as it's unclear which one should take precedence. Despite this ambiguity, this library allows both parameters to be set by default, although the resultant behavior might not align with your expectations.

To resolve this ambiguity, you can activate the strict mode of the library. In strict mode, the library prevents the simultaneous setting of both Day Of Month and Day Of Week, effectively serving as a validation method for user inputs. To enable strict mode, set the `options.strict` flag to true.

Consider the example below:

```javascript
// Specifies a schedule that occurs at 12:00 on every day-of-month from 1 through 31 and on Monday.
const options = {
currentDate: new CronDate('Mon, 12 Sep 2022 14:00:00', 'UTC'),
strict: true,
};
const expression = '0 0 12 1-31 * 1';
// With strict mode enabled, the parser throws an error as both dayOfMonth and dayOfWeek are used together.
CronExpression.parse(expression, options); // throws: Cannot use both dayOfMonth and dayOfWeek together in strict mode!
```

In this example, the CRON expression is meant to trigger an event at 12:00 on every day from the 1st through the 31st and on every Monday. However, since strict mode is enabled in the options, an error is thrown, indicating that both the dayOfMonth and dayOfWeek parameters cannot be used together.

Options
========

Expand All @@ -145,7 +174,7 @@ The reason being that those are the formats accepted by the
[`luxon`](https://moment.github.io/luxon/) library which is being used to handle dates.

Using `Date` as an input can be problematic specially when using the `tz` option. The issue being that, when creating a new `Date` object without
any timezone information, it will be created in the timezone of the system that is running the code. This (most of times) won't be what the user
any timezone information, it will be created in the timezone of the system that is running the code. This (most of the times) won't be what the user
will be expecting. Using one of the supported `string` formats will solve the issue(see timezone example).

* *iterator* - Return ES6 compatible iterator object
Expand Down
1 change: 1 addition & 0 deletions coverage/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions coverage/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions coverage/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions coverage/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
71 changes: 71 additions & 0 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
:root {
--light-hl-0: #0000FF;
--dark-hl-0: #569CD6;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #0070C1;
--dark-hl-2: #4FC1FF;
--light-hl-3: #795E26;
--dark-hl-3: #DCDCAA;
--light-hl-4: #001080;
--dark-hl-4: #9CDCFE;
--light-hl-5: #098658;
--dark-hl-5: #B5CEA8;
--light-hl-6: #008000;
--dark-hl-6: #6A9955;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}

@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
} }

@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
} }

:root[data-theme='light'] {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
}

:root[data-theme='dark'] {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
}

.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
pre, code { background: var(--code-background); }
58 changes: 58 additions & 0 deletions docs/assets/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/search.js

Large diffs are not rendered by default.

Loading