spacetime-week-start 0.1.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/README.md +109 -0
- package/_version.js +1 -0
- package/builds/spacetime-week-start.js +6447 -0
- package/builds/spacetime-week-start.min.js +1 -0
- package/builds/spacetime-week-start.mjs +6439 -0
- package/package.json +45 -0
- package/rollup.config.js +53 -0
- package/scratch.js +6 -0
- package/src/data/countries.js +267 -0
- package/src/index.js +8 -0
- package/src/input/weekStart.js +121 -0
- package/test/basic.test.js +56 -0
- package/types/types.d.ts +202 -0
- package/weekStart-demo.js +47 -0
- package/zonefile/iana.js +2501 -0
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spacetime-week-start",
|
|
3
|
+
"description": "calculate start-of-week",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"unpkg": "builds/spacetime-week.min.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./builds/spacetime-week.js",
|
|
12
|
+
"import": "./builds/spacetime-week.mjs",
|
|
13
|
+
"default": "./builds/spacetime-week.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
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"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"watch": "amble scratch.js",
|
|
24
|
+
"test": "TESTENV=dev tape ./test/**/*.test.js | tap-dancer",
|
|
25
|
+
"build": "rollup -c --silent"
|
|
26
|
+
},
|
|
27
|
+
"prettier": {
|
|
28
|
+
"trailingComma": "none",
|
|
29
|
+
"tabWidth": 2,
|
|
30
|
+
"semi": false,
|
|
31
|
+
"singleQuote": true,
|
|
32
|
+
"printWidth": 100
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"amble": "1.3.0",
|
|
36
|
+
"shelljs": "0.8.4",
|
|
37
|
+
"tap-dancer": "0.3.4",
|
|
38
|
+
"tape": "5.4.0",
|
|
39
|
+
"terser": "5.10.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"spacetime": "^5.8.2"
|
|
43
|
+
},
|
|
44
|
+
"licence": "MIT"
|
|
45
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import commonjs from 'rollup-plugin-commonjs'
|
|
2
|
+
import json from 'rollup-plugin-json'
|
|
3
|
+
import { terser } from 'rollup-plugin-terser'
|
|
4
|
+
import resolve from 'rollup-plugin-node-resolve'
|
|
5
|
+
import sizeCheck from 'rollup-plugin-filesize-check'
|
|
6
|
+
import { version } from './package.json'
|
|
7
|
+
|
|
8
|
+
console.log('\n 📦 - running rollup..\n')
|
|
9
|
+
|
|
10
|
+
let name = 'spacetime-week-start'
|
|
11
|
+
const banner = `/* spencermountain/${name} ` + version + ' Apache 2.0 */'
|
|
12
|
+
|
|
13
|
+
export default [
|
|
14
|
+
{
|
|
15
|
+
input: 'src/index.js',
|
|
16
|
+
output: [{ banner: banner, file: `builds/${name}.mjs`, format: 'esm' }],
|
|
17
|
+
plugins: [
|
|
18
|
+
resolve(),
|
|
19
|
+
json(),
|
|
20
|
+
commonjs(),
|
|
21
|
+
sizeCheck({ expect: 147, warn: 10 })
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
input: 'src/index.js',
|
|
26
|
+
output: [
|
|
27
|
+
{
|
|
28
|
+
banner: banner,
|
|
29
|
+
file: `builds/${name}.js`,
|
|
30
|
+
format: 'umd',
|
|
31
|
+
sourcemap: false,
|
|
32
|
+
name: 'weekStart'
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
plugins: [
|
|
36
|
+
resolve(),
|
|
37
|
+
json(),
|
|
38
|
+
commonjs(),
|
|
39
|
+
sizeCheck({ expect: 159, warn: 10 })
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
input: 'src/index.js',
|
|
44
|
+
output: [{ banner: banner, file: `builds/${name}.min.js`, format: 'umd', name: 'weekStart' }],
|
|
45
|
+
plugins: [
|
|
46
|
+
resolve(),
|
|
47
|
+
json(),
|
|
48
|
+
commonjs(),
|
|
49
|
+
terser(),
|
|
50
|
+
sizeCheck({ expect: 79, warn: 10 })
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
]
|
package/scratch.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
})
|