encoding-lite.d.ts 2.5 KB

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