spacetime-week-start 0.3.0 → 0.5.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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "spacetime-week-start",
3
+ "version": "0.5.0",
3
4
  "description": "calculate start-of-week",
4
- "version": "0.3.0",
5
- "main": "src/index.js",
6
- "unpkg": "builds/spacetime-week-start.min.js",
5
+ "license": "MIT",
6
+ "repository": "github:spencermountain/spacetime",
7
+ "homepage": "https://github.com/spencermountain/spacetime/tree/master/plugins/week-start",
8
+ "author": "Martin Spodniak & Spencer Kelly",
7
9
  "type": "module",
8
- "sideEffects": false,
9
10
  "exports": {
10
11
  ".": {
11
12
  "require": "./builds/spacetime-week-start.cjs",
@@ -13,17 +14,22 @@
13
14
  "default": "./builds/spacetime-week-start.mjs"
14
15
  }
15
16
  },
16
- "author": "Martin Spodniak & Spencer Kelly",
17
- "homepage": "https://github.com/spencermountain/spacetime/tree/master/plugins/week-start",
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/spencermountain/spacetime.git"
17
+ "main": "./src/index.js",
18
+ "module": "./builds/spacetime-week-start.mjs",
19
+ "sideEffects": false,
20
+ "files": [
21
+ "builds"
22
+ ],
23
+ "devDependencies": {
24
+ "@rollup/plugin-terser": "^1.0.0",
25
+ "rollup": "4.64.7",
26
+ "tap-dancer": "0.4.4",
27
+ "tape": "5.10.3"
21
28
  },
22
- "scripts": {
23
- "watch": "node --watch ./scratch.js",
24
- "test": "TESTENV=dev tape ./test/**/*.test.js | tap-dancer",
25
- "build": "rollup -c --silent"
29
+ "peerDependencies": {
30
+ "spacetime": ">=7.0.0"
26
31
  },
32
+ "unpkg": "builds/spacetime-week-start.min.js",
27
33
  "prettier": {
28
34
  "trailingComma": "none",
29
35
  "tabWidth": 2,
@@ -31,14 +37,13 @@
31
37
  "singleQuote": true,
32
38
  "printWidth": 100
33
39
  },
34
- "devDependencies": {
35
- "shelljs": "0.8.5",
36
- "tap-dancer": "0.3.4",
37
- "tape": "5.5.3",
38
- "terser": "5.39.0"
39
- },
40
- "peerDependencies": {
41
- "spacetime": ">=5.8.2"
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
42
  },
43
- "licence": "MIT"
43
+ "scripts": {
44
+ "watch": "node --watch ./scratch.js",
45
+ "test": "tape './test/**/*.test.js' | tap-dancer --color",
46
+ "version": "node ./scripts/version.js",
47
+ "build": "node ./scripts/version.js && rollup -c --silent"
48
+ }
44
49
  }
package/src/index.js CHANGED
@@ -1,8 +1,13 @@
1
+ import version from './_version.js'
1
2
  import { getWeekStart } from './input/weekStart.js'
2
3
 
