extensions.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * **!Do not construct directly!**
  3. *
  4. * **!Only static methods because it gets serialized!**
  5. *
  6. * This represents the "canonical" version for an extension identifier. Extension ids
  7. * have to be case-insensitive (due to the marketplace), but we must ensure case
  8. * preservation because the extension API is already public at this time.
  9. *
  10. * For example, given an extension with the publisher `"Hello"` and the name `"World"`,
  11. * its canonical extension identifier is `"Hello.World"`. This extension could be
  12. * referenced in some other extension's dependencies using the string `"hello.world"`.
  13. *
  14. * To make matters more complicated, an extension can optionally have an UUID. When two
  15. * extensions have the same UUID, they are considered equal even if their identifier is different.
  16. */
  17. export class ExtensionIdentifier {
  18. constructor(value) {
  19. this.value = value;
  20. this._lower = value.toLowerCase();
  21. }
  22. /**
  23. * Gives the value by which to index (for equality).
  24. */
  25. static toKey(id) {
  26. if (typeof id === 'string') {
  27. return id.toLowerCase();
  28. }
  29. return id._lower;
  30. }
  31. }