mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 16:03:33 +09:00
first
This commit is contained in:
48
sample/dev/talk/bundle/mithril-2.2.2/util/censor.js
Normal file
48
sample/dev/talk/bundle/mithril-2.2.2/util/censor.js
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict"
|
||||
|
||||
// Note: this is mildly perf-sensitive.
|
||||
//
|
||||
// It does *not* use `delete` - dynamic `delete`s usually cause objects to bail
|
||||
// out into dictionary mode and just generally cause a bunch of optimization
|
||||
// issues within engines.
|
||||
//
|
||||
// Ideally, I would've preferred to do this, if it weren't for the optimization
|
||||
// issues:
|
||||
//
|
||||
// ```js
|
||||
// const hasOwn = require("./hasOwn")
|
||||
// const magic = [
|
||||
// "key", "oninit", "oncreate", "onbeforeupdate", "onupdate",
|
||||
// "onbeforeremove", "onremove",
|
||||
// ]
|
||||
// module.exports = (attrs, extras) => {
|
||||
// const result = Object.assign(Object.create(null), attrs)
|
||||
// for (const key of magic) delete result[key]
|
||||
// if (extras != null) for (const key of extras) delete result[key]
|
||||
// return result
|
||||
// }
|
||||
// ```
|
||||
|
||||
var hasOwn = require("./hasOwn")
|
||||
// Words in RegExp literals are sometimes mangled incorrectly by the internal bundler, so use RegExp().
|
||||
var magic = new RegExp("^(?:key|oninit|oncreate|onbeforeupdate|onupdate|onbeforeremove|onremove)$")
|
||||
|
||||
module.exports = function(attrs, extras) {
|
||||
var result = {}
|
||||
|
||||
if (extras != null) {
|
||||
for (var key in attrs) {
|
||||
if (hasOwn.call(attrs, key) && !magic.test(key) && extras.indexOf(key) < 0) {
|
||||
result[key] = attrs[key]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var key in attrs) {
|
||||
if (hasOwn.call(attrs, key) && !magic.test(key)) {
|
||||
result[key] = attrs[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user