UNPKG

graphql-scalars

Version:

A collection of scalar types not included in base GraphQL.

56 lines 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BigInt = () => Number.MAX_SAFE_INTEGER - 1; exports.Long = exports.BigInt; exports.DateTime = () => new Date(); exports.EmailAddress = () => 'test@test.com'; exports.NegativeFloat = () => -123.45; exports.NegativeInt = () => -123; exports.NonNegativeFloat = () => 123.45; exports.UnsignedFloat = exports.NonNegativeFloat; exports.NonNegativeInt = () => 123; exports.UnsignedInt = exports.NonNegativeInt; exports.NonPositiveFloat = () => -123.45; exports.NonPositiveInt = () => -123; exports.PhoneNumber = () => '+17895551234'; exports.PositiveFloat = () => 123.45; exports.PositiveInt = () => 123; exports.PostalCode = () => '60031'; const URLMock = () => new url_1.URL('http://www.test.com/'); exports.URL = URLMock; // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript exports.GUID = () => { let d = new Date().getTime(); if (typeof performance !== 'undefined' && typeof performance.now === 'function') { d += performance.now(); //use high-precision timer if available } return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { // tslint:disable-next-line: no-bitwise const r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); // tslint:disable-next-line: no-bitwise return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); }; exports.HexColorCode = () => '#' + Math.floor(Math.random() * 16777215).toString(16); exports.Hexadecimal = () => Math.floor(Math.random() * 16777215).toString(16); const randomVal = (min, max) => { return Math.floor(Math.random() * (max - min) + 1) + min; }; // https://codepen.io/meowwwls/pen/jbEJRp exports.HSL = () => `hsl(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(30, 80)}%)`; exports.HSLA = () => `hsla(${randomVal(0, 360)}, ${randomVal(30, 95)}%, ${randomVal(30, 80)}%, ${Math.random()})`; // https://stackoverflow.com/questions/43464519/creating-fake-ip-address-using-javascript exports.IPv4 = () => (Math.floor(Math.random() * 255) + 1) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0) + '.' + (Math.floor(Math.random() * 255) + 0); exports.IPv6 = () => '2001:0db8:85a3:0000:0000:8a2e:0370:7334'; // http://jsfiddle.net/guest271314/qhbC9/ exports.MAC = () => 'XX:XX:XX:XX:XX:XX'.replace(/X/g, () => '0123456789ABCDEF'.charAt(Math.floor(Math.random() * 16))); exports.Port = () => randomVal(0, 65535); exports.RGB = () => `rgb(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(0, 255)})`; exports.RGBA = () => `rgba(${randomVal(0, 255)}, ${randomVal(0, 255)}, ${randomVal(0, 255)}, ${Math.random()})`; exports.ISBN = () => `978-3-16-148410-0`; exports.USCurrency = () => 1000; exports.JSON = () => ({}); exports.JSONObject = () => ({}); const url_1 = require("url"); //# sourceMappingURL=mocks.js.map