Force Matrix m.notices to be unchanged events
This commit is contained in:
@@ -153,6 +153,26 @@ function howOldUnbridgedMessage(oldTimestamp, newTimestamp) {
|
||||
return dateDisplay
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the input, removing items that don't pass the filter. Returns the items that didn't pass.
|
||||
* @param {T[]} xs
|
||||
* @param {(x: T, i?: number) => any} fn
|
||||
* @template T
|
||||
* @returns T[]
|
||||
*/
|
||||
function filterTo(xs, fn) {
|
||||
/** @type {T[]} */
|
||||
const filtered = []
|
||||
for (let i = xs.length-1; i >= 0; i--) {
|
||||
const x = xs[i]
|
||||
if (!fn(x, i)) {
|
||||
filtered.unshift(x)
|
||||
xs.splice(i, 1)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
module.exports.getPermissions = getPermissions
|
||||
module.exports.hasPermission = hasPermission
|
||||
module.exports.hasSomePermissions = hasSomePermissions
|
||||
@@ -163,3 +183,4 @@ module.exports.snowflakeToTimestampExact = snowflakeToTimestampExact
|
||||
module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact
|
||||
module.exports.getPublicUrlForCdn = getPublicUrlForCdn
|
||||
module.exports.howOldUnbridgedMessage = howOldUnbridgedMessage
|
||||
module.exports.filterTo = filterTo
|
||||
|
||||
@@ -192,3 +192,10 @@ test("how old: hours", t => {
|
||||
test("how old: days", t => {
|
||||
t.equal(utils.howOldUnbridgedMessage("2024-01-01", "2025-01-01"), "a 366-day-old unbridged message")
|
||||
})
|
||||
|
||||
test("filterTo: works", t => {
|
||||
const fruit = ["apple", "banana", "apricot"]
|
||||
const rest = utils.filterTo(fruit, f => f[0] === "b")
|
||||
t.deepEqual(fruit, ["banana"])
|
||||
t.deepEqual(rest, ["apple", "apricot"])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user