How to use the tiny-decoders.mixedDict function in tiny-decoders

To help you get started, we’ve selected a few tiny-decoders examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lydell / tiny-decoders / typescript / decoders.ts View on Github external
either(string, number)(undefined);
// $ExpectType string | number | boolean | { readonly [key: string]: unknown; }
either(either(boolean, string), either(number, mixedDict))(undefined);
// $ExpectType string
lazy(() => string)(undefined);

// $ExpectError
boolean(undefined, []);
// $ExpectError
number(undefined, []);
// $ExpectError
string(undefined, []);
// $ExpectError
mixedArray(undefined, []);
// $ExpectError
mixedDict(undefined, []);
// $ExpectError
constant("const")(undefined, []);
// $ExpectError
constant("const")(undefined, {});
array(string)(undefined, []);
// $ExpectError
array(string)(undefined, {});
dict(string)(undefined, []);
// $ExpectError
dict(string)(undefined, {});
record(() => "")(undefined, []);
// $ExpectError
record(() => "")(undefined, {});
tuple(() => "")(undefined, []);
// $ExpectError
tuple(() => "")(undefined, {});
github lydell / LinkHints / src / background / Program.js View on Github external
async updateOptions({ isInitial = false }: { isInitial?: boolean } = {}) {
    if (!PROD) {
      if (isInitial) {
        const defaultStorageSync = DEFAULT_STORAGE_SYNC;
        if (defaultStorageSync != null) {
          await browser.storage.sync.clear();
          await browser.storage.sync.set(mixedDict(defaultStorageSync));
        }
      }
    }

    const info = await browser.runtime.getPlatformInfo();
    const mac = info.os === "mac";
    const defaults = getDefaults({ mac });
    const rawOptions = await browser.storage.sync.get();
    const defaulted = { ...flattenOptions(defaults), ...rawOptions };
    const unflattened = unflattenOptions(defaulted);
    const decoder = makeOptionsDecoder(defaults);
    const decodeErrors: Array = [];
    const options: Options = decoder(unflattened, decodeErrors);

    log("log", "BackgroundProgram#updateOptions", {
      defaults,
github lydell / LinkHints / src / options / Program.js View on Github external
async importOptions() {
    const { options: optionsData } = this.state;
    if (optionsData == null) {
      return;
    }
    const { values: options, defaults } = optionsData;
    try {
      const file = await selectFile("application/json");
      const data = await readAsJson(file);
      const [tweakableData, otherData] = partitionTweakable(mixedDict(data));
      const { options: newOptions, successCount, errors } = importOptions(
        otherData,
        options,
        defaults
      );
      this.setState({
        importData: {
          successCount,
          tweakableCount: Object.keys(tweakableData).length,
          errors,
        },
      });
      if (newOptions != null) {
        this.saveOptions(newOptions);
      }
      await saveTweakable(tweakableData);