-
Notifications
You must be signed in to change notification settings - Fork 14
/
base.ts
28 lines (26 loc) · 1.16 KB
/
base.ts
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
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Error } from '@hackbg/oops'
import { Console, Logged, bold, colors } from '@hackbg/logs'
class FadromaError extends Error {}
export { FadromaError as Error }
/** Helper for assigning only allowed properties of value object:
* - safe, can't set unsupported properties
* - no need to state property name thrice
* - doesn't leave `undefined`s */
export function assign <T extends {}> (
object: T, properties: Partial<T> & any = {}, allowed: Array<keyof T>|Set<keyof T>
) {
if (!allowed || (typeof allowed !== 'object')) {
throw new Error(`no list of allowed properties when constructing ${object.constructor.name}`)
}
for (const property of allowed) {
if (property in properties) object[property] = properties[property]
}
}
export { Console, Logged, bold, colors, randomColor, timestamp } from '@hackbg/logs'
export * from '@hackbg/into'
export * from '@hackbg/hide'
export * from '@hackbg/4mat'
export * from '@hackbg/dump'