Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Replaceable.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _jestGetType = require('jest-get-type');
  7. function _defineProperty(obj, key, value) {
  8. if (key in obj) {
  9. Object.defineProperty(obj, key, {
  10. value: value,
  11. enumerable: true,
  12. configurable: true,
  13. writable: true
  14. });
  15. } else {
  16. obj[key] = value;
  17. }
  18. return obj;
  19. }
  20. const supportTypes = ['map', 'array', 'object'];
  21. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  22. class Replaceable {
  23. constructor(object) {
  24. _defineProperty(this, 'object', void 0);
  25. _defineProperty(this, 'type', void 0);
  26. this.object = object;
  27. this.type = (0, _jestGetType.getType)(object);
  28. if (!supportTypes.includes(this.type)) {
  29. throw new Error(`Type ${this.type} is not support in Replaceable!`);
  30. }
  31. }
  32. static isReplaceable(obj1, obj2) {
  33. const obj1Type = (0, _jestGetType.getType)(obj1);
  34. const obj2Type = (0, _jestGetType.getType)(obj2);
  35. return obj1Type === obj2Type && supportTypes.includes(obj1Type);
  36. }
  37. forEach(cb) {
  38. if (this.type === 'object') {
  39. const descriptors = Object.getOwnPropertyDescriptors(this.object);
  40. [
  41. ...Object.keys(descriptors),
  42. ...Object.getOwnPropertySymbols(descriptors)
  43. ] //@ts-expect-error because typescript do not support symbol key in object
  44. //https://github.com/microsoft/TypeScript/issues/1863
  45. .filter(key => descriptors[key].enumerable)
  46. .forEach(key => {
  47. cb(this.object[key], key, this.object);
  48. });
  49. } else {
  50. this.object.forEach(cb);
  51. }
  52. }
  53. get(key) {
  54. if (this.type === 'map') {
  55. return this.object.get(key);
  56. }
  57. return this.object[key];
  58. }
  59. set(key, value) {
  60. if (this.type === 'map') {
  61. this.object.set(key, value);
  62. } else {
  63. this.object[key] = value;
  64. }
  65. }
  66. }
  67. /* eslint-enable */
  68. exports.default = Replaceable;