How to use checkValue method in wpt

Best JavaScript code snippet using wpt

validation.js

Source:validation.js Github

copy

Full Screen

...9 term: "Sketch",10 validate: (data, path) => {11 return {12 type: "sketch",13 seed: checkValue(data, [...path, 'seed'], Math.round(Math.random() * 1000), isInteger),14 shake: checkValue(data, [...path, 'shake'], 0.2, isGTE(0), isLTE(1)),15 nib: checkLength(data, [...path, 'nib'], 1, 1),16 }17 }18 },19 pen: {20 term: "Pen",21 validate: (data, path) => {22 return {23 type: "pen",24 nib: checkLength(data, [...path, 'nib'], 1, 1),25 seed: checkValue(data, [...path, 'seed'], Math.round(Math.random() * 1000), isInteger),26 smudge: checkValue(data, [...path, 'smudge'], 0.2, isGTE(0), isLTE(1)),27 jitter: checkValue(data, [...path, 'jitter'], 0.5, isGTE(0), isLTE(1))28 }29 }30 },31 pencil: {32 term: "Pencil",33 validate: (data, path) => {34 return {35 type: "pencil",36 seed: checkValue(data, [...path, 'seed'], Math.round(Math.random() * 1000), isInteger)37 }38 }39 },40 glow: {41 term: "Glow",42 validate: (data, path) => {43 return {44 type: "glow",45 blur: checkValue(data, [...path, 'blur'], 3, isNumber),46 spread: checkLength(data, [...path, 'spread'], 3, 1),47 }48 }49 }50}51export const LAYERS = {52 line: {53 term: "Line",54 category: "shape",55 validate: (data, path) => {56 return {57 type: "line",58 name: checkValue(data, [...path, "name"], "", isString),59 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),60 visible: checkValue(data, [...path, "visible"], true, isBoolean),61 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),62 r1: checkLength(data, [...path, 'r1'], 0, 96),63 t1: checkValue(data, [...path, 't1'], 0, isNumber),64 x1: checkLength(data, [...path,'x1'], 0, 96),65 y1: checkLength(data, [...path,'y1'], 0, 96),66 r2: checkLength(data, [...path,'r2'], 0, 96),67 t2: checkValue(data, [...path, 't2'], 0, isNumber),68 x2: checkLength(data, [...path, 'x2'], 0, 96),69 y2: checkLength(data, [...path, 'y2'], 0, 96),70 stroke: checkStroke(data, [...path, 'stroke'])71 }72 }73 },74 circle: {75 term: "Circle",76 category: "shape",77 validate: (data, path) => {78 return {79 type: "circle",80 name: checkValue(data, [...path, "name"], "", isString),81 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),82 visible: checkValue(data, [...path, "visible"], true, isBoolean),83 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),84 r: checkLength(data, [...path, 'r'], 0, 96),85 t: checkValue(data, [...path, 't'], 0, isNumber),86 x: checkLength(data, [...path, 'x'], 0, 96),87 y: checkLength(data, [...path, 'y'], 0, 96),88 radius: checkLengthWithScale(data, [...path, 'radius'], 2, 96, true, isNumber),89 stroke: checkStroke(data, [...path, 'stroke']),90 fill: checkFill(data, [...path, 'fill'])91 }92 }93 },94 ring: {95 term: "Ring",96 category: "shape",97 validate: (data, path) => {98 return {99 type: "ring",100 name: checkValue(data, [...path, "name"], "", isString),101 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),102 visible: checkValue(data, [...path, "visible"], true, isBoolean),103 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),104 r: checkLength(data, [...path, 'r'], 0, 96),105 t: checkValue(data, [...path, 't'], 0, isNumber),106 x: checkLength(data, [...path, 'x'], 0, 96),107 y: checkLength(data, [...path, 'y'], 0, 96),108 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),109 inner: checkLengthWithScale(data, [...path, 'inner'], 1, 96, true, isNumber),110 outer: checkLengthWithScale(data, [...path, 'outer'], 2, 96, true, isNumber),111 radius: checkLengthWithScale(data, [...path, 'radius'], 1.5, 96, true, isNumber),112 spread: checkLengthWithScale(data, [...path, 'spread'], 0.5, 96, true, isNumber),113 radialMode: checkValue(data, [...path, 'radialMode'], "innerouter", isEnum("innerouter", "radiusspread")),114 stroke: checkStroke(data, [...path, 'stroke']),115 fill: checkFill(data, [...path, 'fill'])116 }117 }118 },119 polygon: {120 term: "Polygon",121 category: "shape",122 validate: (data, path) => {123 return {124 type: "polygon",125 name: checkValue(data, [...path, "name"], "", isString),126 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),127 visible: checkValue(data, [...path, "visible"], true, isBoolean),128 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),129 r: checkLength(data, [...path, 'r'], 0, 96),130 t: checkValue(data, [...path, 't'], 0, isNumber),131 x: checkLength(data, [...path, 'x'], 0, 96),132 y: checkLength(data, [...path, 'y'], 0, 96),133 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),134 radius: checkPolygonRadius(data, [...path, 'radius'], 1.5, 96, true, isGTE(0)),135 scribeMode: checkValue(data, [...path, "scribeMode"], "circumscribe", isLegacy([...path, "radius", "scribe"]), isEnum("circumscribe", "inscribe", "middle")),136 sides: checkValue(data, [...path, 'sides'], 5, isInteger, isGTE(3), isLTE(24)),137 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),138 stroke: checkStroke(data, [...path, 'stroke']),139 fill: checkFill(data, [...path, 'fill'])140 }141 }142 },143 polygram: {144 term: "Polygram",145 category: "shape",146 validate: (data, path) => {147 return {148 type: "polygram",149 name: checkValue(data, [...path, "name"], "", isString),150 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),151 visible: checkValue(data, [...path, "visible"], true, isBoolean),152 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),153 r: checkLength(data, [...path, 'r'], 0, 96),154 t: checkValue(data, [...path, 't'], 0, isNumber),155 x: checkLength(data, [...path, 'x'], 0, 96),156 y: checkLength(data, [...path, 'y'], 0, 96),157 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),158 radius: checkPolygonRadius(data, [...path, 'radius'], 1.5, 96, true, isGTE(0)),159 scribeMode: checkValue(data, [...path, "scribeMode"], "circumscribe", isLegacy([...path, "radius", "scribe"]), isEnum("circumscribe", "inscribe", "middle")),160 sides: checkValue(data, [...path, 'sides'], 5, isInteger, isGTE(5), isLTE(24)),161 skip: checkValue(data, [...path, 'skip'], 1, isInteger, isGTE(0), isLTE(Math.ceil(checkValue(data, [...path, 'sides'], 5, isGTE(5), isLTE(24)) / 2) - 2)),162 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),163 stroke: checkStroke(data, [...path, 'stroke']),164 fill: checkFill(data, [...path, 'fill'])165 }166 }167 },168 burst: {169 term: "Burst",170 category: "shape",171 validate: (data, path) => {172 return {173 type: "burst",174 name: checkValue(data, [...path, "name"], "", isString),175 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),176 visible: checkValue(data, [...path, "visible"], true, isBoolean),177 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),178 r: checkLength(data, [...path, 'r'], 0, 96),179 t: checkValue(data, [...path, 't'], 0, isNumber),180 x: checkLength(data, [...path, 'x'], 0, 96),181 y: checkLength(data, [...path, 'y'], 0, 96),182 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),183 count: checkValue(data, [...path, 'count'], 5, isInteger),184 radialMode: checkValue(data, [...path, 'radialMode'], 'innerouter', isEnum("radiusspread", "innerouter")),185 inner: checkLengthWithScale(data, [...path, 'inner'], 0, 96, true, isNumber),186 outer: checkLengthWithScale(data, [...path, 'outer'], 1.5, 96, true, isNumber),187 radius: checkLengthWithScale(data, [...path, 'radius'], 1.5, 96, true, isNumber),188 spread: checkLengthWithScale(data, [...path, 'spread'], 0.5, 96, true, isNumber),189 thetaMode: checkValue(data, [...path, 'thetaMode'], 'incremental', isEnum("incremental", "startstop")),190 step: checkValue(data, [...path, 'step'], 72, isNumber),191 toExtent: checkValue(data, [...path, 'toExtent'], false, isBoolean),192 coverage: {193 start: checkValue(data, [...path, 'coverage', 'start'], 0, isNumber),194 end: checkValue(data, [...path, 'coverage', 'end'], 360, isNumber),195 },196 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),197 stroke: checkStroke(data, [...path, 'stroke']),198 }199 }200 },201 arc: {202 term: "Arc",203 category: "shape",204 validate: (data, path) => {205 return {206 type: "arc",207 name: checkValue(data, [...path, "name"], "", isString),208 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),209 visible: checkValue(data, [...path, "visible"], true, isBoolean),210 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),211 r: checkLength(data, [...path, 'r'], 0, 96),212 t: checkValue(data, [...path, 't'], 0, isNumber),213 x: checkLength(data, [...path, 'x'], 0, 96),214 y: checkLength(data, [...path, 'y'], 0, 96),215 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),216 radius: checkLengthWithScale(data, [...path, 'radius'], 1.5, 96, true, isNumber),217 pie: checkValue(data, [...path, 'pie'], false, isBoolean),218 coverage: {219 start: checkValue(data, [...path, 'coverage', 'start'], 0, isLTE(360), isGTE(0)),220 end: checkValue(data, [...path, 'coverage', 'end'], 60, isLTE(360), isGTE(0)),221 },222 stroke: checkStroke(data, [...path, 'stroke']),223 fill: checkFill(data, [...path, 'fill'])224 }225 }226 },227 star: {228 term: "Star",229 category: "shape",230 validate: (data, path) => {231 return {232 type: "star",233 name: checkValue(data, [...path, "name"], "", isString),234 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),235 visible: checkValue(data, [...path, "visible"], true, isBoolean),236 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),237 r: checkLength(data, [...path, 'r'], 0, 96),238 t: checkValue(data, [...path, 't'], 0, isNumber),239 x: checkLength(data, [...path, 'x'], 0, 96),240 y: checkLength(data, [...path, 'y'], 0, 96),241 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),242 points: checkValue(data, [...path, 'points'], 5, isInteger),243 scribeMode: checkValue(data, [...path, 'scribeMode'], 'circumscribe', isEnum('circumscribe', 'inscribe', 'middle')),244 radialMode: checkValue(data, [...path, 'radialMode'], 'innerouter', isEnum("radiusspread", "innerouter")),245 inner: checkLengthWithScale(data, [...path, 'inner'], 0.75, 96, true, isNumber),246 outer: checkLengthWithScale(data, [...path, 'outer'], 2, 96, true, isNumber),247 radius: checkLengthWithScale(data, [...path, 'radius'], 1.5, 96, true, isNumber),248 spread: checkLengthWithScale(data, [...path, 'spread'], 0.5, 96, true, isNumber),249 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),250 stroke: checkStroke(data, [...path, 'stroke']),251 fill: checkFill(data, [...path, 'fill'])252 }253 }254 },255 path: {256 term: "Path",257 warning: "Proceed with Caution!",258 category: "shape",259 validate: (data, path) => {260 return {261 type: "path",262 name: checkValue(data, [...path, "name"], "", isString),263 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),264 visible: checkValue(data, [...path, "visible"], true, isBoolean),265 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),266 r: checkLength(data, [...path, 'r'], 0, 96),267 t: checkValue(data, [...path, 't'], 0, isNumber),268 x: checkLength(data, [...path, 'x'], 0, 96),269 y: checkLength(data, [...path, 'y'], 0, 96),270 s: checkValue(data, [...path, 's'], 1, isNumber),271 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),272 definition: checkValue(data, [...path, 'definition'], "", isString),273 stroke: checkStroke(data, [...path, 'stroke']),274 fill: checkFill(data, [...path, 'fill'])275 }276 }277 },278 group: {279 term: "Group",280 category: "collection",281 validate: (data, path) => {282 return {283 type: "group",284 name: checkValue(data, [...path, "name"], "", isString),285 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),286 visible: checkValue(data, [...path, "visible"], true, isBoolean),287 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),288 r: checkLength(data, [...path, 'r'], 0, 96),289 t: checkValue(data, [...path, 't'], 0, isNumber),290 x: checkLength(data, [...path, 'x'], 0, 96),291 y: checkLength(data, [...path, 'y'], 0, 96),292 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),293 layers: checkLayers(data, [...path, 'layers'])294 }295 }296 },297 radialary: {298 term: "Radial Array",299 category: "collection",300 validate: (data, path) => {301 return {302 type: "radialary",303 name: checkValue(data, [...path, "name"], "", isString),304 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),305 visible: checkValue(data, [...path, "visible"], true, isBoolean),306 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),307 r: checkLength(data, [...path, 'r'], 0, 96),308 t: checkValue(data, [...path, 't'], 0, isNumber),309 x: checkLength(data, [...path, 'x'], 0, 96),310 y: checkLength(data, [...path, 'y'], 0, 96),311 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),312 count: checkValue(data, [...path, 'count'], 3, isInteger),313 radialMode: checkValue(data, [...path, 'radialMode'], 'innerouter', isEnum("radiusspread", "innerouter")),314 inner: checkLengthWithScale(data, [...path, 'inner'], 1, 96, true, isNumber),315 outer: checkLengthWithScale(data, [...path, 'outer'], 2, 96, true, isNumber),316 radius: checkLengthWithScale(data, [...path, 'radius'], 1.5, 96, true, isNumber),317 spread: checkLengthWithScale(data, [...path, 'spread'], 0.5, 96, true, isNumber),318 thetaMode: checkValue(data, [...path, 'thetaMode'], 'incremental', isEnum("incremental", "startstop")),319 step: checkValue(data, [...path, 'step'], 20, isNumber),320 toExtent: checkValue(data, [...path, 'toExtent'], false, isBoolean),321 coverage: {322 start: checkValue(data, [...path, 'coverage', 'start'], 0, isNumber),323 end: checkValue(data, [...path, 'coverage', 'end'], 360, isNumber),324 },325 scaleFactor: checkValue(data, [...path, 'scaleFactor'], "1 0,linear,1 1", isSpline),326 radialCurve: checkValue(data, [...path, 'radialCurve'], "linear", isEnum(...CURVES)),327 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),328 colorFactorInherit: checkValue(data, [...path, 'colorFactorInherit'], false, isBoolean),329 colorFactorFill: checkValue(data, [...path, 'colorFactorFill'], "#ffffffff 0,rgb linear,#000000ff 1", isGradient),330 colorFactorStroke: checkValue(data, [...path, 'colorFactorStroke'], "#ffffffff 0,rgb linear,#000000ff 1", isGradient),331 layers: checkLayers(data, [...path, 'layers'])332 }333 }334 },335 vertexary: {336 term: "Vertex Array",337 category: "collection",338 validate: (data, path) => {339 return {340 type: "vertexary",341 name: checkValue(data, [...path, "name"], "", isString),342 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),343 visible: checkValue(data, [...path, "visible"], true, isBoolean),344 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),345 r: checkLength(data, [...path, 'r'], 0, 96),346 t: checkValue(data, [...path, 't'], 0, isNumber),347 x: checkLength(data, [...path, 'x'], 0, 96),348 y: checkLength(data, [...path, 'y'], 0, 96),349 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),350 radius: checkPolygonRadius(data, [...path, 'radius'], 1.5, 96, true, isGTE(0)),351 scribeMode: checkValue(data, [...path, "scribeMode"], "circumscribe", isLegacy([...path, "radius", "scribe"]), isEnum("circumscribe", "inscribe", "middle")),352 count: checkValue(data, [...path, 'count'], 5, isInteger),353 scaleFactor: checkValue(data, [...path, 'scaleFactor'], "1 0,linear,1 1", isSpline),354 thetaCurve: checkValue(data, [...path, 'thetaCurve'], "linear", isEnum(...CURVES)),355 colorFactorInherit: checkValue(data, [...path, 'colorFactorInherit'], false, isBoolean),356 colorFactorFill: checkValue(data, [...path, 'colorFactorFill'], "#ffffffff 0,rgb linear,#000000ff 1", isGradient),357 colorFactorStroke: checkValue(data, [...path, 'colorFactorStroke'], "#ffffffff 0,rgb linear,#000000ff 1", isGradient),358 layers: checkLayers(data, [...path, 'layers'])359 }360 }361 },362 mask: {363 term: "Mask",364 category: "utility",365 validate: (data, path) => {366 return {367 type: "mask",368 name: checkValue(data, [...path, "name"], "", isString),369 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),370 visible: checkValue(data, [...path, "visible"], true, isBoolean),371 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),372 r: checkLength(data, [...path, 'r'], 0, 96),373 t: checkValue(data, [...path, 't'], 0, isNumber),374 x: checkLength(data, [...path, 'x'], 0, 96),375 y: checkLength(data, [...path, 'y'], 0, 96),376 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),377 invertMask: checkValue(data, [...path, 'invertMask'], false, isBoolean),378 showMask: checkValue(data, [...path, 'showMask'], false, isBoolean),379 masks: checkLayers(data, [...path, 'masks']),380 layers: checkLayers(data, [...path, 'layers'])381 }382 }383 },384 effect: {385 term: "Effect",386 category: "utility",387 validate: (data, path) => {388 return {389 type: "effect",390 name: checkValue(data, [...path, "name"], "", isString),391 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),392 visible: checkValue(data, [...path, "visible"], true, isBoolean),393 posMode: checkValue(data, [...path, "posMode"], "polar", isEnum("cartesian", "polar")),394 r: checkLength(data, [...path, 'r'], 0, 96),395 t: checkValue(data, [...path, 't'], 0, isNumber),396 x: checkLength(data, [...path, 'x'], 0, 96),397 y: checkLength(data, [...path, 'y'], 0, 96),398 rotation: checkValue(data, [...path, 'rotation'], 0, isNumber),399 showEffect: checkValue(data, [...path, 'showEffect'], true, isBoolean),400 definition: checkEffect(data, [...path, 'definition']),401 layers: checkLayers(data, [...path, 'layers'])402 }403 }404 },405 recolor: {406 term: "Recolor",407 category: "utility",408 validate: (data, path) => {409 return {410 type: "recolor",411 name: checkValue(data, [...path, "name"], "", isString),412 isOpen: checkValue(data, [...path, "isOpen"], true, isBoolean),413 visible: checkValue(data, [...path, "visible"], true, isBoolean),414 foreground: checkValue(data, [...path, 'foreground'], "#800", isColor),415 background: checkValue(data, [...path, 'background'], "#fff", isColor),416 layers: checkLayers(data, [...path, 'layers'])417 }418 }419 },420 note: {421 term: "Note",422 category: "utility",423 validate: (data, path) => {424 return {425 type: "note",426 name: checkValue(data, [...path, "name"], "", isString),427 isOpen: checkValue(data, [...path, "isOpen"], false, isBoolean),428 note: checkValue(data, [...path, "note"], "", isString)429 }430 }431 }432}433export const isString = a => typeof a === "string" ? a : undefined;434export const isGradient = a => typeof a === "string" ? (Gradient.fromString(a)?.toString() ?? undefined) : undefined;435export const isSpline = a => typeof a === "string" ? (Spline.fromString(a)?.toString() ?? undefined) : undefined;436export const isLiteral = (c) => { return a => a === c ? a : undefined; };437export const isNull = (a) => { return a === null ? a : typeof a === 'string' && a === '' ? null : undefined }438export const isColor = a => typeof a === "string" && COLOR_REGEX.test(a) ? a : undefined;439export const isNumber = a => !isNaN(Number(a)) ? Number(a) : undefined;440export const isEnum = (...values) => { return a => values.includes(a) ? a : undefined; }441export const isGT = (c) => { return a => Number(a) > c ? Number(a) : undefined }442export const isLT = (c) => { return a => Number(a) < c ? Number(a) : undefined }443export const isGTE = (c) => { return a => Number(a) >= c ? Number(a) : undefined }444export const isLTE = (c) => { return a => Number(a) <= c ? Number(a) : undefined }445export const isArray = a => Array.isArray(a) ? a : undefined;446export const isInteger = a => !isNaN(Number(a)) ? Math.round(a) : undefined;447export const isLegacy = (path) => {448 return (a, data) => a ?? get(path, undefined)449}450export const isBoolean = (a) => {451 if (a === true) { return true; }452 if (a === false) { return false; }453 if (a === 1) { return true; }454 if (a === 0) { return false; }455 if (typeof a === 'string') {456 if (a.toLowerCase() === "true") { return true; }457 if (a.toLowerCase() === "false") { return false; }458 }459 return undefined;460};461const checkValue = (data, path, fallback, ...funcs) => {462 const t = funcs.reduce((acc, func) => {463 if (acc === undefined) { return undefined; }464 return func(acc, data);465 }, get(data, path));466 if (t === undefined) {467 return fallback;468 }469 return t;470}471const checkStroke = (data, path) => {472 return {473 option: checkValue(data, [...path, 'option'], 'foreground', isEnum("foreground", "background", "none", "custom", "tween")),474 color: checkValue(data, [...path, 'color'], '#000', isColor),475 value: checkValue(data, [...path, 'value'], 1, isGTE(0)),476 unit: checkValue(data, [...path, 'unit'], 1, isEnum(1, 96, 25.4, 2.54)),477 useScale: checkValue(data, [...path, 'useScale'], false, isBoolean)478 }479}480const checkFill = (data, path) => {481 return {482 option: checkValue(data, [...path, 'option'], 'none', isEnum("foreground", "background", "none", "custom", "tween")),483 color: checkValue(data, [...path, 'color'], '#000', isColor)484 }485}486const checkPolygonRadius = (data, path, valueFB, unitFB, scaleFB, ...funcs) => {487 return {488 value: checkValue(data, [...path, "value"], valueFB, ...funcs),489 unit: checkValue(data, [...path, "unit"], unitFB, isEnum(1, 96, 2.54, 25.4)),490 useScale: checkValue(data, [...path, "useScale"], scaleFB, isBoolean)491 }492}493const checkLength = (data, path, valueFB, unitFB, useScale, useScribe, ...funcs) => {494 return {495 value: checkValue(data, [...path, "value"], valueFB, ...funcs),496 unit: checkValue(data, [...path, "unit"], unitFB, isEnum(1, 96, 2.54, 25.4))497 }498}499const checkLengthWithScale = (data, path, valueFB, unitFB, scaleFB, ...funcs) => {500 return {501 value: checkValue(data, [...path, "value"], valueFB, ...funcs),502 unit: checkValue(data, [...path, "unit"], unitFB, isEnum(1, 96, 2.54, 25.4)),503 useScale: checkValue(data, [...path, "useScale"], scaleFB, isBoolean)504 }505}506const checkLayers = (data, path) => {507 return checkValue(data, path, [], isArray).map((each, i) => {508 const t = checkValue(each, ["type"], null, isEnum(...Object.keys(LAYERS)))509 if (t === null) { return undefined }510 return LAYERS[t].validate(data, [...path, i])511 }).filter(a => a !== undefined)512}513const checkEffect = (data, path) => {514 const t = checkValue(data, [...path, 'type'], null, isEnum(...Object.keys(EFFECTS)));515 if (t === null) { return null; }516 return EFFECTS[t].validate(data, path);517}518export const validateUpload = (data) => {519 const path = [];520 const result = {};521 result.name = checkValue(data, [...path, "name"], "", isString);522 result.colors = {523 foreground: checkValue(data, [...path, "colors", "foreground"], "#800", isColor),524 background: checkValue(data, [...path, "colors", "background"], "#fff", isLiteral("none"), isColor),525 canvas: checkValue(data, [...path, "colors", "canvas"], "#fff", isColor),526 viewport: checkValue(data, [...path, "colors", "viewport"], "#000", isColor)527 }528 result.dimensions = {529 w: checkLength(data, [...path, "dimensions", "w"], 5, 96, isGT(0)),530 h: checkLength(data, [...path, "dimensions", "h"], 5, 96, isGT(0))531 }532 result.layers = checkLayers(data, [...path, "layers"])533 return result;534}535const output = {536 validateUpload,537 LAYERS,538 EFFECTS539};540export default output;

