@rhinostone/swig 2.0.0-alpha.2 → 2.0.0-alpha.4
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/.changes/v2.0.0-alpha.4.md +10 -0
- package/HISTORY.md +11 -0
- package/dist/swig.js +59 -8
- package/dist/swig.min.js +2 -2
- package/dist/swig.min.js.map +1 -1
- package/lib/dateformatter.js +11 -198
- package/lib/swig.js +2 -2
- package/lib/tags/for.js +8 -0
- package/package.json +2 -1
package/lib/dateformatter.js
CHANGED
|
@@ -1,198 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
DateZ is licensed under the MIT License:
|
|
15
|
-
Copyright (c) 2011 Tomo Universalis (http://tomouniversalis.com)
|
|
16
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
|
-
*/
|
|
20
|
-
exports.tzOffset = 0;
|
|
21
|
-
exports.DateZ = function () {
|
|
22
|
-
var members = {
|
|
23
|
-
'default': ['getUTCDate', 'getUTCDay', 'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth', 'getUTCSeconds', 'toISOString', 'toGMTString', 'toUTCString', 'valueOf', 'getTime'],
|
|
24
|
-
z: ['getDate', 'getDay', 'getFullYear', 'getHours', 'getMilliseconds', 'getMinutes', 'getMonth', 'getSeconds', 'getYear', 'toDateString', 'toLocaleDateString', 'toLocaleTimeString']
|
|
25
|
-
},
|
|
26
|
-
d = this;
|
|
27
|
-
|
|
28
|
-
d.date = d.dateZ = (arguments.length > 1) ? new Date(Date.UTC.apply(Date, arguments) + ((new Date()).getTimezoneOffset() * 60000)) : (arguments.length === 1) ? new Date(new Date(arguments['0'])) : new Date();
|
|
29
|
-
|
|
30
|
-
d.timezoneOffset = d.dateZ.getTimezoneOffset();
|
|
31
|
-
|
|
32
|
-
utils.each(members.z, function (name) {
|
|
33
|
-
d[name] = function () {
|
|
34
|
-
return d.dateZ[name]();
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
utils.each(members['default'], function (name) {
|
|
38
|
-
d[name] = function () {
|
|
39
|
-
return d.date[name]();
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
this.setTimezoneOffset(exports.tzOffset);
|
|
44
|
-
};
|
|
45
|
-
exports.DateZ.prototype = {
|
|
46
|
-
getTimezoneOffset: function () {
|
|
47
|
-
return this.timezoneOffset;
|
|
48
|
-
},
|
|
49
|
-
setTimezoneOffset: function (offset) {
|
|
50
|
-
this.timezoneOffset = offset;
|
|
51
|
-
this.dateZ = new Date(this.date.getTime() + this.date.getTimezoneOffset() * 60000 - this.timezoneOffset * 60000);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Day
|
|
57
|
-
exports.d = function (input) {
|
|
58
|
-
return (input.getDate() < 10 ? '0' : '') + input.getDate();
|
|
59
|
-
};
|
|
60
|
-
exports.D = function (input) {
|
|
61
|
-
return _days.abbr[input.getDay()];
|
|
62
|
-
};
|
|
63
|
-
exports.j = function (input) {
|
|
64
|
-
return input.getDate();
|
|
65
|
-
};
|
|
66
|
-
exports.l = function (input) {
|
|
67
|
-
return _days.full[input.getDay()];
|
|
68
|
-
};
|
|
69
|
-
exports.N = function (input) {
|
|
70
|
-
var d = input.getDay();
|
|
71
|
-
return (d >= 1) ? d : 7;
|
|
72
|
-
};
|
|
73
|
-
exports.S = function (input) {
|
|
74
|
-
var d = input.getDate();
|
|
75
|
-
return (d % 10 === 1 && d !== 11 ? 'st' : (d % 10 === 2 && d !== 12 ? 'nd' : (d % 10 === 3 && d !== 13 ? 'rd' : 'th')));
|
|
76
|
-
};
|
|
77
|
-
exports.w = function (input) {
|
|
78
|
-
return input.getDay();
|
|
79
|
-
};
|
|
80
|
-
exports.z = function (input, offset, abbr) {
|
|
81
|
-
var year = input.getFullYear(),
|
|
82
|
-
e = new exports.DateZ(year, input.getMonth(), input.getDate(), 12, 0, 0),
|
|
83
|
-
d = new exports.DateZ(year, 0, 1, 12, 0, 0);
|
|
84
|
-
|
|
85
|
-
e.setTimezoneOffset(offset, abbr);
|
|
86
|
-
d.setTimezoneOffset(offset, abbr);
|
|
87
|
-
return Math.round((e - d) / 86400000);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Week
|
|
91
|
-
exports.W = function (input) {
|
|
92
|
-
var target = new Date(input.valueOf()),
|
|
93
|
-
dayNr = (input.getDay() + 6) % 7,
|
|
94
|
-
fThurs;
|
|
95
|
-
|
|
96
|
-
target.setDate(target.getDate() - dayNr + 3);
|
|
97
|
-
fThurs = target.valueOf();
|
|
98
|
-
target.setMonth(0, 1);
|
|
99
|
-
if (target.getDay() !== 4) {
|
|
100
|
-
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return 1 + Math.ceil((fThurs - target) / 604800000);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// Month
|
|
107
|
-
exports.F = function (input) {
|
|
108
|
-
return _months.full[input.getMonth()];
|
|
109
|
-
};
|
|
110
|
-
exports.m = function (input) {
|
|
111
|
-
return (input.getMonth() < 9 ? '0' : '') + (input.getMonth() + 1);
|
|
112
|
-
};
|
|
113
|
-
exports.M = function (input) {
|
|
114
|
-
return _months.abbr[input.getMonth()];
|
|
115
|
-
};
|
|
116
|
-
exports.n = function (input) {
|
|
117
|
-
return input.getMonth() + 1;
|
|
118
|
-
};
|
|
119
|
-
exports.t = function (input) {
|
|
120
|
-
return 32 - (new Date(input.getFullYear(), input.getMonth(), 32).getDate());
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Year
|
|
124
|
-
exports.L = function (input) {
|
|
125
|
-
return new Date(input.getFullYear(), 1, 29).getDate() === 29;
|
|
126
|
-
};
|
|
127
|
-
exports.o = function (input) {
|
|
128
|
-
var target = new Date(input.valueOf());
|
|
129
|
-
target.setDate(target.getDate() - ((input.getDay() + 6) % 7) + 3);
|
|
130
|
-
return target.getFullYear();
|
|
131
|
-
};
|
|
132
|
-
exports.Y = function (input) {
|
|
133
|
-
return input.getFullYear();
|
|
134
|
-
};
|
|
135
|
-
exports.y = function (input) {
|
|
136
|
-
return (input.getFullYear().toString()).substr(2);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Time
|
|
140
|
-
exports.a = function (input) {
|
|
141
|
-
return input.getHours() < 12 ? 'am' : 'pm';
|
|
142
|
-
};
|
|
143
|
-
exports.A = function (input) {
|
|
144
|
-
return input.getHours() < 12 ? 'AM' : 'PM';
|
|
145
|
-
};
|
|
146
|
-
exports.B = function (input) {
|
|
147
|
-
var hours = input.getUTCHours(), beats;
|
|
148
|
-
hours = (hours === 23) ? 0 : hours + 1;
|
|
149
|
-
beats = Math.abs(((((hours * 60) + input.getUTCMinutes()) * 60) + input.getUTCSeconds()) / 86.4).toFixed(0);
|
|
150
|
-
return ('000'.concat(beats).slice(beats.length));
|
|
151
|
-
};
|
|
152
|
-
exports.g = function (input) {
|
|
153
|
-
var h = input.getHours();
|
|
154
|
-
return h === 0 ? 12 : (h > 12 ? h - 12 : h);
|
|
155
|
-
};
|
|
156
|
-
exports.G = function (input) {
|
|
157
|
-
return input.getHours();
|
|
158
|
-
};
|
|
159
|
-
exports.h = function (input) {
|
|
160
|
-
var h = input.getHours();
|
|
161
|
-
return ((h < 10 || (12 < h && 22 > h)) ? '0' : '') + ((h < 12) ? h : h - 12);
|
|
162
|
-
};
|
|
163
|
-
exports.H = function (input) {
|
|
164
|
-
var h = input.getHours();
|
|
165
|
-
return (h < 10 ? '0' : '') + h;
|
|
166
|
-
};
|
|
167
|
-
exports.i = function (input) {
|
|
168
|
-
var m = input.getMinutes();
|
|
169
|
-
return (m < 10 ? '0' : '') + m;
|
|
170
|
-
};
|
|
171
|
-
exports.s = function (input) {
|
|
172
|
-
var s = input.getSeconds();
|
|
173
|
-
return (s < 10 ? '0' : '') + s;
|
|
174
|
-
};
|
|
175
|
-
//u = function () { return ''; },
|
|
176
|
-
|
|
177
|
-
// Timezone
|
|
178
|
-
//e = function () { return ''; },
|
|
179
|
-
//I = function () { return ''; },
|
|
180
|
-
exports.O = function (input) {
|
|
181
|
-
var tz = input.getTimezoneOffset();
|
|
182
|
-
return (tz < 0 ? '-' : '+') + (tz / 60 < 10 ? '0' : '') + Math.abs((tz / 60)) + '00';
|
|
183
|
-
};
|
|
184
|
-
//T = function () { return ''; },
|
|
185
|
-
exports.Z = function (input) {
|
|
186
|
-
return input.getTimezoneOffset() * 60;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// Full Date/Time
|
|
190
|
-
exports.c = function (input) {
|
|
191
|
-
return input.toISOString();
|
|
192
|
-
};
|
|
193
|
-
exports.r = function (input) {
|
|
194
|
-
return input.toUTCString();
|
|
195
|
-
};
|
|
196
|
-
exports.U = function (input) {
|
|
197
|
-
return input.getTime() / 1000;
|
|
198
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Phase 3 carve bridge — dateformatter moved to @rhinostone/swig-core.
|
|
3
|
+
*
|
|
4
|
+
* This shim re-exports the swig-core module so every in-repo consumer
|
|
5
|
+
* (`require('./dateformatter')` from lib/swig.js and lib/filters.js)
|
|
6
|
+
* keeps resolving to the same exports object. The mutable `tzOffset`
|
|
7
|
+
* binding set by `swig.setDefaultTZOffset` is the same property on
|
|
8
|
+
* both paths via Node's module cache.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = require('@rhinostone/swig-core/lib/dateformatter');
|
package/lib/swig.js
CHANGED
|
@@ -9,11 +9,11 @@ var utils = require('./utils'),
|
|
|
9
9
|
/**
|
|
10
10
|
* Swig version number as a string.
|
|
11
11
|
* @example
|
|
12
|
-
* if (swig.version === "2.0.0-alpha.
|
|
12
|
+
* if (swig.version === "2.0.0-alpha.4") { ... }
|
|
13
13
|
*
|
|
14
14
|
* @type {String}
|
|
15
15
|
*/
|
|
16
|
-
exports.version = "2.0.0-alpha.
|
|
16
|
+
exports.version = "2.0.0-alpha.4";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Swig Options Object. This object can be passed to many of the API-level Swig methods to control various aspects of the engine. All keys are optional.
|
package/lib/tags/for.js
CHANGED
|
@@ -104,6 +104,14 @@ exports.parse = function (str, line, parser, types) {
|
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// CVE-2023-25345: the lexer folds dotted paths into a single VAR token
|
|
108
|
+
// (e.g. `foo.__proto__` matches as one VAR with .match === "foo.__proto__"),
|
|
109
|
+
// so the _dangerousProps indexOf check below misses the prototype segment.
|
|
110
|
+
// Loop variables bind to `_ctx.<name>` — bare identifiers only.
|
|
111
|
+
if (token.match.indexOf('.') !== -1) {
|
|
112
|
+
throw new Error('Loop variable "' + token.match + '" must be a bare identifier in "for" tag on line ' + line + '.');
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
// CVE-2023-25345: block prototype-chain property names as loop variables
|
|
108
116
|
if (_dangerousProps.indexOf(token.match) !== -1) {
|
|
109
117
|
throw new Error('Unsafe loop variable "' + token.match + '" is not allowed (CVE-2023-25345) on line ' + line + '.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinostone/swig",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"description": "A simple, powerful, and extendable templating engine for node.js and browsers, similar to Django, Jinja2, and Twig.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"template",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"Rhinostone <contact@gina.io>"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@rhinostone/swig-core": "2.0.0-alpha.4",
|
|
24
25
|
"terser": "^5.46.1",
|
|
25
26
|
"yargs": "^17.7.2"
|
|
26
27
|
},
|