• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inclusion-numerique / coop-mediation-numerique / ac5796ce-2060-42b0-8ac2-9a33dfeae3db

22 May 2026 08:08AM UTC coverage: 9.999% (+3.0%) from 6.955%
ac5796ce-2060-42b0-8ac2-9a33dfeae3db

Pull #499

circleci

web-flow
chore(deps): bump @tootallnate/once from 2.0.0 to 2.0.1

Bumps [@tootallnate/once](https://github.com/TooTallNate/once) from 2.0.0 to 2.0.1.
- [Release notes](https://github.com/TooTallNate/once/releases)
- [Changelog](https://github.com/TooTallNate/once/blob/v2.0.1/CHANGELOG.md)
- [Commits](https://github.com/TooTallNate/once/compare/2.0.0...v2.0.1)

---
updated-dependencies:
- dependency-name: "@tootallnate/once"
  dependency-version: 2.0.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #499: chore(deps): bump @tootallnate/once from 2.0.0 to 2.0.1

689 of 10876 branches covered (6.34%)

Branch coverage included in aggregate %.

2112 of 17137 relevant lines covered (12.32%)

1.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/apps/web/src/utils/encodeSerializableState.ts
1
import pako from 'pako'
2
import superjson from 'superjson'
3

4
/**
5
 * Utility functions to encode and decode form state for safe transmission via URL.
6
 *
7
 * This module provides two functions, `encodeSerializableState` and `decodeSerializableState`,
8
 * which are intended to be used for serializing form state to a compressed string
9
 * and deserializing it back to its original form. This is particularly useful for passing
10
 * non-sensitive form data through URLs, ensuring the data remains unreadable to users.
11
 *
12
 * Example use case:
13
 * - Encode form state into a compressed string and append it as a query parameter in a URL.
14
 * - Decode the compressed string from the URL to prefill the form with the original data.
15
 */
16

17
export type EncodedState<T> = string & { __encodedStateType: T }
18

19
/**
20
 * Converts a Uint8Array to a url safe Base64 string.
21
 */
22
const uint8ArrayToBase64 = (uint8Array: Uint8Array): string => {
×
23
  const binaryString = [...uint8Array]
×
24
    .map((byte) => String.fromCodePoint(byte))
×
25
    .join('')
26
  return btoa(binaryString)
27
    .replaceAll('+', '-') // Replace "+" with "-"
28
    .replaceAll('/', '_') // Replace "/" with "_"
29
    .replace(/=+$/, '') // Remove "=" padding
30
}
31

32
/**
33
 * Converts a url safe Base64 string back to a Uint8Array.
34
 */
35
const base64ToUint8Array = (base64String: string): Uint8Array => {
×
36
  const binaryString = atob(
×
37
    base64String
38
      .replaceAll('-', '+') // Replace "-" with "+"
39
      .replaceAll('_', '/'), // Replace "_" with "/"
40
  )
41
  return Uint8Array.from(binaryString, (char) => {
×
42
    const code = char.codePointAt(0)
×
43
    if (code === undefined) {
×
44
      throw new Error('Invalid character in Base64 string')
×
45
    }
46
    return code
×
47
  })
48
}
49

50
export const encodeSerializableState = <T>(state: T): EncodedState<T> => {
×
51
  const jsonString = superjson.stringify(state)
×
52
  const compressed = pako.deflate(jsonString)
×
53

54
  return uint8ArrayToBase64(compressed) as EncodedState<T> // Base64-URL-safe encoding
×
55
}
56

57
export const decodeSerializableState = <T>(
×
58
  encodedState: EncodedState<T>,
59
  defaultValue: T, // Needed if decoding fails
60
): T => {
61
  try {
×
62
    const compressed = base64ToUint8Array(encodedState) // Base64-URL-safe decoding
×
63
    const jsonString = pako.inflate(compressed, { to: 'string' })
×
64
    return superjson.parse<T>(jsonString)
×
65
  } catch {
66
    return defaultValue
×
67
  }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc