프로젝트
GitHub에서 보기
nvie/decoders
소개
TypeScript의 타입 안전 입력 데이터를 위한 우아한 검증 라이브러리
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
Elegant and battle-tested validation library for type-safe input data for TypeScript.
Basic example
import { array, isoDate, number, object, optional, string } from 'decoders';
// Incoming data at runtime, e.g. the request body
// The point is that this data is untrusted and its type unknown
const externalData = {
id: 123,
name: 'Alison Roberts',
createdAt: '2026-01-11T12:26:37.024Z',
tags: ['foo', 'bar'],
};
// Write the decoder (= what you expect the data to look like)
const userDecoder = object({
id: number,
name: string,
createdAt: optional(isoDate),
tags: array(string),
});
// Call .verify() on the incoming data
const user = userDecoder.verify(externalData);
// ^^^^
// TypeScript will infer this type as:
// {
// id: number;
// name: string;
// createdAt?: Date;
// tags: string[];
// }
Installation
npm install decoders
Requirements
You must set strict: true in your tsconfig.json in order for type inference to work
correctly!
// tsconfig.json
{
"compilerOptions": {
"strict": true
}
}
Documentation
Documentation can be found on decoders.cc.
There is a dedicated page that explains how to build your own decoders.
관련 프로젝트 살펴보기
불러오는 중…