mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 07:13:46 +09:00
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
"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
|
|
}
|