date-holidays 3.24.3 → 3.25.0

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/types/index.d.ts CHANGED
@@ -65,7 +65,7 @@ declare module 'date-holidays' {
65
65
  type: HolidayType;
66
66
  /** the holiday rule - use for references */
67
67
  rule: string;
68
- /** holiday is a substritute day */
68
+ /** holiday is a substitute day */
69
69
  substitute?: boolean;
70
70
  }
71
71
  }
@@ -102,8 +102,8 @@ declare module 'date-holidays' {
102
102
  */
103
103
  setHoliday(rule: string, opts: HolidaysTypes.HolidayOptions | string): boolean;
104
104
  /**
105
- * get all holidays for `year` with names using prefered `language`
106
- * @param [year] - if omitted current year is choosen
105
+ * get all holidays for `year` with names using preferred `language`
106
+ * @param [year] - if omitted current year is chosen
107
107
  * @param [language] - ISO 639-1 code for language
108
108
  * @returns of found holidays in given year sorted by Date:
109
109
  */
package/rollup.config.mjs DELETED
@@ -1,10 +0,0 @@
1
- export default {
2
- input: './src/index.js',
3
- output: {
4
- dir: 'lib',
5
- format: 'cjs',
6
- entryFileNames: '[name].cjs',
7
- preserveModules: true,
8
- exports: 'auto'
9
- }
10
- }
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require('path')
4
-
5
- /**
6
- * include new generated tree of supported countries to README.md file
7
- */
8
- if (module === require.main) {
9
- const fs = require('fs')
10
- const tree = require('./tree.cjs')
11
- const readmeFile = path.resolve(__dirname, '..', 'README.md')
12
- const buf = (function () {
13
- const self = {
14
- str: '',
15
- write: function (str) {
16
- self.str += str
17
- }
18
- }
19
- return self
20
- })()
21
- let content = fs.readFileSync(readmeFile, 'utf8')
22
-
23
- tree(buf)
24
- content = content.replace(/(<!-- !tree -->)[^]*(<!-- tree! -->)/m, '$1\n\n```\n' + buf.str + '```\n$2')
25
-
26
- fs.writeFileSync(readmeFile, content, 'utf8')
27
- }
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint
4
- key-spacing: 0
5
- */
6
-
7
- const fs = require('fs')
8
- const path = require('path')
9
-
10
- const argv = process.argv
11
- .slice(2)
12
- .map((f) => {
13
- return process.cwd() + '/' + f
14
- })
15
-
16
- const config = {
17
- fileRegex: /^([A-Z]+)\.yaml$/,
18
- license: argv[0] || path.resolve(__dirname, '..', 'LICENSE'),
19
- countries: argv[1] || path.resolve(__dirname, '..', 'data', 'countries')
20
- }
21
-
22
- function uniq (arr) {
23
- const obj = {}
24
- arr.forEach((i) => {
25
- obj[i] = 1
26
- })
27
- return Object.keys(obj)
28
- }
29
-
30
- function Attributions () {
31
- }
32
- module.exports = Attributions
33
-
34
- Attributions.prototype = {
35
- _load (filename) {
36
- return fs.readFileSync(filename, 'utf8')
37
- },
38
-
39
- _save (filename, data) {
40
- return fs.writeFileSync(filename, data, 'utf8')
41
- },
42
-
43
- load () {
44
- const list = fs.readdirSync(config.countries)
45
- console.log(list.length, 'files read')
46
-
47
- this.data = list
48
- .map((file) => {
49
- if (config.fileRegex.test(file)) {
50
- return this._load(path.resolve(config.countries, file))
51
- }
52
- return ''
53
- })
54
- .join('')
55
- .split(/[\n\r]/)
56
-
57
- return this
58
- },
59
-
60
- extract () {
61
- const data = this.data
62
- .filter((d) => /#\s*@attrib\s/.test(d))
63
- .map((d) => {
64
- return d
65
- .replace(/#\s*@attrib/, '')
66
- .trim()
67
- })
68
- .sort()
69
-
70
- this.data = uniq(data).join('\n')
71
-
72
- return this
73
- },
74
-
75
- insert (filename) {
76
- this.filename = filename
77
- const license = this._load(filename)
78
- this.data = license.replace(/<(attribution)>[^]*<\/\1>/m, '<attribution>\n\n' + this.data + '\n\n</attribution>')
79
- return this
80
- },
81
-
82
- save () {
83
- this._save(this.filename, this.data)
84
- }
85
- }
86
-
87
- if (module === require.main) {
88
- const a = new Attributions()
89
- a.load().extract().insert(config.license).save()
90
- }
@@ -1,129 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint no-unused-vars: ["error", { varsIgnorePattern: "_" }] */
4
-
5
- const { promisify } = require('util')
6
- const { exec } = require('child_process')
7
- const path = require('path')
8
- const fs = require('fs')
9
- const { version } = require('../package.json')
10
-
11
- const BASE = 'https://github.com/commenthol/date-holidays'
12
- const CHANGELOG = path.resolve(__dirname, '../CHANGELOG.md')
13
-
14
- const MAJOR = 0
15
- const MINOR = 1
16
- const PATCH = 2
17
-
18
- const semverInc = (version, semrel) => {
19
- const semver = version.split(/[.-]/)
20
- semver[semrel] = +semver[semrel] + 1
21
- if (semrel === MINOR) semver[2] = 0
22
- if (semrel === MAJOR) semver[2] = semver[1] = 0
23
- return semver.splice(0, 3).join('.')
24
- }
25
-
26
- const date = () => new Date().toISOString().substr(0, 10)
27
-
28
- const templateHeader = (from, to) =>
29
- `## [${to}](${BASE}/compare/${from}...${to}) (${date()})`
30
-
31
- const templateCommit = (line) =>
32
- `- ${line.subject} [${line.short}](${BASE}/commit/${line.hash})`
33
-
34
- const gitTagVersions = async () => {
35
- const gittags = await promisify(exec)('git tag --list v*')
36
- const tags = gittags.stdout.split(/\n/)
37
- .map(v => {
38
- // filter pre-release versions
39
- const [_, vv] = /^v?(\d+\.\d+\.\d+).*/.exec(v) || []
40
- if (vv) {
41
- const vvv = vv.split(/[.-]/).filter(s => !s[3]).filter(Boolean)
42
- return vvv && vvv.length ? vvv : undefined
43
- } else {
44
- return undefined
45
- }
46
- })
47
- .filter(Boolean)
48
- .sort((a, b) => {
49
- for (let i = 0; i < 3; i++) {
50
- if (a[i] !== b[i]) {
51
- return b[i] - a[i]
52
- }
53
- }
54
- return 0
55
- })
56
- return tags
57
- }
58
-
59
- const gitLog = async (from, to = 'HEAD') => {
60
- const gitLogMapper = ['short', 'hash', 'tags', 'date', 'subject']
61
-
62
- const opts = version ? `${from}..${to}` : ''
63
- const cmd = `git log ${opts} --pretty=format:"%h|%H|%d|%ci|%s"`
64
- const log = await promisify(exec)(cmd)
65
-
66
- const lines = log.stdout.split('\n')
67
- .map(line => line.split(/[|]/)
68
- .reduce((o, item, i) => {
69
- const prop = gitLogMapper[i]
70
- let val = item
71
- switch (prop) {
72
- case 'date':
73
- val = item.substring(0, 10)
74
- break
75
- case 'tags': {
76
- const [_, tags] = /^.*\(tag: ([^)]+)\).*$/.exec(item) || []
77
- if (tags) {
78
- val = tags.split(/\s*,\s*/)
79
- } else {
80
- val = []
81
- }
82
- break
83
- }
84
- }
85
- o[prop] = val
86
- return o
87
- }, {})
88
- )
89
- return lines
90
- }
91
-
92
- ;(async () => {
93
- let semrel = PATCH
94
-
95
- const tagVersions = await gitTagVersions()
96
- const lastVersion = tagVersions[0] && tagVersions[0].join('.')
97
-
98
- const gitlog = await gitLog('v' + lastVersion)
99
- const lines = gitlog
100
- .filter(line => !/Merge pull request|chore.*(bump|contributors)/.test(line.subject))
101
- .map(line => {
102
- if (/break[(:)]/.test(line.subject)) {
103
- semrel = MAJOR
104
- } else if (/feat[(:)]/.test(line.subject)) {
105
- semrel = MINOR
106
- }
107
- return line
108
- })
109
-
110
- const nextVersion = semverInc(version, semrel)
111
-
112
- const changes = [
113
- '',
114
- templateHeader(lastVersion, nextVersion),
115
- '',
116
- lines.map(line => templateCommit(line)).join('\n'),
117
- ''
118
- ].join('\n')
119
-
120
- const changelog = await promisify(fs.readFile)(CHANGELOG, 'utf8')
121
-
122
- const containsRE = new RegExp(`\n## \\[${nextVersion}\\]\\([^]*?\n## `, 'm')
123
-
124
- const out = containsRE.test(changelog)
125
- ? changelog.replace(containsRE, changes + '\n## ')
126
- : changelog.replace(/(# Changelog\n)/, '$1' + changes)
127
-
128
- await promisify(fs.writeFile)(CHANGELOG, out, 'utf8')
129
- })()
package/scripts/tree.cjs DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * draw tree of supported countries, states, regions
5
- */
6
- function tree (stream) {
7
- const draw = [
8
- '├── ',
9
- '└── ',
10
- '│ ',
11
- ' '
12
- ]
13
-
14
- const Holidays = require('..')
15
-
16
- const countries = new Holidays().getCountries()
17
- const countriesLen = Object.keys(countries).length - 1
18
-
19
- stream.write('Countries: ' + (countriesLen + 1) + '\n')
20
-
21
- Object.keys(countries).forEach((country, i) => {
22
- const d = (i === countriesLen ? draw[1] : draw[0])
23
- stream.write(d + country + ': ' + countries[country] + '\n')
24
-
25
- const states = new Holidays().getStates(country)
26
- if (states) {
27
- const statesLen = Object.keys(states).length - 1
28
- Object.keys(states).forEach((state, j) => {
29
- let d = (i === countriesLen ? draw[3] : draw[2])
30
- d += (j === statesLen ? draw[1] : draw[0])
31
- stream.write(d + state + ': ' + states[state] + '\n')
32
-
33
- const regions = new Holidays().getRegions(country, state)
34
- if (regions) {
35
- const regionsLen = Object.keys(regions).length - 1
36
- Object.keys(regions).forEach((region, k) => {
37
- let d = (i === countriesLen ? draw[3] : draw[2])
38
- d += (j === statesLen ? draw[3] : draw[2])
39
- d += (k === regionsLen ? draw[1] : draw[0])
40
- stream.write(d + region + ': ' + regions[region] + '\n')
41
- })
42
- }
43
- })
44
- }
45
- })
46
- }
47
- module.exports = tree
48
-
49
- if (module === require.main) {
50
- tree(process.stdout)
51
- }
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "lib": [
5
- "es6"
6
- ],
7
- "noImplicitAny": true,
8
- "noImplicitThis": true,
9
- "strictFunctionTypes": true,
10
- "strictNullChecks": true,
11
- "baseUrl": "../../",
12
- "typeRoots": [
13
- "../../"
14
- ],
15
- "types": [],
16
- "noEmit": true,
17
- "forceConsistentCasingInFileNames": true
18
- },
19
- "files": [
20
- "index.d.ts",
21
- "typings.test.ts"
22
- ]
23
- }
package/types/tslint.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "dtslint/dtslint.json",
3
- "rules": {
4
- "no-single-declare-module": false,
5
- "strict-export-declare-modifiers": false,
6
- "no-redundant-jsdoc": false
7
- }
8
- }
@@ -1,8 +0,0 @@
1
- import Holidays from 'date-holidays';
2
-
3
- const hd = new Holidays();
4
- hd.init('US');
5
-
6
- hd.isHoliday(new Date('2019-01-01')); // $ExpectType false | Holiday[]
7
- hd.isHoliday(new Date('2019-02-01')); // $ExpectType false | Holiday[]
8
- hd.getHolidays(); // $ExpectType Holiday[]