@terabits/grapi
Version:
Grapi Schema Generator For GraphQL Server
28 lines (27 loc) • 1.02 kB
JavaScript
;
exports.__esModule = true;
exports.Phone = void 0;
var graphql_1 = require("graphql");
var isPhoneOrMobileNumber = function (value) {
return /^([0-9]{1})?([0-9]{1})?([0-9]{1})([0-9]{10})|^([0-9]{7})$/.test(value);
};
var parseAndSerializeValue = function (value) {
if (isPhoneOrMobileNumber(value)) {
return value;
}
throw new Error("Wrong \"".concat(value, "\" format for phone or mobile number."));
};
var parseLiteral = function (ast) {
if (isPhoneOrMobileNumber(ast.value)) {
return ast.value;
}
throw new Error("Wrong \"".concat(ast.value, "\" format for phone or mobile number."));
};
var Phone = new graphql_1.GraphQLScalarType({
name: 'Phone',
description: "Formats from Phone number or mobile number. This data type accept digits with a standard, 7 digits for phone and 11 - 13 digits for mobile number.",
serialize: parseAndSerializeValue,
parseValue: parseAndSerializeValue,
parseLiteral: parseLiteral
});
exports.Phone = Phone;