Part 7: superstruct

This is the 7th post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

Superstruct is another newcomer, created in November 2017. It has zero dependencies and a mini-zipped size of just 3.2 KB, the smallest package among the tested validators. It can be used on both the back-end and front-end.

Achievement of the Design Goals

1. One definition, multi-uses — achieved

Superstruct defines data with “structs”. The…


Part 6: zod

This is the 6th post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

Zod is a newcomer in the tested validators and assimilated many ideas from its predecessors. The creator of zod looked into several popular validators (joi, yup, and io-ts mentioned) and decided to build his own from scratch. …


Part 4: yup

This is the 4th post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

Yup is “heavily inspired by joi”, and is similar to joi in many ways. However, it claims to be “leaner (than joi) and built with client-side validation as its primary use-case”.

Achievement of the Design Goals

1. One definition, multi-uses — achieved with glitches

Yup provides type inference off-the-shelf. In fact, it goes a step further…


Part 5: ajv

This is the 5th post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

Ajv is a JSON Schema based validator, which distinguishes it from the other tested validators. Ajv is self-claimed to be “super fast”, and works for both the back-end (Node.js) and the front-end (browser). …


Part 3: joi

This is the 3rd post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

Joi is the earliest created (in September 2012) and the second most popular validator (according to the downloads) among the tested validators. It boasts a “simple, intuitive, and readable language” for defining data, and does a good job in achieving this goal.

Achievement of the Design Goals

1. One definition, multi-uses — achievable

Joi…


Part 2: io-ts

This is the 2nd post of a series report on the comparison of run-time data validators based on my hands-on experiences. You should read the introduction in the first post to understand the goals and test methods involved in making this report, before proceeding with the rest of this series.

  1. Introduction

Introduction

io-ts is a “run-time type system for IO decoding/encoding”. Its creator, gcanti, also created the popular library “fp-ts” for typed functional programming in TypeScript. “fp-ts” is a peer dependency of “io-ts”. Both “io-ts” and “fp-ts” fall heavily into the functional programming paradigm. …


Part 1: Introduction

Introduction

This is a research report. Wishing to find “the perfect run-time data validator” for a TypeScript project, I listed design goals that a “perfect validator” should achieve and collected a list of validators (io-ts, joi, ajv, yup, zod, and superstruct) to see if, and how well, these validators achieve the goals. I built a project to use each of the validators to validate the same data. All validators must pass the same set of test cases, which represent a range of common and somewhat complex validation scenarios in real projects.

I gained hands-on experiences and insights into these validators in…


Directory Structure, Module Resolution and Related Configuration Options

Directory structures and module resolution of TypeScript projects are not complex, until you start organizing things into separate units, putting them into different directories, and experimenting with some of the configuration options discussed here.

This article provides an overall understanding of the mechanisms and configuration options that affect TypeScript project directory structures and module resolution, as well as some caveats in the hope of saving the reader from certain pitfalls. However, it is not a tutorial, and does not give detailed examples. …


So one day I was wondering if ‘any’ extends ‘object’.

I was amazed of what I had found out.


Gulp tasks make heavy use of node.js object Transform stream API (https://nodejs.org/api/stream.html#stream_class_stream_transform) to process files. More accurately, to process Vinyl (https://gulpjs.com/docs/en/api/vinyl) objects that represent files. There are gulp plugins that provide ready made node stream.Transform objects for performing many kinds of processing.

To write a gulp plugin is to implement a stream.Transform. Check “Implementing a Transform Stream” in the node.js stream API documentation (https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream). The codes below is a gulp task that reads files under ./src/**.* and concatenates the contents to the corresponding files under ./dst, e.g. “./src/a.txt” concatenates to “./dst/a.txt”. Like most gulp tasks, it starts with gulp.src() …

Bing Ren

Developer, paddler

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store