# graphql-scalar

> Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.

Latest version **0.1.0** (published 2023-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-scalar
pnpm add graphql-scalar
yarn add graphql-scalar
bun add graphql-scalar
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-03-23 |
| First published | 2019-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 105.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Joon Ho Cho |
| Maintainers | joonhocho |
| Keywords | configurable, custom, GraphQL, scalars, GraphQLScalarType, string, number, date, timestamp, sanitization, validation, transformation, TypeScript, graphql-input-number, graphql-input-string |

## Links

- npm: https://www.npmjs.com/package/graphql-scalar
- Repository: https://github.com/joonhocho/graphql-scalar
- Homepage: https://github.com/joonhocho/graphql-scalar#readme
- Issues: https://github.com/joonhocho/graphql-scalar/issues
- npm.io page: https://npm.io/package/graphql-scalar

## Dependencies (1)

- [tsdef](https://npm.io/package/tsdef.md) ^0.0.14

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2023-03-23
- 0.0.11 — 2019-11-17
- 0.0.10 — 2019-10-26
- 0.0.9 — 2019-07-11
- 0.0.8 — 2019-07-11
- 0.0.7 — 2019-07-11
- 0.0.6 — 2019-07-11
- 0.0.5 — 2019-07-10
- 0.0.4 — 2019-07-06
- 0.0.3 — 2019-06-28
- 0.0.2 — 2019-06-28

## README

# graphql-scalar
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.

[![npm version](https://badge.fury.io/js/graphql-scalar.svg)](https://badge.fury.io/js/graphql-scalar)
[![Build Status](https://travis-ci.org/joonhocho/graphql-scalar.svg?branch=master)](https://travis-ci.org/joonhocho/graphql-scalar)
[![Coverage Status](https://coveralls.io/repos/github/joonhocho/graphql-scalar/badge.svg?branch=master)](https://coveralls.io/github/joonhocho/graphql-scalar?branch=master)
[![Dependency Status](https://david-dm.org/joonhocho/graphql-scalar.svg)](https://david-dm.org/joonhocho/graphql-scalar)
![npm type definitions](https://img.shields.io/npm/types/graphql-scalar.svg)
[![GitHub](https://img.shields.io/github/license/joonhocho/graphql-scalar.svg)](https://github.com/joonhocho/graphql-scalar/blob/master/LICENSE)

TypeScript version (with breaking changes) of the following repos:  
[joonhocho/graphql-input-number](https://github.com/joonhocho/graphql-input-number)  
[joonhocho/graphql-input-string](https://github.com/joonhocho/graphql-input-string)  

## Get Started
```
npm install graphql-scalar
```
or
```
yarn add graphql-scalar
```

## How to Use
```typescript
import { createStringScalar, createIntScalar, createFloatScalar } from 'graphql-scalar';

const stringScalar = createStringScalar({
  name: string;
  description?: string;
  capitalize?: 'characters' | 'words' | 'sentences' | 'first';
  collapseWhitespace?: boolean;
  lowercase?: boolean;
  maxLength?: number;
  minLength?: number;
  nonEmpty?: boolean;
  pattern?: RegExp | string;
  singleline?: string;
  trim?: boolean;
  trimLeft?: boolean;
  trimRight?: boolean;
  truncate?: number;
  uppercase?: boolean;
  coerce?: ScalarCoerceFunction<TValue>;
  errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
  parse?: ScalarParseFunction<TValue, TInternal>;
  sanitize?: ScalarSanitizeFunction<TValue>;
  serialize?: ScalarSerializeFunction<TInternal, TExternal>;
  validate?: ScalarValidateFunction<TValue>;
})

const intScalar = createIntScalar({
  name: string;
  description?: string;
  maximum?: number;
  minimum?: number;
  coerce?: ScalarCoerceFunction<TValue>;
  errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
  parse?: ScalarParseFunction<TValue, TInternal>;
  sanitize?: ScalarSanitizeFunction<TValue>;
  serialize?: ScalarSerializeFunction<TInternal, TExternal>;
  validate?: ScalarValidateFunction<TValue>;
})
```

## License
[MIT License](https://github.com/joonhocho/graphql-scalar/blob/master/LICENSE)

---
_Source: https://npm.io/package/graphql-scalar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
