-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcensor.js
42 lines (34 loc) · 1.2 KB
/
censor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Use this to filter out any of Mithril's magic attributes while still keeping
* your interfaces as unrestrictive as possible.
*/
;(function () {
"use strict"
if (typeof module === "object" && module && module.exports) {
module.exports = censor
} else if (typeof m !== "function") {
throw new Error("Mithril must be loaded first!")
} else {
(m.helpers || (m.helpers = {})).censor = censor
}
// Note: this avoids as much allocation and overhead as possible.
var hasOwn = {}.hasOwnProperty
return function censor(attrs, extras) {
var exclude = [
"key", "oninit", "oncreate", "onbeforeupdate", "onupdate",
"onbeforeremove", "onremove",
]
if (extras != null) exclude.push.apply(exclude, extras)
for (let i = 0; i < exclude.length; i++) {
if (hasOwn.call(attrs, exclude[i])) {
var result = {}
for (var key in attrs) {
if (hasOwn.call(attrs, key) && !exclude.includes(key)) {
result[key] = attrs[key]
}
}
return result
}
}
return attrs
})()