source: imaps-frontend/node_modules/side-channel/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.2 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4var inspect = require('object-inspect');
5var getSideChannelList = require('side-channel-list');
6var getSideChannelMap = require('side-channel-map');
7var getSideChannelWeakMap = require('side-channel-weakmap');
8
9var makeChannel = getSideChannelWeakMap || getSideChannelMap || getSideChannelList;
10
11/** @type {import('.')} */
12module.exports = function getSideChannel() {
13 /** @typedef {ReturnType<typeof getSideChannel>} Channel */
14
15 /** @type {Channel | undefined} */ var $channelData;
16
17 /** @type {Channel} */
18 var channel = {
19 assert: function (key) {
20 if (!channel.has(key)) {
21 throw new $TypeError('Side channel does not contain ' + inspect(key));
22 }
23 },
24 'delete': function (key) {
25 return !!$channelData && $channelData['delete'](key);
26 },
27 get: function (key) {
28 return $channelData && $channelData.get(key);
29 },
30 has: function (key) {
31 return !!$channelData && $channelData.has(key);
32 },
33 set: function (key, value) {
34 if (!$channelData) {
35 $channelData = makeChannel();
36 }
37
38 $channelData.set(key, value);
39 }
40 };
41 // @ts-expect-error TODO: figure out why this is erroring
42 return channel;
43};
Note: See TracBrowser for help on using the repository browser.