question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mask() is not recursive

See original GitHub issue

https://codesandbox.io/s/superstruct-ff5i4-forked-ye1ns?file=/src/index.js

Notice that zzz is silently removed (expected), but unk is not (surprising).

import { type, mask, number } from "superstruct";

let data = {
  id: 1,
  zzz: 444,
  some: {
    a: 10,
    unk: 55
  }
};

let Type = type({
  id: number(),
  some: type({
    a: number()
  })
});

console.log(JSON.stringify(mask(data, Type)));

// {"id":1,"some":{"a":10,"unk":55}} 

P.S. I don’t want to wrap all the type() I have in the code with masked(), because it produces a lot of boilerplate. I assume that the decision of stripping unknown properties is to be made at the caller side (which is likely singular) and not at the definition side (which has way higher cardinality).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dko-slapdashcommented, Jan 22, 2021

Oh yeah, that’s right! So for assert/is, coerce is definitely always = false then.

0reactions
dko-slapdashcommented, Jan 26, 2021

I think it would involve not implementing mask with masked under the covers. Instead, mask: true would be an option pass in to validate and run (which the mask function would pass). And the masking logic would be handled inside the run function. This would allow it to be recursive.

Here is the PR following the above idea: https://github.com/ianstormtaylor/superstruct/pull/629

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Mask not allowing recursive input - Stack Overflow
recursive is meant to repeat any static characters intrinsic to the mask, so for some reason, if there's only one matching character, it...
Read more >
Input Mask Guide | imaskjs
Despite mask has been already support esm modules treeshaking did not work on it because of recursive masks and therefore circular dependencies inside....
Read more >
Bug in recursion + maxlength in jQuery-Mask-Plugin. - Plunker
As I understand it, it adds the mask on the 9 digits informed, not removing ... Code goes here $(document).ready(function() { $('#noRecursive').mask('0,00', ...
Read more >
I cant get samba to set proper permissions on created directories
i have tested adding and removing the directory mask, force directory mode, directory security mode, and the force directory security mode, but the...
Read more >
Masks - WinSCP
To make operation non-recursive use exclude mask */ .2. Directory masks are recursive. E.g. mask images/ matches directories ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found