3
- export default {
4
+ const plugin = {
4
5
  weekStart: function (input) {
5
- input = input || this.timezone().name
6
- return getWeekStart(input)
6
+ return getWeekStart(input, this.tz)
7
7
  }
8
8
  }
9
+
10
+ // Keep metadata out of spacetime.extend()'s method list.
11
+ Object.defineProperty(plugin, 'version', { value: version })
12
+
13
+ export default plugin
package/_version.js DELETED
@@ -1 +0,0 @@
1
- export default '0.0.1'
package/rollup.config.js DELETED
@@ -1,31 +0,0 @@
1
- import fs from 'fs'
2
- import commonjs from 'rollup-plugin-commonjs'
3
- import json from 'rollup-plugin-json'
4
- import { terser } from 'rollup-plugin-terser'
5
- import resolve from 'rollup-plugin-node-resolve'
6
- import sizeCheck from 'rollup-plugin-filesize-check'
7
- let pkg = JSON.parse(fs.readFileSync('./package.json').toString())
8
- const version = pkg.version
9
-
10
- console.log('\n 📦 - running rollup..\n')
11
-
12
- let name = 'spacetime-week-start'
13
- const banner = `/* spencermountain/${name} ` + version + ' Apache 2.0 */'
14
-
15
- export default [
16
- {
17
- input: 'src/index.js',
18
- output: [{ banner: banner, file: `builds/${name}.mjs`, format: 'esm' }],
19
- plugins: [resolve(), json(), commonjs(), sizeCheck({ expect: 147, warn: 10 })]
20
- },
21
- {
22
- input: 'src/index.js',
23
- output: [{ banner: banner, file: `builds/${name}.cjs`, format: 'umd', sourcemap: false, name: 'weekStart' }],
24
- plugins: [resolve(), json(), commonjs(), sizeCheck({ expect: 159, warn: 10 })]
25
- },
26
- {
27
- input: 'src/index.js',
28
- output: [{ banner: banner, file: `builds/${name}.min.js`, format: 'umd', name: 'weekStart' }],
29
- plugins: [resolve(), json(), commonjs(), terser(), sizeCheck({ expect: 79, warn: 10 })]
30
- }
31
- ]
package/scratch.js DELETED
@@ -1,6 +0,0 @@
1
- import spacetime from 'spacetime'
2
- import spacetimeWeek from './src/index.js'
3
-
4
- spacetime.extend(spacetimeWeek)
5
- let d = spacetime.now('Europe/Berlin')
6
- console.log(d.weekStart('iran'))
@@ -1,267 +0,0 @@
1
- let loc = {
2
- c009: 'antarctica',
3
- c011: 'arctic',
4
- c081: 'gmt',
5
- c231: 'universal',
6
- c233: 'utc',
7
- c245: 'zulu'
8
- }
9
-
10
- let firstDay = {
11
- monday: {
12
- c002: 'aland islands',
13
- c003: 'albania',
14
- c006: 'andorra',
15
- c007: 'angola',
16
- c008: 'anguilla',
17
- c013: 'armenia',
18
- c014: 'aruba',
19
- c016: 'austria',
20
- c017: 'azerbaijan',
21
- c020: 'barbados',
22
- c021: 'belarus',
23
- c022: 'belgium',
24
- c024: 'benin',
25
- c025: 'bermuda',
26
- c028: 'bonaire',
27
- c029: 'bosnia and herzegovina',
28
- c032: 'british indian ocean territory',
29
- c033: 'brunei',
30
- c034: 'bulgaria',
31
- c035: 'burkina faso',
32
- c036: 'burundi',
33
- c038: 'cameroon',
34
- c040: 'cape verde',
35
- c041: 'cayman islands',
36
- c042: 'central african republic',
37
- c043: 'chad',
38
- c046: 'christmas island',
39
- c047: 'cocos (keeling) islands',
40
- c049: 'comoros',
41
- c050: 'cook islands',
42
- c052: 'croatia',
43
- c053: 'cuba',
44
- c054: 'curacao',
45
- c055: 'cyprus',
46
- c056: 'czech republic',
47
- c057: 'democratic republic of the congo',
48
- c058: 'denmark',
49
- c064: 'equatorial guinea',
50
- c065: 'eritrea',
51
- c066: 'estonia',
52
- c068: 'falkland islands',
53
- c069: 'faroe islands',
54
- c070: 'fiji',
55
- c071: 'finland',
56
- c072: 'france',
57
- c073: 'french guiana',
58
- c074: 'french polynesia',
59
- c075: 'french southern and antarctic lands',
60
- c076: 'gabon',
61
- c077: 'georgia',
62
- c078: 'germany',
63
- c079: 'ghana',
64
- c080: 'gibraltar',
65
- c082: 'greece',
66
- c083: 'greenland',
67
- c084: 'grenada',
68
- c085: 'guadeloupe',
69
- c088: 'guinea',
70
- c089: 'guinea-bissau',
71
- c090: 'guyana',
72
- c091: 'haiti',
73
- c094: 'hungary',
74
- c095: 'iceland',
75
- c097: 'indonesia',
76
- c100: 'ireland',
77
- c102: 'italy',
78
- c103: 'ivory coast',
79
- c107: 'kazakhstan',
80
- c109: 'kiribati',
81
- c111: 'kyrgyzstan',
82
- c113: 'latvia',
83
- c114: 'lebanon',
84
- c115: 'lesotho',
85
- c116: 'liberia',
86
- c118: 'liechtenstein',
87
- c119: 'lithuania',
88
- c120: 'luxembourg',
89
- c123: 'madagascar',
90
- c124: 'malawi',
91
- c127: 'mali',
92
- c130: 'martinique',
93
- c131: 'mauritania',
94
- c132: 'mauritius',
95
- c133: 'mayotte',
96
- c135: 'micronesia',
97
- c137: 'moldova',
98
- c138: 'monaco',
99
- c139: 'mongolia',
100
- c140: 'montenegro',
101
- c141: 'montserrat',
102
- c142: 'morocco',
103
- c145: 'namibia',
104
- c146: 'nauru',
105
- c148: 'netherlands',
106
- c149: 'new caledonia',
107
- c150: 'new zealand',
108
- c152: 'niger',
109
- c153: 'nigeria',
110
- c154: 'niue',
111
- c155: 'norfolk island',
112
- c157: 'northern ireland',
113
- c158: 'northern macedonia',
114
- c160: 'norway',
115
- c162: 'pakistan',
116
- c166: 'papua new guinea',
117
- c170: 'pitcairn islands',
118
- c171: 'poland',
119
- c175: 'republic of the congo',
120
- c176: 'reunion',
121
- c177: 'romania',
122
- c178: 'russia',
123
- c179: 'rwanda',
124
- c180: 'saint helena, ascension and tristan da cunha',
125
- c181: 'saint kitts and nevis',
126
- c182: 'saint lucia',
127
- c183: 'saint pierre and miquelon',
128
- c184: 'saint vincent and the grenadines',
129
- c186: 'san marino',
130
- c187: 'sao tome and principe',
131
- c189: 'senegal',
132
- c190: 'serbia',
133
- c191: 'seychelles',
134
- c192: 'sierra leone',
135
- c194: 'sint maarten',
136
- c195: 'slovakia',
137
- c196: 'slovenia',
138
- c197: 'solomon islands',
139
- c200: 'south georgia and the south sandwich islands',
140
- c203: 'spain',
141
- c204: 'sri lanka',
142
- c206: 'suriname',
143
- c207: 'swaziland',
144
- c208: 'sweden',
145
- c209: 'switzerland',
146
- c212: 'tajikistan',
147
- c213: 'tanzania',
148
- c216: 'the gambia',
149
- c217: 'togo',
150
- c218: 'tokelau',
151
- c219: 'tonga',
152
- c221: 'tunisia',
153
- c222: 'turkey',
154
- c223: 'turkmenistan',
155
- c224: 'turks and caicos islands',
156
- c225: 'tuvalu',
157
- c226: 'uganda',
158
- c227: 'ukraine',
159
- c229: 'united kingdom',
160
- c234: 'uzbekistan',
161
- c235: 'vanuatu',
162
- c236: 'vatican city',
163
- c238: 'vietnam',
164
- c241: 'wallis and futuna',
165
- c243: 'zambia'
166
- },
167
- saturday: {
168
- c019: 'bangladesh',
169
- c059: 'djibouti',
170
- c098: 'iran',
171
- c164: 'palestine',
172
- c198: 'somalia'
173
- },
174
- sunday: {
175
- c001: 'afghanistan',
176
- c004: 'algeria',
177
- c005: 'american samoa',
178
- c010: 'antigua and barbuda',
179
- c012: 'argentina',
180
- c015: 'australia',
181
- c018: 'bahrain',
182
- c023: 'belize',
183
- c026: 'bhutan',
184
- c030: 'botswana',
185
- c031: 'brazil',
186
- c037: 'cambodia',
187
- c039: 'canada',
188
- c044: 'chile',
189
- c045: 'china',
190
- c048: 'colombia',
191
- c051: 'costa rica',
192
- c060: 'dominica',
193
- c061: 'ecuador',
194
- c062: 'egypt',
195
- c063: 'el salvador',
196
- c067: 'ethiopia',
197
- c086: 'guam',
198
- c092: 'honduras',
199
- c093: 'hong kong',
200
- c096: 'india',
201
- c099: 'iraq',
202
- c101: 'israel',
203
- c104: 'jamaica',
204
- c105: 'japan',
205
- c106: 'jordan',
206
- c108: 'kenya',
207
- c110: 'kuwait',
208
- c112: 'laos',
209
- c121: 'macao',
210
- c122: 'macau',
211
- c125: 'malaysia',
212
- c126: 'maldives',
213
- c128: 'malta',
214
- c129: 'marshall islands',
215
- c134: 'mexico',
216
- c136: 'midway atoll',
217
- c143: 'mozambique',
218
- c144: 'myanmar',
219
- c147: 'nepal',
220
- c151: 'nicaragua',
221
- c156: 'north korea',
222
- c159: 'northern mariana islands',
223
- c161: 'oman',
224
- c163: 'palau',
225
- c165: 'panama',
226
- c167: 'paraguay',
227
- c168: 'peru',
228
- c169: 'philippines',
229
- c172: 'portugal',
230
- c173: 'puerto rico',
231
- c174: 'qatar',
232
- c185: 'samoa',
233
- c188: 'saudi arabia',
234
- c193: 'singapore',
235
- c199: 'south africa',
236
- c201: 'south korea',
237
- c202: 'south sudan',
238
- c205: 'sudan',
239
- c210: 'syria',
240
- c211: 'taiwan',
241
- c214: 'thailand',
242
- c215: 'the bahamas',
243
- c220: 'trinidad and tobago',
244
- c228: 'united arab emirates',
245
- c230: 'united states of america',
246
- c232: 'uruguay',
247
- c237: 'venezuela',
248
- c239: 'virgin islands',
249
- c240: 'wake island',
250
- c242: 'yemen',
251
- c244: 'zimbabwe'
252
- }
253
- }
254
-
255
- export default {
256
- countries: () => {
257
- let arr = []
258
- Object.keys(firstDay).forEach(day => {
259
- Object.keys(firstDay[day]).forEach(country => {
260
- arr.push(firstDay[day][country])
261
- })
262
- })
263
- return arr.sort()
264
- },
265
- firstDay: () => firstDay,
266
- locations: () => loc
267
- };
@@ -1,121 +0,0 @@
1
- import c from '../data/countries.js'
2
- const firstDay = c.firstDay();
3
- const loc = c.locations();
4
-
5
- import iana from '../../zonefile/iana.js'
6
- import spacetime from 'spacetime'
7
- // const fs = require('fs');
8
-
9
-
10
- function getCountry(country) {
11
- for (let day in firstDay) {
12
- if (firstDay.hasOwnProperty(day)) {
13
- for (let key in firstDay[day]) {
14
- if (firstDay[day].hasOwnProperty(key)) {
15
- if ((key === country) || (firstDay[day][key].indexOf(country) !== -1)) {
16
- return { day: day, country: firstDay[day][key] }
17
- }
18
- }
19
- }
20
- }
21
- }
22
- for (let item in loc) {
23
- if (loc.hasOwnProperty(item) && loc[item].indexOf(country) !== -1) {
24
- return { day: 'monday', location: country }
25
- }
26
- }
27
- return {}
28
- }
29
-
30
- function getCurrent(tz) {
31
- if (!tz) {
32
- return { message: `there are problems determine time zone` }
33
- }
34
- // searches if current tz matches with iana
35
- // gets country key
36
- for (let key in iana) {
37
- if (key === tz) {
38
- if (!iana[key].ctry && !iana[key].loc) {
39
- let country = getCountry(key.substr(0, key.indexOf('/')))
40
- if (country) { return country }
41
- country = getCountry((key.substr(key.indexOf('/') + 1)).replace('_', ' '))
42
- if (country) { return country }
43
- }
44
- else if (iana[key].loc) {
45
- return getCountry(iana[key].loc)
46
- }
47
- else if (iana[key].ctry) {
48
- return getCountry(iana[key].ctry)
49
- }
50
- }
51
- }
52
- return null
53
- }
54
-
55
- function setWeekStart(value, newDay) {
56
-
57
- const a = {
58
- country: '',
59
- origin: '',
60
- assigned: '',
61
- key: '',
62
- isDay: false,
63
- isCountry: false
64
- }
65
-
66
- if (!value || !newDay) { return { message: 'missing argument' } }
67
-
68
- // check if values are valid
69
- for (let day in firstDay) {
70
- if (firstDay.hasOwnProperty(day)) {
71
- if (day === newDay.toLowerCase()) { a.isDay = true }
72
- for (let key in firstDay[day]) {
73
- if (firstDay[day][key].indexOf(value.toLowerCase()) !== -1) {
74
- a.origin = day;
75
- a.assigned = newDay;
76
- a.country = firstDay[day][key];
77
- a.key = key;
78
- a.isCountry = true
79
- }
80
- }
81
- }
82
- }
83
-
84
- if (!a.isDay || !a.isCountry) {
85
- return { message: 'incorrect day or country name' }
86
- }
87
-
88
- // when both entries are valid save new JSON
89
- delete firstDay[a.origin][a.key];
90
- firstDay[newDay][a.key] = a.country;
91
- // const data = JSON.stringify(firstDay);
92
- // fs.writeFile('../data/countries.json', data);
93
-
94
- return {
95
- country: a.country,
96
- origin: a.origin,
97
- assigned: a.assigned
98
- };
99
- }
100
-
101
- function getWeekStart(country = '') {
102
- // checks function argument and sets default value
103
- let tz
104
- if (!country || typeof country !== 'string') {
105
- country = null
106
- tz = spacetime.now().tz
107
- }
108
- if (!country) {
109
- return getCurrent(tz);
110
- } else if (country) {
111
- let first = getCountry((country.toLowerCase()).trim())
112
- if (first) { return first }
113
- else { return getWeekStart() }
114
- }
115
- return null
116
- }
117
-
118
- export {
119
- getWeekStart,
120
- setWeekStart
121
- }
@@ -1,56 +0,0 @@
1
- import test from 'tape'
2
- import { getWeekStart as weekStart } from '../src/input/weekStart.js'
3
-
4
- test('week by country returns values, when no or falsy argument is supplied', t => {
5
- t.notEqual(weekStart(), null)
6
- t.notEqual(weekStart(), undefined)
7
- t.notEqual(weekStart(12), null)
8
- t.notEqual(weekStart(12), undefined)
9
-
10
- t.notEqual(weekStart(null), null)
11
- t.notEqual(weekStart(null), undefined)
12
- t.notEqual(weekStart(''), null)
13
- t.notEqual(weekStart(''), undefined)
14
-
15
- t.notEqual(weekStart(undefined), null)
16
- t.notEqual(weekStart(undefined), undefined)
17
- t.notEqual(weekStart('abc'), null)
18
- t.notEqual(weekStart('abc'), undefined)
19
- t.end()
20
- })
21
-
22
- test('JSON values are string and not empty', t => {
23
- t.equal(typeof weekStart().day, 'string')
24
- t.notEqual(weekStart().day, '')
25
- t.equal(typeof weekStart().country, 'string')
26
- t.notEqual(weekStart().country, '')
27
- t.end()
28
- })
29
-
30
- test('when supplied full coutry name returns day and country', t => {
31
- t.equal(weekStart('canada').day, 'sunday')
32
- t.equal(weekStart('canada').country, 'canada')
33
- t.end()
34
- })
35
-
36
- test('when supplied partial coutry name returns day and country', t => {
37
- t.equal(weekStart('united arab emirates').day, 'sunday')
38
- t.equal(weekStart('emirates').country, 'united arab emirates')
39
- t.end()
40
- })
41
-
42
- test('country name can be in lower case, upper case or camel case', t => {
43
- t.equal(weekStart('cana').day, 'sunday')
44
- t.equal(weekStart('nada').country, 'grenada')
45
- t.notEqual(weekStart('nada').country, 'canada')
46
- // finds first occourance of string 'nada' in JSON
47
- t.equal(weekStart('CANADA').day, 'sunday')
48
- t.equal(weekStart('Canada').country, 'canada')
49
- // it's located in array under key "monday" for
50
- // grenada and after that appears located in
51
- // canada under key "sunday"
52
- t.equal(weekStart('CaNa').day, 'sunday')
53
- t.equal(weekStart('nAdA').country, 'grenada')
54
- t.notEqual(weekStart('nAdA').country, 'canada')
55
- t.end()
56
- })