npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-input-string

v0.0.16

Published

A configurable custom input string type for GraphQL with sanitization and validation.

Downloads

200

Readme

graphql-input-string

Build Status Coverage Status npm version Dependency Status License

A configurable custom input string type for GraphQL with sanitization and validation.

Checkout graphql-input-number for validating number inputs.

Install

npm install --save graphql-input-string

Usage

import GraphQLInputString from 'graphql-input-string';

const argType = GraphQLInputString({
  name: 'TrimmedString',
  trim: true,
});

new GraphQLObjectType({
  name: 'Query',
  fields: {
    input: {
      type: GraphQLString,
      args: {
        name: {
          type: argType,
        },
      },
      resolve: (_, {name}) => {

        'name' IS NOW A TRIMMED STRING

      };
    },
  },
});

Options

GraphQLInputString({
  // Type name.
  // [REQUIRED]
  name: string = null,

  // Whether to trim strings.
  trim: boolean = false,

  // Whether to trimLeft strings.
  trimLeft: boolean = false,

  // Whether to trimRight strings.
  trimRight: boolean = false,

  // Whether to disallow newline characters.
  singleline: boolean = false,

  // Whether to collapse whitespace characters.
  collapseWhitespace: boolean = false,

  // If specified, truncate strings to the specified length.
  truncate: number = null,

  // Whether to transform characters to uppercase.
  upperCase: boolean = false,

  // Whether to transform characters to lowercase.
  lowerCase: boolean = false,

  // If specified, capitalize string according to specified rule.
  // possible values: 'characters' | 'words' | 'sentences' | 'first'
  capitalize: string = null,

  // Sanitize function that is called at the end of sanitzation phase and before
  // validation phase.
  sanitize: ((string) => string) = null,

  // Whether to allow empty strings.
  empty: boolean = false,

  // Minimum length allowed (inclusive).
  min: number = null,

  // Maximum length allowed (inclusive).
  max: number = null,

  // Allowed pattern definition.
  pattern: (string | RegExp) = null,

  // Test function that is called at the end of validation phase.
  test: ((string) => boolean) = null,

  // Custom error handler.
  // May throw an error or return a value.
  // If a value is returned, it will become the final value.
  error: ErrorHandler = () => throw GraphQLError,

  // Parse function that is called after validation phase before returning a
  // value.
  // May throw an error or return a value.
  parse: ((string) => any) = null,

  // If you want to pass additional config to type constructor, simply add them here.
  // For example,
  description: string,
});


type ErrorInfo = {
  type: string,
  value: string,
  message: ?string,
  ast: ?Ast,
  ...args,
};


type ErrorHandler = (ErrorInfo) => any;

License

The MIT License (MIT)

Copyright (c) 2016 Joon Ho Cho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.