Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed May 25, 2020
1 parent 61e123e commit 1ddb8a9
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-scalars",
"version": "1.1.2",
"version": "1.1.3",
"description": "A collection of scalar types not included in base GraphQL.",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export {
JSONObject as JSONObjectDefinition,
IBAN as IBANTypeDefinition,
ObjectID as ObjectIDTypeDefinition,
Void as VoidTypeDefinition,
} from './typeDefs';

export { default as typeDefs } from './typeDefs';
Expand Down Expand Up @@ -75,6 +76,7 @@ export {
JSONObject as JSONObjectResolver,
IBAN as IBANResolver,
ObjectID as ObjectIDResolver,
Void as VoidResolver,
} from './resolvers';

export {
Expand Down Expand Up @@ -112,6 +114,7 @@ export {
JSONObject as GraphQLJSONObject,
IBAN as GraphQLIBAN,
ObjectID as GraphQLObjectID,
Void as GraphQLVoid,
} from './resolvers';

export { resolvers };
Expand Down Expand Up @@ -151,6 +154,7 @@ export {
JSONObject as JSONObjectMock,
IBAN as IBANMock,
ObjectID as ObjectIDMock,
Void as VoidMock,
} from './mocks';

export { mocks };
Expand Down
1 change: 1 addition & 0 deletions src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const USCurrency = () => 1000;
export const JSON = () => ({});
export const JSONObject = () => ({});
export const IBAN = () => 'NL55INGB4789170233';
export const Void = (): null => null;

export {
URLMock as URL,
Expand Down
8 changes: 1 addition & 7 deletions src/resolvers/IBAN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ const IBAN_SPECIFICATIONS: CountryStructure = {
XK: { length: 20, structure: 'F04F10F02', example: 'XK051212012345678906' },
};

const NON_ALPHANUM = /[^a-zA-Z0-9]/g;

const A = 'A'.charCodeAt(0);
const Z = 'Z'.charCodeAt(0);

Expand Down Expand Up @@ -386,16 +384,12 @@ function _testIBAN(
}

function validate(iban: string): boolean {
iban = electronicFormat(iban);
iban = iban.toUpperCase();
const countryCode = iban.slice(0, 2);
const countryStructure = IBAN_SPECIFICATIONS[countryCode];
return !!countryStructure && _testIBAN(iban, countryCode, countryStructure);
}

function electronicFormat(iban: string): string {
return iban.replace(NON_ALPHANUM, '').toUpperCase();
}

export default new GraphQLScalarType({
name: `IBAN`,
description: `A field whose value is an International Bank Account Number (IBAN): https://en.wikipedia.org/wiki/International_Bank_Account_Number.`,
Expand Down
19 changes: 19 additions & 0 deletions src/resolvers/Void.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { GraphQLScalarType } from 'graphql';

export default new GraphQLScalarType({
name: 'Void',

description: 'Represents NULL values',

serialize() {
return null;
},

parseValue() {
return null;
},

parseLiteral() {
return null;
},
});
70 changes: 36 additions & 34 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import USCurrency from './USCurrency';
import { JSON, JSONObject } from './JSON';
import IBAN from './IBAN';
import ObjectID from './ObjectID';
import Void from './Void';

const BigIntResolver = BigIntFactory('BigInt');
const LongResolver = BigIntFactory('Long');
Expand All @@ -39,38 +40,39 @@ const NonNegativeFloatResolver = NonNegativeFloatFactory('NonNegativeFloat');
const UnsignedFloatResolver = NonNegativeFloatFactory('UnsignedFloat');

export {
DateTime,
NonPositiveInt,
PositiveInt,
NonNegativeIntResolver as NonNegativeInt,
UnsignedIntResolver as UnsignedInt,
NegativeInt,
NonPositiveFloat,
PositiveFloat,
NonNegativeFloatResolver as NonNegativeFloat,
UnsignedFloatResolver as UnsignedFloat,
NegativeFloat,
EmailAddress,
URL,
PhoneNumber,
PostalCode,
BigIntResolver as BigInt,
LongResolver as Long,
GUID,
Hexadecimal,
HexColorCode,
HSL,
HSLA,
IPv4,
IPv6,
ISBN,
MAC,
Port,
RGB,
RGBA,
USCurrency,
JSON,
JSONObject,
IBAN,
ObjectID,
DateTime,
NonPositiveInt,
PositiveInt,
NonNegativeIntResolver as NonNegativeInt,
UnsignedIntResolver as UnsignedInt,
NegativeInt,
NonPositiveFloat,
PositiveFloat,
NonNegativeFloatResolver as NonNegativeFloat,
UnsignedFloatResolver as UnsignedFloat,
NegativeFloat,
EmailAddress,
URL,
PhoneNumber,
PostalCode,
BigIntResolver as BigInt,
LongResolver as Long,
GUID,
Hexadecimal,
HexColorCode,
HSL,
HSLA,
IPv4,
IPv6,
ISBN,
MAC,
Port,
RGB,
RGBA,
USCurrency,
JSON,
JSONObject,
IBAN,
ObjectID,
Void,
};
3 changes: 3 additions & 0 deletions src/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const UnsignedInt = 'scalar UnsignedInt';
export const Long = 'scalar Long';
export const ObjectID = 'scalar ObjectID';

export const Void = 'scalar Void';

export default [
DateTime,
EmailAddress,
Expand Down Expand Up @@ -69,4 +71,5 @@ export default [
JSONObject,
IBAN,
ObjectID,
Void,
];
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"noUnusedParameters": true,
"resolveJsonModule": true,
"importHelpers": true,
"typeRoots": [ "./types", "./node_modules/@types"],
"typeRoots": ["./types", "./node_modules/@types"],
"baseUrl": ".",
"paths": {
"*": ["./types/*"]
Expand Down

0 comments on commit 1ddb8a9

Please sign in to comment.