@bemoje/date 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @bemoje/date
2
+ Date related tools/util.
3
+
4
+ ![GitHub Top Language](https://img.shields.io/github/languages/top/bemoje/https://github.com/bemoje/tsmono)
5
+
6
+ ##### Github
7
+ ![GitHub Last Commit](https://img.shields.io/github/last-commit/bemoje/https://github.com/bemoje/tsmono?color=red)
8
+ ![GitHub Stars](https://img.shields.io/github/stars/bemoje/https://github.com/bemoje/tsmono)
9
+ ![GitHub Forks](https://img.shields.io/github/forks/bemoje/https://github.com/bemoje/tsmono)
10
+ ![GitHub Watchers](https://img.shields.io/github/watchers/bemoje/https://github.com/bemoje/tsmono)
11
+ ![GitHub Repo Size](https://img.shields.io/github/repo-size/bemoje/https://github.com/bemoje/tsmono)
12
+
13
+ ##### NPM
14
+ <span><a href="https://npmjs.org/@bemoje/date" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bemoje/date" alt="NPM Version" /></a></span>
15
+ <span><a href="https://npmjs.org/@bemoje/date" title="NPM Downloads"><img src="https://img.shields.io/npm/dt/@bemoje/date" alt="NPM Downloads" /></a></span>
16
+
17
+ ## Documentation
18
+ [date docs](https://bemoje.github.io/tsmono/html/date/modules.html)
19
+
20
+ ##### Donate
21
+ <span><a href="https://www.patreon.com/user?u=40752770" title="Donate using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon Donation" /></a></span>
22
+
23
+ ## Installation
24
+ This library is published in the NPM registry and can be installed using any compatible package manager.
25
+
26
+ #### NPM
27
+ ```sh
28
+ npm install @bemoje/date
29
+ ```
30
+
31
+
32
+ ## Issues
33
+ Please let me know of any bugs or [issues](https://github.com/bemoje/https://github.com/bemoje/tsmono/issues).
34
+
35
+ ## Contribute
36
+ Contributors are welcome to open a [pull request](https://github.com/bemoje/https://github.com/bemoje/tsmono/pulls).
37
+
38
+ ## License
39
+ Released under the [MIT License](./LICENSE).
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @bemoje/date v0.0.1
2
+ * @bemoje/date v0.0.2
3
3
  * (c) Benjamin Møller Jensen
4
4
  * Released under the MIT License.
5
5
  */"use strict";function isValidDate(year,month,day,hour,minute,second,millisecond){year=year?+year:0,month=month?+month:0,day=day?+day:0,hour=hour?+hour:0,minute=minute?+minute:0,second=second?+second:0,millisecond=millisecond?+millisecond:0;const d=new Date(year,month-1,day,hour,minute,second,millisecond);return d.getFullYear()===year&&d.getMonth()+1===month&&d.getDate()===day&&d.getHours()===hour&&d.getMinutes()===minute&&d.getSeconds()===second&&d.getMilliseconds()===millisecond}function assertValidDate(year,month,day,hour,minute,second,millisecond){if(!isValidDate(year,month,day,hour,minute,second,millisecond))throw new Error(`Expected valid date. Got: ${JSON.stringify({year,month,day,hour,minute,second,millisecond})}.`)}function isValidDateMonth(month){return Number.isInteger(month)&&1<=month&&12>=month}function assertValidDateMonth(month){if(!isValidDateMonth(month))throw new Error(`Invalid month: ${month}.`)}function isValidDateYear(year){return Number.isInteger(year)&&0<=year}function assertValidDateYear(year){if(!isValidDateYear(year))throw new Error(`Invalid year: ${year}.`)}function isLeapYear(year){return assertValidDateYear(year),0==year%4&&0!=year%100||0==year%400}function numDaysInMonth(month,year){assertValidDateMonth(month);return 2===month&&year!==void 0&&isLeapYear(year)?29:[0,31,28,31,30,31,30,31,31,30,31,30,31][month]}function isValidDateDay(day,month,year){return!!Number.isInteger(day)&&!!Number.isInteger(month)&&(!year||Number.isInteger(year))&&!(1>day)&&!(day>numDaysInMonth(month,year))}function assertValidDateDay(day,month,year){if(!isValidDateDay(day,month,year))throw new Error(`Invalid day of the month: ${day}.`)}const MS_IN_DAY=86400000,MS_IN_HOUR=3600000,MS_IN_MINUTE=60000,MS_IN_MONTH=2628000000,MS_IN_SECOND=1e3,MS_IN_WEEK=604800000,MS_IN_YEAR=31536000000;function dateDaysAgo(days){const date=new Date;return date.setDate(date.getDate()-days),date}function dateWeekDayName(date){return names[date.getDay()]}const names=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function msSinceDate(date){if("number"==typeof date){if(!Number.isInteger(date))throw new Error("Expected date to be a Date or an integer. Got: "+date);date=new Date(date)}return Date.now()-date.getTime()}function daysSinceDate(date){return msSinceDate(date)/MS_IN_DAY}function getCentury(year){return assertValidDateYear(year),Math.floor(year/100)+1}function getCurrentYear(){return new Date().getUTCFullYear()}function hoursSinceDate(date){return msSinceDate(date)/MS_IN_HOUR}function isoDateTimestamp(date=new Date){return date.toISOString().replace(/\D/g,"")}function isoDateTimestampForFilename(date=new Date){return date.toISOString().replace(/[-:T.]/g,"-").replace("Z","")}function minutesSinceDate(date){return msSinceDate(date)/MS_IN_MINUTE}function monthsSinceDate(date){return msSinceDate(date)/MS_IN_MONTH}function prettyIsoDateString(iso,dateTimeSeparator=" ",precision="millisecond"){return iso.substring(0,map[precision]).replace(/T/,dateTimeSeparator).replace(/-|:/g,".")}const map={year:4,month:7,day:10,hour:13,minute:16,second:19,millisecond:23};function secondsSinceDate(date){return msSinceDate(date)/MS_IN_SECOND}function weeksSinceDate(date){return msSinceDate(date)/MS_IN_WEEK}function yearsSinceDate(date){return msSinceDate(date)/MS_IN_YEAR}exports.MS_IN_DAY=86400000,exports.MS_IN_HOUR=MS_IN_HOUR,exports.MS_IN_MINUTE=MS_IN_MINUTE,exports.MS_IN_MONTH=MS_IN_MONTH,exports.MS_IN_SECOND=MS_IN_SECOND,exports.MS_IN_WEEK=MS_IN_WEEK,exports.MS_IN_YEAR=MS_IN_YEAR,exports.assertValidDate=assertValidDate,exports.assertValidDateDay=assertValidDateDay,exports.assertValidDateMonth=assertValidDateMonth,exports.assertValidDateYear=assertValidDateYear,exports.dateDaysAgo=dateDaysAgo,exports.dateWeekDayName=dateWeekDayName,exports.daysSinceDate=daysSinceDate,exports.getCentury=getCentury,exports.getCurrentYear=getCurrentYear,exports.hoursSinceDate=hoursSinceDate,exports.isLeapYear=isLeapYear,exports.isValidDate=isValidDate,exports.isValidDateDay=isValidDateDay,exports.isValidDateMonth=isValidDateMonth,exports.isValidDateYear=isValidDateYear,exports.isoDateTimestamp=isoDateTimestamp,exports.isoDateTimestampForFilename=isoDateTimestampForFilename,exports.minutesSinceDate=minutesSinceDate,exports.monthsSinceDate=monthsSinceDate,exports.msSinceDate=msSinceDate,exports.numDaysInMonth=numDaysInMonth,exports.prettyIsoDateString=prettyIsoDateString,exports.secondsSinceDate=secondsSinceDate,exports.weeksSinceDate=weeksSinceDate,exports.yearsSinceDate=yearsSinceDate;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @bemoje/date v0.0.1
2
+ * @bemoje/date v0.0.2
3
3
  * (c) Benjamin Møller Jensen
4
4
  * Released under the MIT License.
5
5
  */function isValidDate(year,month,day,hour,minute,second,millisecond){year=year?+year:0,month=month?+month:0,day=day?+day:0,hour=hour?+hour:0,minute=minute?+minute:0,second=second?+second:0,millisecond=millisecond?+millisecond:0;const d=new Date(year,month-1,day,hour,minute,second,millisecond);return d.getFullYear()===year&&d.getMonth()+1===month&&d.getDate()===day&&d.getHours()===hour&&d.getMinutes()===minute&&d.getSeconds()===second&&d.getMilliseconds()===millisecond}function assertValidDate(year,month,day,hour,minute,second,millisecond){if(!isValidDate(year,month,day,hour,minute,second,millisecond))throw new Error(`Expected valid date. Got: ${JSON.stringify({year,month,day,hour,minute,second,millisecond})}.`)}function isValidDateMonth(month){return Number.isInteger(month)&&1<=month&&12>=month}function assertValidDateMonth(month){if(!isValidDateMonth(month))throw new Error(`Invalid month: ${month}.`)}function isValidDateYear(year){return Number.isInteger(year)&&0<=year}function assertValidDateYear(year){if(!isValidDateYear(year))throw new Error(`Invalid year: ${year}.`)}function isLeapYear(year){return assertValidDateYear(year),0==year%4&&0!=year%100||0==year%400}function numDaysInMonth(month,year){assertValidDateMonth(month);return 2===month&&year!==void 0&&isLeapYear(year)?29:[0,31,28,31,30,31,30,31,31,30,31,30,31][month]}function isValidDateDay(day,month,year){return!!Number.isInteger(day)&&!!Number.isInteger(month)&&(!year||Number.isInteger(year))&&!(1>day)&&!(day>numDaysInMonth(month,year))}function assertValidDateDay(day,month,year){if(!isValidDateDay(day,month,year))throw new Error(`Invalid day of the month: ${day}.`)}const MS_IN_DAY=86400000,MS_IN_HOUR=3600000,MS_IN_MINUTE=60000,MS_IN_MONTH=2628000000,MS_IN_SECOND=1e3,MS_IN_WEEK=604800000,MS_IN_YEAR=31536000000;function dateDaysAgo(days){const date=new Date;return date.setDate(date.getDate()-days),date}function dateWeekDayName(date){return names[date.getDay()]}const names=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function msSinceDate(date){if("number"==typeof date){if(!Number.isInteger(date))throw new Error("Expected date to be a Date or an integer. Got: "+date);date=new Date(date)}return Date.now()-date.getTime()}function daysSinceDate(date){return msSinceDate(date)/MS_IN_DAY}function getCentury(year){return assertValidDateYear(year),Math.floor(year/100)+1}function getCurrentYear(){return new Date().getUTCFullYear()}function hoursSinceDate(date){return msSinceDate(date)/MS_IN_HOUR}function isoDateTimestamp(date=new Date){return date.toISOString().replace(/\D/g,"")}function isoDateTimestampForFilename(date=new Date){return date.toISOString().replace(/[-:T.]/g,"-").replace("Z","")}function minutesSinceDate(date){return msSinceDate(date)/MS_IN_MINUTE}function monthsSinceDate(date){return msSinceDate(date)/MS_IN_MONTH}function prettyIsoDateString(iso,dateTimeSeparator=" ",precision="millisecond"){return iso.substring(0,map[precision]).replace(/T/,dateTimeSeparator).replace(/-|:/g,".")}const map={year:4,month:7,day:10,hour:13,minute:16,second:19,millisecond:23};function secondsSinceDate(date){return msSinceDate(date)/MS_IN_SECOND}function weeksSinceDate(date){return msSinceDate(date)/MS_IN_WEEK}function yearsSinceDate(date){return msSinceDate(date)/MS_IN_YEAR}export{MS_IN_DAY,MS_IN_HOUR,MS_IN_MINUTE,MS_IN_MONTH,MS_IN_SECOND,MS_IN_WEEK,MS_IN_YEAR,assertValidDate,assertValidDateDay,assertValidDateMonth,assertValidDateYear,dateDaysAgo,dateWeekDayName,daysSinceDate,getCentury,getCurrentYear,hoursSinceDate,isLeapYear,isValidDate,isValidDateDay,isValidDateMonth,isValidDateYear,isoDateTimestamp,isoDateTimestampForFilename,minutesSinceDate,monthsSinceDate,msSinceDate,numDaysInMonth,prettyIsoDateString,secondsSinceDate,weeksSinceDate,yearsSinceDate};
package/jest.config.ts ADDED
@@ -0,0 +1,13 @@
1
+ /* eslint-disable */
2
+ const pkg = require('./package.json')
3
+ const name = pkg.name.split('@')[1]
4
+ export default {
5
+ displayName: name,
6
+ preset: '../../jest.preset.js',
7
+ testEnvironment: 'node',
8
+ transform: {
9
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
10
+ },
11
+ moduleFileExtensions: ['ts', 'js', 'html'],
12
+ coverageDirectory: '../../coverage/pkg/' + name,
13
+ }
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@bemoje/date",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Date related tools/util.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "types": "dist/types/index.d.ts",
8
8
  "scripts": {
9
- "lint": "eslint \"*/**/*.{ts,js,json}\" --fix",
10
- "test": "jest --preset ts-jest",
11
9
  "build": "rimraf dist && rollup --config ./rollup.config.js --bundleConfigAsCjs",
12
- "docs": "rimraf ../../docs/date && typedoc --out ../../docs/date --entryPoints src/index.ts",
13
- "prepub": "npm run lint && npm run build && npm run test && npm run docs"
10
+ "docs": "rimraf ../../docs/date && typedoc --out ../../docs/date --entryPoints src/index.ts"
14
11
  },
15
12
  "author": {
16
13
  "name": "Benjamin Møller Jensen",
package/project.json CHANGED
@@ -3,6 +3,28 @@
3
3
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
4
  "sourceRoot": "pkg/date/src",
5
5
  "projectType": "library",
6
- "targets": {},
6
+ "targets": {
7
+ "lint": {
8
+ "executor": "@nx/linter:eslint",
9
+ "outputs": ["{options.outputFile}"],
10
+ "options": {
11
+ "lintFilePatterns": ["pkg/date/**/*.ts"]
12
+ }
13
+ },
14
+ "test": {
15
+ "executor": "@nx/jest:jest",
16
+ "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
17
+ "options": {
18
+ "jestConfig": "pkg/date/jest.config.ts",
19
+ "passWithNoTests": true
20
+ },
21
+ "configurations": {
22
+ "ci": {
23
+ "ci": true,
24
+ "codeCoverage": true
25
+ }
26
+ }
27
+ }
28
+ },
7
29
  "tags": []
8
30
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9
+ }