Full Screen

Full Screen

Measurements.js

Source:Measurements.js Github

copy

Full Screen

...33 }34 }35 for (var i = 0; i < items.length; i++) {36 const roofmeasure = await RoofMeasure.create({37 bin: checkValue(items[i].bin),38 chimney: checkValue(items[i].chimney),39 chimneyInc: checkValue(items[i].chimneyInc),40 eave: checkValue(items[i].eave),41 eaveInc: checkValue(items[i].eaveInc),42 gableGrnd: checkValue(items[i].gableGrnd),43 gableGrndInc: checkValue(items[i].gableGrndInc),44 hipRM: checkValue(items[i].hipRM),45 hipRMInc: checkValue(items[i].hipRMInc),46 measureType: checkValue(items[i].measureType),47 newConst: checkValue(items[i].binewConstn),48 pitch: checkValue(items[i].pitch),49 ridge: checkValue(items[i].ridge),50 ridgeInc: checkValue(items[i].ridgeInc),51 roofTop: checkValue(items[i].roofTop),52 stories: checkValue(items[i].stories),53 totalSqFt: checkValue(items[i].totalSqFt),54 valleyRM: checkValue(items[i].valleyRM),55 valleyRMInc: checkValue(items[i].valleyRMInc),56 wall: checkValue(items[i].wall),57 wallInc: checkValue(items[i].wallInc),58 customer: id,59 });60 roofmeasure.save();61 }62 if (eaveItems.length > 0) {63 for (var i = 0; i < eaveItems.length; i++) {64 const eavemeasure = await EaveMeasure.create({65 adjOneStory: checkValue(eaveItems[i].adjOneStory),66 adjOneStoryInc: checkValue(eaveItems[i].adjOneStoryInc),67 adjOneStoryPrice: checkValue(eaveItems[i].adjOneStoryPrice),68 adjTwoStory: checkValue(eaveItems[i].adjTwoStory),69 adjTwoStoryInc: checkValue(eaveItems[i].adjTwoStoryInc),70 adjTwoStoryPrice: checkValue(eaveItems[i].adjTwoStoryPrice),71 corners: checkValue(eaveItems[i].corners),72 cornersPrice: checkValue(eaveItems[i].cornersPrice),73 difficultyPrice: checkValue(eaveItems[i].difficultyPrice),74 elbows: checkValue(eaveItems[i].elbows),75 extraExtensions: checkValue(eaveItems[i].extraExtensions),76 extraExtensionsPrice: checkValue(eaveItems[i].extraExtensionsPrice),77 oneStoryDown: checkValue(eaveItems[i].oneStoryDown),78 oneStoryDownPrice: checkValue(eaveItems[i].oneStoryDownPrice),79 oneStoryEaves: checkValue(eaveItems[i].oneStoryEaves),80 oneStoryPrice: checkValue(eaveItems[i].oneStoryPrice),81 twoStoryDown: checkValue(eaveItems[i].twoStoryDown),82 twoStoryDownPrice: checkValue(eaveItems[i].twoStoryDownPrice),83 twoStoryPrice: checkValue(eaveItems[i].twoStoryPrice),84 customer: id,85 });86 eavemeasure.save();87 }88 }89 } else {90 for (var i = 0; i < items.length; i++) {91 const roofmeasure = await RoofMeasure.create({92 bin: checkValue(items[i].bin),93 chimney: checkValue(items[i].chimney),94 chimneyInc: checkValue(items[i].chimneyInc),95 eave: checkValue(items[i].eave),96 eaveInc: checkValue(items[i].eaveInc),97 gableGrnd: checkValue(items[i].gableGrnd),98 gableGrndInc: checkValue(items[i].gableGrndInc),99 hipRM: checkValue(items[i].hipRM),100 hipRMInc: checkValue(items[i].hipRMInc),101 measureType: checkValue(items[i].measureType),102 newConst: checkValue(items[i].binewConstn),103 pitch: checkValue(items[i].pitch),104 ridge: checkValue(items[i].ridge),105 ridgeInc: checkValue(items[i].ridgeInc),106 roofTop: checkValue(items[i].roofTop),107 stories: checkValue(items[i].stories),108 totalSqFt: checkValue(items[i].totalSqFt),109 valleyRM: checkValue(items[i].valleyRM),110 valleyRMInc: checkValue(items[i].valleyRMInc),111 wall: checkValue(items[i].wall),112 wallInc: checkValue(items[i].wallInc),113 customer: id,114 });115 roofmeasure.save();116 }117 if (eaveItems.length > 0) {118 for (var i = 0; i < eaveItems.length; i++) {119 const eavemeasure = await EaveMeasure.create({120 adjOneStory: checkValue(eaveItems[i].adjOneStory),121 adjOneStoryInc: checkValue(eaveItems[i].adjOneStoryInc),122 adjOneStoryPrice: checkValue(eaveItems[i].adjOneStoryPrice),123 adjTwoStory: checkValue(eaveItems[i].adjTwoStory),124 adjTwoStoryInc: checkValue(eaveItems[i].adjTwoStoryInc),125 adjTwoStoryPrice: checkValue(eaveItems[i].adjTwoStoryPrice),126 corners: checkValue(eaveItems[i].corners),127 cornersPrice: checkValue(eaveItems[i].cornersPrice),128 difficultyPrice: checkValue(eaveItems[i].difficultyPrice),129 elbows: checkValue(eaveItems[i].elbows),130 extraExtensions: checkValue(eaveItems[i].extraExtensions),131 extraExtensionsPrice: checkValue(eaveItems[i].extraExtensionsPrice),132 oneStoryDown: checkValue(eaveItems[i].oneStoryDown),133 oneStoryDownPrice: checkValue(eaveItems[i].oneStoryDownPrice),134 oneStoryEaves: checkValue(eaveItems[i].oneStoryEaves),135 oneStoryPrice: checkValue(eaveItems[i].oneStoryPrice),136 twoStoryDown: checkValue(eaveItems[i].twoStoryDown),137 twoStoryDownPrice: checkValue(eaveItems[i].twoStoryDownPrice),138 twoStoryPrice: checkValue(eaveItems[i].twoStoryPrice),139 customer: id,140 });141 eavemeasure.save();142 }143 }144 }145 res.status(200).json({146 Success: "Success",147 });148 } catch (error) {149 return next(new ErrorResponse(error, 401));150 }151};152exports.addSelectionsMeasure = async (req, res, next) => {153 const { id, email, passToken, form } = req.body;154 try {155 const user = await User.findOne({ email });156 //checking if the email exists157 if (!user) {158 return next(new ErrorResponse("Email Invalid", 401));159 }160 //checking if the email exists161 if (user.passToken != passToken) {162 return next(new ErrorResponse("PassToken Invalid", 401));163 }164 let layer;165 if (form.oneLayer_remove === false) {166 layer = "Two layer";167 } else {168 layer = "One layer";169 }170 let delivery;171 if (form.ground_delivery === false) {172 delivery = "Roof top delivery";173 } else {174 delivery = "Ground delivery";175 }176 let bin;177 if (form.roof_bin === false) {178 bin = "Away from roof";179 } else {180 bin = "Near roof";181 }182 let decking;183 if (form.osb_decking === false && form.plywood_decking === false) {184 decking = "Fir decking";185 } else if (form.fir_decking === false && form.plywood_decking === false) {186 decking = "OSB decking";187 } else if (form.osb_decking === false && form.fir_decking === false) {188 decking = "Plywood decking";189 }190 let chimney;191 if (form.metal_chimney === false && form.concrete_chimney === false) {192 chimney = "Brick";193 } else if (194 form.brick_chimney === false &&195 form.concrete_chimney === false196 ) {197 chimney = "Metal";198 } else if (form.metal_chimney === false && form.brick_chimney === false) {199 chimney = "Concrete";200 }201 let install;202 if (form.satellite_reinstall === false) {203 install = "Solar panels";204 } else {205 install = "Satellite dish";206 }207 let warranty;208 if (form.work_warranty === false) {209 warranty = "Registered";210 } else {211 warranty = "Workman ship";212 }213 //finding the selections214 const findSelectionsMeasure = await SelectionsMeasure.find({215 customer: id,216 });217 if (findSelectionsMeasure.length === 1) {218 const newID = findSelectionsMeasure[0]._id;219 const updateselctions = await SelectionsMeasure.findByIdAndUpdate({220 _id: newID,221 });222 (updateselctions.Replace_ventilation = form.Replace_ventilation),223 (updateselctions.brand_roof = form.brand_roof),224 (updateselctions.capping_roof = form.capping_roof),225 (updateselctions.chimney_flashing = form.chimney_flashing),226 (updateselctions.color_roof = form.color_roof),227 (updateselctions.convert_BPS = form.convert_BPS),228 (updateselctions.drip_edge_flashing = form.drip_edge_flashing),229 (updateselctions.fourmat_BPS = form.fourmat_BPS),230 (updateselctions.hr_brand = form.hr_brand),231 (updateselctions.hr_shingle = form.hr_shingle),232 (updateselctions.ice_water_brand = form.ice_water_brand),233 (updateselctions.ice_water_protection = form.ice_water_protection),234 (updateselctions.new_ventilation = form.new_ventilation),235 (updateselctions.onemat_BPS = form.onemat_BPS),236 (updateselctions.reSeal_BPS = form.reSeal_BPS),237 (updateselctions.remove_ventilation = form.remove_ventilation),238 (updateselctions.ridge_ventilation = form.ridge_ventilation),239 (updateselctions.shingle_roof = form.shingle_roof),240 (updateselctions.starter_brand = form.starter_brand),241 (updateselctions.starter_shingle = form.starter_shingle),242 (updateselctions.threemat_BPS = form.threemat_BPS),243 (updateselctions.twomat_BPS = form.twomat_BPS),244 (updateselctions.underlay_brand = form.underlay_brand),245 (updateselctions.underlay_protection = form.underlay_protection),246 (updateselctions.valley_flashing = form.valley_flashing),247 (updateselctions.wall_roof_flashing = form.wall_roof_flashing),248 (updateselctions.layer = layer),249 (updateselctions.delivery = delivery),250 (updateselctions.bin = bin),251 (updateselctions.decking = decking),252 (updateselctions.chimney = chimney),253 (updateselctions.install = install),254 (updateselctions.warranty = warranty),255 updateselctions.save();256 } else {257 const selectionsmeasure = await SelectionsMeasure.create({258 Replace_ventilation: form.Replace_ventilation,259 brand_roof: form.brand_roof,260 capping_roof: form.capping_roof,261 chimney_flashing: form.chimney_flashing,262 color_roof: form.color_roof,263 convert_BPS: form.convert_BPS,264 drip_edge_flashing: form.drip_edge_flashing,265 fourmat_BPS: form.fourmat_BPS,266 hr_brand: form.hr_brand,267 hr_shingle: form.hr_shingle,268 ice_water_brand: form.ice_water_brand,269 ice_water_protection: form.ice_water_protection,270 new_ventilation: form.new_ventilation,271 onemat_BPS: form.onemat_BPS,272 reSeal_BPS: form.reSeal_BPS,273 remove_ventilation: form.remove_ventilation,274 ridge_ventilation: form.ridge_ventilation,275 shingle_roof: form.shingle_roof,276 starter_brand: form.starter_brand,277 starter_shingle: form.starter_shingle,278 threemat_BPS: form.threemat_BPS,279 twomat_BPS: form.twomat_BPS,280 underlay_brand: form.underlay_brand,281 underlay_protection: form.underlay_protection,282 valley_flashing: form.valley_flashing,283 wall_roof_flashing: form.wall_roof_flashing,284 layer: layer,285 delivery: delivery,286 bin: bin,287 decking: decking,288 chimney: chimney,289 install: install,290 warranty: warranty,291 customer: id,292 });293 selectionsmeasure.save();294 }295 res.status(200).json({296 Success: "Success",297 });298 } catch (error) {299 return next(new ErrorResponse(error, 401));300 }301};302exports.getAllMeasure = async (req, res, next) => {303 const { id, email, passToken } = req.body;304 try {305 const user = await User.findOne({ email });306 //checking if the email exists307 if (!user) {308 return next(new ErrorResponse("Email Invalid", 401));309 }310 //checking if the email exists311 if (user.passToken != passToken) {312 return next(new ErrorResponse("PassToken Invalid", 401));313 }314 const findRoofMeasure = await RoofMeasure.find({ customer: id });315 const findEaveMeasure = await EaveMeasure.find({ customer: id });316 const findSelectionMeasure = await SelectionsMeasure.find({ customer: id });317 res.status(200).json({318 Success: "Success",319 roof: findRoofMeasure,320 eave: findEaveMeasure,321 selection: findSelectionMeasure,322 });323 } catch (error) {324 return next(new ErrorResponse(error, 401));325 }326};327function checkValue(val) {328 let newVal;329 if (val === "" || val === undefined) {330 newVal = "0";331 } else {332 newVal = val;333 }334 return newVal;...

Full Screen

Full Screen

diagnosis.js

Source:diagnosis.js Github

copy

Full Screen

1function output(form) {2 var sum = 0 * 1;3 var checkvalue = $('input:radio[name="diagnosis1"]:checked').val() * 1;4 sum += checkvalue;5 checkvalue = $('input:radio[name="diagnosis2"]:checked').val() * 1;6 sum += checkvalue;7 checkvalue = $('input:radio[name="diagnosis3"]:checked').val() * 1;8 sum += checkvalue;9 checkvalue = $('input:radio[name="diagnosis4"]:checked').val() * 1;10 sum += checkvalue;11 checkvalue = $('input:radio[name="diagnosis5"]:checked').val() * 1;12 sum += checkvalue;13 checkvalue = $('input:radio[name="diagnosis6"]:checked').val() * 1;14 sum += checkvalue;15 checkvalue = $('input:radio[name="diagnosis7"]:checked').val() * 1;16 sum += checkvalue;17 checkvalue = $('input:radio[name="diagnosis8"]:checked').val() * 1;18 sum += checkvalue;19 checkvalue = $('input:radio[name="diagnosis9"]:checked').val() * 1;20 sum += checkvalue;21 checkvalue = $('input:radio[name="diagnosis10"]:checked').val() * 1;22 sum += checkvalue;23 24 document.getElementById("diagnosis-result").innerHTML = sum;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkValue('location', 'Dulles:Chrome', function(err, data) {4 if (!err) {5 console.log(data);6 }7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10wpt.checkStatus(function(err, data) {11 if (!err) {12 console.log(data);13 }14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17wpt.getLocations(function(err, data) {18 if (!err) {19 console.log(data);20 }21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24wpt.getTesters(function(err, data) {25 if (!err) {26 console.log(data);27 }28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTesters(function(err, data) {32 if (!err) {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.getTest('140127_7A_2G1', function(err, data) {39 if (!err) {40 console.log(data);41 }42});43var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.checkValue('test', 'test', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var check = wpt.checkValue;3check(1,2);4check(2,2);5check(2,3);6check(3,3);7check(3,4);8check(4,4);9check(4,5);10check(5,5);11check(5,6);12check(6,6);13check(6,7);14check(7,7);15check(7,8);16check(8,8);17check(8,9);18check(9,9);19check(9,10);20check(10,10);21check(10,11);22check(11,11);23check(11,12);24check(12,12);25check(12,13);26check(13,13);27check(13,14);28check(14,14);29check(14,15);30check(15,15);31check(15,16);32check(16,16);33check(16,17);34check(17,17);35check(17,18);36check(18,18);37check(18,19);38check(19,19);39check(19,20);40check(20,20);41check(20,21);42check(21,21);43check(21,22);44check(22,22);45check(22,23);46check(23,23);47check(23,24);48check(24,24);49check(24,25);50check(25,25);51check(25,26);52check(26,26);53check(26,27);54check(27,27);55check(27,28);56check(28,28);57check(28,29);58check(29,29);59check(29,30);60check(30,30);61check(30,31);62check(31,31);63check(31,32);64check(32,32);65check(32,33);66check(33,33);67check(33,34);68check(34,34);69check(34,35);70check(35,35);71check(35,36);72check(36,36);73check(36,37);74check(37,37);75check(37,38);76check(38,38);77check(38,39);78check(39,39);79check(39,40);80check(40,40);81check(40,41);82check(41,41);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var checkValue = wpt.checkValue;3var assert = require('assert');4var test = function() {5var result = checkValue(1, 1);6assert.equal(result, true, 'checkValue(1,1) should be true');7};8test();9exports.checkValue = function(value, expectedValue) {10return value === expectedValue;11};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wptInstance = new wpt();3var checkValue = wptInstance.checkValue;4var value = 'test';5var result = checkValue(value);6console.log(result);7module.exports = function () {8 this.checkValue = function (value) {9 if (value === 'test') {10 return 'value is correct';11 }12 else {13 return 'value is incorrect';14 }15 };16};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful