encoding-lite.d.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * The exact same exports as `@exodus/bytes/encoding.js` are also exported as
  3. * `@exodus/bytes/encoding-lite.js`, with the difference that the lite version does not load
  4. * multi-byte `TextDecoder` encodings by default to reduce bundle size ~12x.
  5. *
  6. * ```js
  7. * import { TextDecoder, TextEncoder } from '@exodus/bytes/encoding-lite.js'
  8. * import { TextDecoderStream, TextEncoderStream } from '@exodus/bytes/encoding-lite.js' // Requires Streams
  9. * import { isomorphicDecode, isomorphicEncode } from '@exodus/bytes/encoding-lite.js'
  10. *
  11. * // Hooks for standards
  12. * import { getBOMEncoding, legacyHookDecode, labelToName, normalizeEncoding } from '@exodus/bytes/encoding-lite.js'
  13. * ```
  14. *
  15. * The only affected encodings are: `gbk`, `gb18030`, `big5`, `euc-jp`, `iso-2022-jp`, `shift_jis`
  16. * and their [labels](https://encoding.spec.whatwg.org/#names-and-labels) when used with `TextDecoder`.
  17. *
  18. * Legacy single-byte encodingds are loaded by default in both cases.
  19. *
  20. * `TextEncoder` and hooks for standards (including `labelToName` / `normalizeEncoding`) do not have any behavior
  21. * differences in the lite version and support full range if inputs.
  22. *
  23. * To avoid inconsistencies, the exported classes and methods are exactly the same objects.
  24. *
  25. * ```console
  26. * > lite = require('@exodus/bytes/encoding-lite.js')
  27. * [Module: null prototype] {
  28. * TextDecoder: [class TextDecoder],
  29. * TextDecoderStream: [class TextDecoderStream],
  30. * TextEncoder: [class TextEncoder],
  31. * TextEncoderStream: [class TextEncoderStream],
  32. * getBOMEncoding: [Function: getBOMEncoding],
  33. * labelToName: [Function: labelToName],
  34. * legacyHookDecode: [Function: legacyHookDecode],
  35. * normalizeEncoding: [Function: normalizeEncoding]
  36. * }
  37. * > new lite.TextDecoder('big5').decode(Uint8Array.of(0x25))
  38. * Uncaught:
  39. * Error: Legacy multi-byte encodings are disabled in /encoding-lite.js, use /encoding.js for full encodings range support
  40. *
  41. * > full = require('@exodus/bytes/encoding.js')
  42. * [Module: null prototype] {
  43. * TextDecoder: [class TextDecoder],
  44. * TextDecoderStream: [class TextDecoderStream],
  45. * TextEncoder: [class TextEncoder],
  46. * TextEncoderStream: [class TextEncoderStream],
  47. * getBOMEncoding: [Function: getBOMEncoding],
  48. * labelToName: [Function: labelToName],
  49. * legacyHookDecode: [Function: legacyHookDecode],
  50. * normalizeEncoding: [Function: normalizeEncoding]
  51. * }
  52. * > full.TextDecoder === lite.TextDecoder
  53. * true
  54. * > new full.TextDecoder('big5').decode(Uint8Array.of(0x25))
  55. * '%'
  56. * > new lite.TextDecoder('big5').decode(Uint8Array.of(0x25))
  57. * '%'
  58. * ```
  59. *
  60. * @module @exodus/bytes/encoding-lite.js
  61. */
  62. export * from './encoding.js'