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.

support for sanitization

See original GitHub issue

Not sure whether this in scope of the library, but for example io-ts, joi, yup all etc. can sanitize values (i.e. coerce them within certain boundaries) which is actually useful in some use cases. It would be nice if runtypes could do that too. joi and yup all do sanitization for some of their built in types and in io-ts one can do sanitization in the validator function of custom types by passing the sanitized value to t.success(sanitizedValue).

I was actually looking at all the above mentioned libraries incl. runtypes for the use case of API validation. While I really wanted to use io-ts or runtypes (I use typescript everywhere) but I decided against the use of runtypes because of the lack of sanitization and it wasn’t clear to me how to create custom types, and against io-ts because of the lack of an ability to create validation specific error messages.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
kjvalencikcommented, Jan 15, 2019

I packaged my filtering into a small lib in case it’s useful for anyone else. runtypes-filter.

Usage:

import { Literal, Number, Record } from "runtypes";
import CheckFilter from "runtypes-filter";
 
const Asteroid = Record({
    type: Literal("asteroid"),
    mass: Number
});
 
const filterAsteroid = CheckFilter(Asteroid);
 
const untrustedAsteroid: unknown = {
    type: "asteroid",
    mass: 100
};
 
const trustedAteroid = filterAsteroid(untrustedAsteroid);
1reaction
pelotomcommented, Jun 13, 2018

That makes sense. I think it should be possible to write such a function against runtype’s Reflect API. If so, I would say that it makes sense to define it as a separate library, so as to keep the core of runtypes as simple as possible. What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cleaning, Disinfecting, and Ventilation - CDC
The Clean Air in Buildings Challenge helps building owners and operators improve indoor air quality and protect public health. Create your clean indoor...
Read more >
Cleaning, Disinfecting, and Sanitizing - MedlinePlus
Some common disinfectants are bleach and alcohol solutions. You usually need to leave the disinfectant on the surfaces and objects for a certain ......
Read more >
FiltaShield | Preventative Sanitization Treatment
Our preventative sanitization treatment service utilizes eco-friendly, naturally derived, mild surfactants to produce an environmentally-responsible and ...
Read more >
Disinfection Services | Covid Cleaning Services | Book Online ...
Eco-friendly and revolutionary, EPA-approved electrostatic disinfection and sanitization services. Call for a FREE quote now 617-209-9124.
Read more >
COVID-19 Sanitizing and Disinfection Services - BAY AREA ...
Our premium service includes disinfecting and sanitizing by fogging of all rooms and common areas in your home and office including wiping down...
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