-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecord.js
35 lines (29 loc) · 805 Bytes
/
Record.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
if (! (globalThis.Record instanceof Function)) {
function Record(obj) {
if (new.target === Record) {
throw new TypeError('Record is not a constructor');
}
const record = Object.create(Record.prototype);
Object.defineProperties(record, Object.fromEntries(Object.entries(obj).map(([key, value]) => [
key, {
'enumerable': true,
'configurable': false,
'writable': false,
'value': value,
}
])));
Object.freeze(record);
return record;
}
Record.prototype.constructor = Record;
Object.defineProperty(Record.prototype, Symbol.toStringTag, {
value: 'Record',
enumerable: true,
configurable: false,
writable: false,
});
Record.fromEntries = function fromEntries(entries) {
return Record(Object.fromEntries(entries));
};
globalThis.Record = Record;
}