Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ yarn.lock
/index.js
validator.js
validator.min.js
.idea

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Validator | Description
**isFQDN(str [, options])** | check if the string is a fully qualified domain name (e.g. domain.com).<br/><br/>`options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false, allow_numeric_tld: false, allow_wildcard: false, ignore_max_length: false }`.<br/><br/>`require_tld` - If set to false the validator will not check if the domain includes a TLD.<br/>`allow_underscores` - if set to true, the validator will allow underscores in the domain.<br/>`allow_trailing_dot` - if set to true, the validator will allow the domain to end with a `.` character.<br/>`allow_numeric_tld` - if set to true, the validator will allow the TLD of the domain to be made up solely of numbers.<br />`allow_wildcard` - if set to true, the validator will allow domains starting with `*.` (e.g. `*.example.com` or `*.shop.example.com`).<br/>`ignore_max_length` - if set to true, the validator will not check for the standard max length of a domain.<br/>
**isFreightContainerID(str)** | alias for `isISO6346`, check if the string is a valid [ISO 6346](https://en.wikipedia.org/wiki/ISO_6346) shipping container identification.
**isFullWidth(str)** | check if the string contains any full-width chars.
**isValidGraphQLQuery(str [, options])** | check if the string is valid graphql query (note: uses parse function from graphql package).<br/><br/>`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid graphql query values.
**isHalfWidth(str)** | check if the string contains any half-width chars.
**isHash(str, algorithm)** | check if the string is a hash of type algorithm.<br/><br/>Algorithm is one of `['crc32', 'crc32b', 'md4', 'md5', 'ripemd128', 'ripemd160', 'sha1', 'sha256', 'sha384', 'sha512', 'tiger128', 'tiger160', 'tiger192']`.
**isHexadecimal(str)** | check if the string is a hexadecimal number.
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';
import isValidGraphQLQuery from "./lib/isValidGraphQLQuery";

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Strings must use singlequote

Check failure on line 132 in src/index.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Strings must use singlequote

const version = '13.15.0';

Expand Down Expand Up @@ -245,6 +246,7 @@
isLicensePlate,
isVAT,
ibanLocales,
isValidGraphQLQuery,
};

export default validator;
23 changes: 23 additions & 0 deletions src/lib/isValidGraphQLQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import assertString from './util/assertString';
import { parse } from 'graphql';

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Absolute imports should come before relative imports

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Unable to resolve path to module 'graphql'

Check failure on line 2 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Absolute imports should come before relative imports
import merge from './util/merge';

const default_json_options = {
allow_primitives: false,
};

export default function isValidGraphQLQuery(input, options) {
assertString(input);
try {
options = merge(options, default_json_options);
let primitives = [];
if (options.allow_primitives) {
primitives = [null, false, true];
}

const obj = parse(input);
return includes(primitives, obj) || (!!obj && typeof obj === 'object');

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

'includes' is not defined

Check failure on line 19 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

'includes' is not defined
} catch (e) {
return false;
};

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Unnecessary semicolon

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Unreachable code

Check failure on line 22 in src/lib/isValidGraphQLQuery.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Unnecessary semicolon
}
Loading