Best JavaScript code snippet using storybook-root
ssoTemplate.js
Source:ssoTemplate.js
1function LoginType(configParam){2 return `3 <div>4 <div class="socialLogin dflex ">5 ${configParam.socialLogin.map((config)=>`6 <button id="${config.type.toLowerCase()}-div" type="button" class="btn socialBtn mr18 btn-${config.type.toLowerCase()}" >7 <div class="social-imageWrapper ${configParam.socialLogin.length<=2?"border-right":"text-center"}"><img class="social-image ico-${config.type.toLowerCase()}" src=${config.logoUrl?config.logoUrl:"ok"} alt=${config.type} ></img></div>8 ${configParam.socialLogin.length<=2 ?`<div class="social-text medFont">${config.label}</div>`:""}9 </button>10 `).join("")} 11 </div>12 <div class="truecaller hide">13 <input id="truecaller" class="trueCallerInput boldFont" autocomplete="off" type="number" placeholder="enter Mobile No " maxlength="10">14 </div>15 ${configParam.socialLogin.length?16 `<div class="separator ovalsep">17 <span class="boldFont ">OR</span>18 </div>`:""19 }20 21 ${configParam.nonSocialLogin && configParam.nonSocialLogin.loginVia.length==2?22 `<div class="non-social-section">23 <div class="emailAndMobile posRelative">24 ${configParam.nonSocialLogin.loginVia[0].toLowerCase()=="email"?25 ` <input id="emailAndMobile" required class="input-data boldFont focusActive" autocomplete="off" type="text" name="emailAndMobile" maxlength="100"><label class="floating-label">Enter Email or Mobile No</label>`:26 `<input id="emailAndMobile" class="input-data boldFont focusActive" autocomplete="off" type="text" name="emailAndMobile" maxlength="100"><label class="floating-label">Enter Mobile No or Email</label>`27 }28 </div>29 </div>30 `:31 `${configParam.nonSocialLogin && configParam.nonSocialLogin.loginVia[0].toLowerCase()=="email"?32 `<div class="non-social-section">33 <div class="emailOnly posRelative">34 <input id="emailOnly" required class="input-data boldFont" autocomplete="off" type="text" name="emailOnly" maxlength="100">35 <label class="floating-label">Enter email</label>36 </div>37 </div>38 `:39 `${configParam.nonSocialLogin && configParam.nonSocialLogin.loginVia[0].toLowerCase()=="mobile"?40 `<div class="non-social-section">41 <div class="mobileOnly posRelative">42 <input inputmode="tel" id="mobileOnly" required class="input-data boldFont" autocomplete="off" type="number" name="mobileOnly" maxlength="10">43 <label class="floating-label">Enter Mobile No</label>44 </div>45 </div>46 `:""47 }`48 }`49 } 50 <div class="error inputError"> </div> 51 <div class="unverified hide">52 <div class="notify-icon"></div>53 <div class="unverified-error"></div>54 </div> 55 <div>56 <button type="button" class=" continueLoginBtn continueBtn btn boldFont" value="CONTINUE" disabled>Continue</button>57 </div> 58 59 </div>`60 61}62function signinWithPassword(configParam){63 return `64 <div class="hide sign-with-pwd">65 <div class="boldFont modalTitle sign-in-Heading">Sign in with password </div>66 <div class="pwdFormBody ">67 <div class="dflex user-section">68 <div class="user-login-Detail">69 <div class="medFont user-pwd-info"></div>70 </div>71 <div class="link changelink medFont">Change</div>72 </div>73 <div class="custom-input posRelative dflex">74 <div class="input ">75 <input required class="reset-input required pwdPrefernce pwd-otp boldFont otpText" type="password" />76 <label class="floating-label">Enter Password</label>77 </div>78 <span class="link forget-password-link medFont">Forgot Password?</span>79 80 </div>81 <div class="error signIn-error"></div>82 ${siginbtn("Or Sign in with OTP","pwdSubmit","switchToOtpLink","Sign In",configParam)}83 </div>84 </div>`85}86function signinWithOtp(configParam){87 return `88 <div class="hide sign-with-otp">89 <div class="boldFont resetHeading modalTitle sign-in-Heading">Sign in with OTP </div>90 <div class="otpFormBody">91 ${enterotp(configParam,true,"otp")}92 ${siginbtn("Or Sign in with Password","otpSubmit","switchToPwdLink","Sign In",configParam)}93 </div>94 </div>`95}96function siginbtn(linktext,btnClass,className,btnText,configParam){97 return`98 <div class="signInBtn-wrapper">99 <button disabled class="btn signInBtn ${btnClass} continueBtn "> ${btnText}</button>100 ${configParam.nonSocialLogin.loginWith.length>1?101 `<div class="link boldFont toggleSignIn ${className}">${linktext}</div>`:""102 } 103 </div>` 104}105function pwdAndConfirmPwd(signup){106 return ` 107 <div class=" ${signup?"signupPwdSection sign-up-field":"nonSignupPwdSection"}">108 <div class="custom-input posRelative dflex textinput">109 <div class="input ">110 <input required id="passwordSignUp" data-required="required" required name="password" type="password" class=" reset-input password-field ${signup?"signupPwd ":" nonSignupPwd "}" />111 <label class="floating-label">Password</label>112 </div>113 <span class="eye-icon"></span>114 </div>115 ${!signup ?`<div class="info-icon"><div class="medFont passwordInfo">Can't match last 3 passwords.</div></div>`:""} 116 <div class="password-error error"></div>117 118 <div class="password-strength hide">119 <li class="uncheck chk1">6-14 characters</li>120 <li class="uncheck chk2">1 Lower case character (a-z)</li>121 <li class="uncheck chk3">1 Numeric character (0-9)</li>122 <li class="uncheck chk4">1 special character (Such as #, $, %, &, !)</li>123 </div>124 </div>`125 126}127function successLogin(configParam){128 return`<div class="ssoSuccessPage hide">129 <div class="successIcon"></div>130 <div class="success-heading modalTitle boldFont">Congratulations</div>131 <div class="boldFont fontBlack">You are now registered with ${configParam.displayChannel} and your user id is:</div>132 <div class="boldFont success-subHeading"></div>133 <div>Your account is valid across all Times Internet network</div>134 <div class="channel-image">135 <img class="" src="${configParam.staticPath}/src/img/toi.png"></img>136 <img class="" src="${configParam.staticPath}/src/img/nbt.png"></img>137 <img class="" src="${configParam.staticPath}/src/img/et.png"></img>138 <img class="" src="${configParam.staticPath}/src/img/mt.png"></img>139 <img class="" src="${configParam.staticPath}/src/img/gaana.png"></img>140 <img class="" src="${configParam.staticPath}/src/img/indiatimes.png"></img>141 <img class="" src="${configParam.staticPath}/src/img/st.png"></img>142 </div>143 <button class="boldFont btn successBtn continueBtn">Continue</button>144 </div>`145}146function enterotp(configParam,changeLink,triggerPoint){147 return `148 <div class="dflex user-section">149 <div class="user-login-Detail">150 <div class="medFont otpVerifyTitle">${triggerPoint=="verify"?"Enter verification code sent to":"OTP has been sent to"}</div>151 <div class="boldFont user-otp-info"></div>152 </div>153 ${changeLink?`<div class="link changelink medFont">Change</div>`:""} 154 </div>155 <div class="custom-input posRelative dflex">156 <div class="input ">157 <input inputmode="numeric" required class="reset-input ${triggerPoint+"Input"} pwd-otp boldFont otpText" type="text"/>158 <label class="floating-label">Enter OTP</label>159 </div>160 <span class="link hide ${triggerPoint+"ResentLink"} resend-otp-link medFont">Resend OTP</span>161 <div class="timerWrapper show">162 <div class="pie spinner" style="animation: rota ${configParam.resendOtpTimer+"s"} linear infinite"></div>163 <div class="pie filler" style="animation: opa ${configParam.resendOtpTimer+"s"} steps(1, end) infinite reverse"></div>164 <div class="mask" style="animation: opa ${configParam.resendOtpTimer+"s"} steps(1, end) infinite"></div>165 </div>166 <span class="green-tick hide"></span>167 </div>168 <div class="error signIn-error"></div>`169}170function verifyUser(configParam){171 return`172 <div class="verify-user hide">173 <div class="boldFont resetHeading modalTitle verify-heading">Verify </div>174 ${(configParam.signupForm.MandatoryVerifyVia.length==2)?175 `<div class="show verifySection1 sectionToVerify" >${enterotp(configParam,false,"verify")}</div>176 <div class=" hide verifySection2 sectionToVerify"> ${enterotp(configParam,false,"verify")}</div>`177 :`<div class="show verifySection1 sectionToVerify">${enterotp(configParam,false,"verify")}</div>`178 } 179 <button disabled class="btn verifyBtn continueBtn "> Verify</button> 180 </div>`181}182function passwordChangedsuccess(){183 return `<div class="password-changed modalTitle hide">184 <div class="boldFont forgot-pwd-heading">Password Changed Successfully</div>185 <div>Your new password will be effective for TimesPoints and all other Times network sites.</div>186 <button class="boldFont btn signIn continueBtn">Sign In</button>187 </div>`188}189function forgotPassword(configParam){190 return `191 <div class="forgot-password hide">192 <div class="boldFont modalTitle forgot-pwd-heading">Forgot Password</div>193 <div class="slectOtpGenPt hide">194 <div>195 <div class="txt medFont">We will send you a reset OTP on your registered E-mail ID or Mobile Number</div>196 <div class=" circle radio-uncheck medFont select-mobile"></div>197 <div class="circle radio-uncheck medFont select-email"></div>198 </div>199 <div>200 <button class="boldFont btn forgetContinueBtn continueBtn">Continue</button>201 </div>202 </div>203 <div class="direct-otp hide">204 ${enterotp(configParam,true,"forgot")}205 <div>206 ${pwdAndConfirmPwd()}207 <button disabled class="boldFont btn submitResetPwd continueBtn">Continue</button>208 </div>209 </div> 210 </div>`211}212function signupform(configParam){213 return `214 <div id="signUp-div" class="mediumPanel hide clearfix" >215 <form class="tlogins sign-in-form ">216 <fieldset>217 <div class="sign-up-wrapper boldFont modalTitle">Sign up</div>218 <div class="newUser-error hide">219 <div class="error medFont">You are not registered with TimesPoints.</div>220 <div id="emailReg-error medFont" class="error"> Please sign up.</div>221 </div>222 ${Object.keys(configParam.signupForm.signUpFields).map((signup)=>223 `<div class="form-group posRelative sign-up-field textinput">224 <input required type=${signup.toLowerCase()=="mobilenumber"?"tel":"text"} name=${signup.toLowerCase()} id=${signup} data-required=${configParam.signupForm.signUpFields[signup].required?"required":"optional"} class="form-control ${signup.toLowerCase()}" />225 <label class="floating-label" for=${signup}>${configParam.signupForm.signUpFields[signup].required?"*":""}${configParam.signupForm.signUpFields[signup].placeholder}</label>226 <div class="error ${signup.toLowerCase()}-error"></div>227 </div>`228 ).join("")} 229 ${configParam.signupForm.signupVia[0]=="Password" ?230 `${pwdAndConfirmPwd("signup")}`:""231 }232 ${configParam.signupForm.recaptcha ?233 `<div class="form-group">234 <div class="g-recaptcha" ${configParam.signupForm.recaptcha.required==true?"required":""} data-sitekey="6LcXeh0TAAAAAO1DsEX1iEF8n8-E_hQB67bIpxIw"></div>235 </div>`:""236 }237 238 <div class="terms sign-up-field termsCondition ">239 <div class=" checkTerms medFont ${configParam.defaultSelected?"t-check":"t-uncheck"}">240 <span>I agree to the </span>241 <a href=${configParam.termsConditionLink} target="_blank" class="link termsConditionLink">Terms and Conditions</a>242 </div>243 <div class="error termsError"></div>244 </div>245 <div>246 <div class="consent sign-up-field terms ">247 <div class=" checkTerms medFont ${configParam.defaultSelected?"t-check":"t-uncheck"}">248 <span>I consent to allow my data to be 249 <span>used to personalised ads </span>250 </div>251 <div class="error termsError"></div>252 </div>253 <div class="signup-error error"></div>254 <div class="form-group">255 <button type="button" id="registerbtn" class="btn btn-register sign-up continueBtn">Sign Up</button>256 </div>257 258 </fieldset>259 </form>260 </div> 261 `262}263export function createHTMLTemplate(configParam){264 var temp;265 return temp= `266 <section class="ssoLoginWidget">267 <div class="ssoContainer" id="nonLoggedInUser">268 <div class="row">269 <div class="ssoMainWrapper clearfix">270 ${configParam.closeIcon?271 `<img class="cross-icon" src="${configParam.staticPath}/src/img/close-icon.png"/>`:""272 }273 <div class="ssoLeftSection">274 <div class="minht">275 <a href="#" class="logobrand">276 <img id="channelLogo" src=${configParam.channelLogo}></a>277 ${successLogin(configParam)}278 <div class="loginForm active show">279 <div class=""> 280 <p>${configParam.subTitle}</p>281 </div>282 <div class="boldFont modalTitle sign-in-text">Sign In with</div>283 <div class="mediumPanel clearfix">284 ${LoginType(configParam)} 285 </div>286 <div class="initSignup medFont">287 <span>Donât have an account?</span>288 <span id="signUpLink" class="link sign-up-link"> Create one.</span>289 </div>290 </div>291 ${signinWithOtp(configParam)}292 ${signinWithPassword(configParam)} 293 ${verifyUser(configParam)}294 ${forgotPassword(configParam)}295 ${signupform(configParam)}296 ${passwordChangedsuccess()}297 </div>298 <div class="footer-logo"><img src="${configParam.staticPath}/src/img/timeslogin.png" class="timesLoginLogo"></img></div>299 </div>300 <div class="show sso-footer-img">301 ${configParam.isMobileView ?`<img src="${configParam.staticPath}/src/img/group-mob.png"></img>`302 :`<img src="${configParam.staticPath}/src/img/bg-img.png"></img>`303 }304 </div>305 </div>306 </div>307 </div>308 </section>` ...
config-param.ts
Source:config-param.ts
1import os from "os"2import { QError } from "./utils"3function toPascal(s: string): string {4 return s !== "" ? `${s[0].toUpperCase()}${s.substr(1).toLowerCase()}` : ""5}6function splitNonEmpty(s: string, separator = ","): string[] {7 return s8 .split(separator)9 .map(x => x.trim())10 .filter(x => x !== "")11}12function toOption(s: string): string {13 return splitNonEmpty(s.toLowerCase(), " ").join("-")14}15function withPrefix(prefix: string, s: string): string {16 return prefix !== "" ? `${prefix} ${s}` : s17}18export type DeepPartial<T> = {19 [P in keyof T]?: DeepPartial<T[P]>20}21type ValueParser<T extends ConfigValue> = (s: string) => T | undefined22const parse = {23 boolean: (s: string): boolean | undefined => s.toLowerCase() === "true",24 integer(s: string): number | undefined {25 if (s.trim() === "") {26 return undefined27 }28 const n = Number(s)29 if (!Number.isInteger(n)) {30 throw new Error(`Not valid integer: ${s}`)31 }32 return n33 },34 string: (s: string): string | undefined => s,35 array: (s: string): string[] | undefined => splitNonEmpty(s),36 map(s: string): Record<string, string> {37 return splitNonEmpty(s).reduce(38 (map, nameValue): Record<string, string> => {39 let i = nameValue.indexOf("=")40 if (i < 0) {41 i = nameValue.length42 }43 return {44 ...map,45 [nameValue.substr(0, i)]: nameValue.substr(i + 1),46 }47 },48 {} as Record<string, string>,49 )50 },51}52export type ConfigValue =53 | boolean54 | number55 | string56 | string[]57 | Record<string, string>58type HotColdParams = {59 hot: ConfigParam<string[]>60 cache: ConfigParam<string>61 cold: ConfigParam<string[]>62}63type BlockchainParams = {64 hotCache: ConfigParam<string>65 hotCacheExpiration: ConfigParam<number>66 hotCacheEmptyDataExpiration: ConfigParam<number>67 accounts: ConfigParam<string[]>68 blocks: HotColdParams69 transactions: HotColdParams70 zerostate: ConfigParam<string>71}72export class ConfigParam<T extends ConfigValue> {73 optionName: string74 env: string75 private constructor(76 public option: string,77 public defaultValue: T,78 public description: string,79 public parser: ValueParser<T>,80 public deprecated: boolean = false,81 ) {82 const words = option.split("-")83 this.env = `Q_${words.map(x => x.toUpperCase()).join("_")}`84 this.optionName = `${words[0]}${words.slice(1).map(toPascal).join("")}`85 }86 descriptionWithDefaults(): string {87 const defaultValueStr = this.defaultValueAsString()88 return `${this.description}${89 defaultValueStr !== "" ? ` (default: "${defaultValueStr}")` : ""90 }`91 }92 static string(93 option: string,94 defaultValue: string,95 description: string,96 deprecated = false,97 ): ConfigParam<string> {98 return new ConfigParam(99 option,100 defaultValue,101 description,102 parse.string,103 deprecated,104 )105 }106 static integer(107 option: string,108 defaultValue: number,109 description: string,110 deprecated = false,111 ): ConfigParam<number> {112 return new ConfigParam(113 option,114 defaultValue,115 description,116 parse.integer,117 deprecated,118 )119 }120 static boolean(121 option: string,122 defaultValue: boolean,123 description: string,124 deprecated = false,125 ): ConfigParam<boolean> {126 return new ConfigParam(127 option,128 defaultValue,129 description,130 parse.boolean,131 deprecated,132 )133 }134 static array(135 option: string,136 defaultValue: string[],137 description: string,138 deprecated = false,139 ): ConfigParam<string[]> {140 return new ConfigParam(141 option,142 defaultValue,143 description,144 parse.array,145 deprecated,146 )147 }148 static map(149 option: string,150 defaultValue: Record<string, string>,151 description: string,152 deprecated = false,153 ): ConfigParam<Record<string, string>> {154 return new ConfigParam(155 option,156 defaultValue,157 description,158 parse.map,159 deprecated,160 )161 }162 static dataDeprecated(prefix: string): {163 mut: ConfigParam<string>164 hot: ConfigParam<string>165 cold: ConfigParam<string[]>166 cache: ConfigParam<string>167 counterparties: ConfigParam<string>168 } {169 function dataParam<T extends ConfigValue>(170 name: string,171 defaultValue: T,172 description: string,173 parser: ValueParser<T>,174 ) {175 return new ConfigParam<T>(176 `${toOption(prefix)}-${name}`,177 defaultValue,178 withPrefix(toPascal(prefix), description),179 parser,180 true,181 )182 }183 return {184 mut: dataParam(185 "mut",186 "arangodb",187 "mutable db config url",188 parse.string,189 ),190 hot: dataParam(191 "hot",192 "arangodb",193 "hot db config url",194 parse.string,195 ),196 cold: dataParam(197 "cold",198 [],199 "cold db config urls (comma separated)",200 parse.array,201 ),202 cache: dataParam("cache", "", "cache config url", parse.string),203 counterparties: dataParam(204 "counterparties",205 "",206 "counterparties db config url",207 parse.string,208 ),209 }210 }211 static hotCold(prefix: string, descriptionPrefix?: string): HotColdParams {212 descriptionPrefix ??= prefix213 return {214 hot: ConfigParam.databases(215 withPrefix(prefix, "hot"),216 withPrefix(descriptionPrefix, "hot"),217 ),218 cache: ConfigParam.string(219 `${toOption(prefix)}-cache`,220 "",221 withPrefix(toPascal(descriptionPrefix), "cache server"),222 ),223 cold: ConfigParam.databases(224 withPrefix(prefix, "cold"),225 withPrefix(descriptionPrefix, "cold"),226 ),227 }228 }229 static databases(230 prefix: string,231 descriptionPrefix?: string,232 ): ConfigParam<string[]> {233 descriptionPrefix ??= prefix234 return ConfigParam.array(235 toOption(prefix),236 [],237 withPrefix(toPascal(descriptionPrefix), "databases"),238 )239 }240 static blockchain(prefix: string): BlockchainParams {241 const zerostatePrefix = withPrefix(prefix, "zerostate")242 return {243 hotCache: ConfigParam.string(244 `${prefix !== "" ? `${toOption(prefix)}-` : ""}hot-cache`,245 "",246 withPrefix(toPascal(prefix), "hot cache server"),247 ),248 hotCacheExpiration: ConfigParam.integer(249 `${250 prefix !== "" ? `${toOption(prefix)}-` : ""251 }hot-cache-expiration`,252 10,253 withPrefix(toPascal(prefix), "hot cache expiration in seconds"),254 ),255 hotCacheEmptyDataExpiration: ConfigParam.integer(256 `${257 prefix !== "" ? `${toOption(prefix)}-` : ""258 }hot-cache-empty-data-expiration`,259 2,260 withPrefix(261 toPascal(prefix),262 "hot cache empty entries expiration in seconds",263 ),264 ),265 accounts: ConfigParam.databases(withPrefix(prefix, "accounts")),266 blocks: ConfigParam.hotCold(withPrefix(prefix, "blocks")),267 transactions: ConfigParam.hotCold(268 withPrefix(prefix, "transactions"),269 withPrefix(prefix, "transactions and messages"),270 ),271 zerostate: ConfigParam.string(272 toOption(zerostatePrefix),273 "",274 withPrefix(toPascal(zerostatePrefix), "database"),275 ),276 }277 }278 static resolvePath(279 path: string[],280 value: Record<string, unknown>,281 ): ConfigValue | undefined {282 let parent: Record<string, unknown> | undefined = value283 for (let i = 0; i < path.length - 1 && parent !== undefined; i += 1) {284 parent = parent[path[i]] as Record<string, unknown>285 }286 return parent !== undefined287 ? (parent[path[path.length - 1]] as ConfigValue | undefined)288 : undefined289 }290 /**291 * Converts value specified in program option or environment variable into param type.292 * Returns undefined if value can't be converted.293 */294 parse(value: ConfigValue | undefined | null): ConfigValue | undefined {295 if (value === undefined || value === null) {296 return undefined297 }298 try {299 return this.parser(value.toString().trim())300 } catch (error) {301 throw QError.invalidConfigValue(302 this.option,303 error.message ?? error.toString(),304 )305 }306 }307 resolve(308 path: string[],309 options: Record<string, ConfigValue>,310 json: Record<string, unknown>,311 env: Record<string, string>,312 specified?: ConfigParam<ConfigValue>[],313 ): unknown | undefined {314 let resolved: ConfigValue | undefined =315 this.parse(options[this.optionName]) ??316 ConfigParam.resolvePath(path, json) ??317 this.parse(env[this.env])318 if (resolved !== undefined && specified !== undefined) {319 specified.push(this)320 }321 if (resolved === undefined && !this.deprecated) {322 resolved = this.defaultValue323 }324 if (resolved === "{ip}") {325 resolved = getIp()326 }327 return resolved328 }329 static resolveConfig<T>(330 options: Record<string, ConfigValue>,331 json: DeepPartial<T>,332 env: Record<string, string>,333 params: Record<string, unknown>,334 ): {335 config: T336 specified: ConfigParam<ConfigValue>[]337 } {338 const specified: ConfigParam<ConfigValue>[] = []339 const resolve = (340 path: string[],341 params: Record<string, unknown>,342 ): Record<string, unknown> | undefined => {343 let resolved: Record<string, unknown> | undefined = undefined344 for (const [name, param] of Object.entries(params)) {345 const paramPath = [...path, name]346 const value =347 param instanceof ConfigParam348 ? param.resolve(349 paramPath,350 options,351 json,352 env,353 specified,354 )355 : resolve(paramPath, param as Record<string, unknown>)356 if (value !== undefined) {357 if (resolved === undefined) {358 resolved = { [name]: value }359 } else {360 resolved[name] = value361 }362 }363 }364 return resolved365 }366 return {367 config: resolve([], params) as T,368 specified,369 }370 }371 static getAll(params: Record<string, unknown>): ConfigParam<ConfigValue>[] {372 const all: ConfigParam<ConfigValue>[] = []373 const collect = (params: Record<string, unknown>) => {374 for (const param of Object.values(params)) {375 if (param instanceof ConfigParam) {376 all.push(param)377 } else {378 collect(param as Record<string, unknown>)379 }380 }381 }382 collect(params)383 return all384 }385 defaultValueAsString(): string {386 const v = this.defaultValue387 if (v === null || v === undefined || v === "") {388 return ""389 }390 if (391 typeof v === "string" ||392 typeof v === "number" ||393 typeof v === "boolean"394 ) {395 return `${v}`396 }397 if (Array.isArray(v)) {398 return v.join(",")399 }400 if (401 typeof v === "object" &&402 v !== null &&403 Object.keys(v).length === 0404 ) {405 return ""406 }407 return JSON.stringify(v)408 }409}410function getIp(): string {411 for (const networkInterfaces of Object.values(os.networkInterfaces())) {412 if (networkInterfaces !== undefined) {413 for (const networkInterface of networkInterfaces) {414 if (415 networkInterface.family === "IPv4" &&416 !networkInterface.internal417 ) {418 return networkInterface.address419 }420 }421 }422 }423 return ""...
configParamController.js
Source:configParamController.js
1'use strict';2/*---------------ConfigParam----------------------*/3var mongoose = require('mongoose'),4 ConfigParam = mongoose.model('ConfigParam');5var authController = require('../controllers/authController');6exports.create_an_configParam = async function (req, res) {7 var new_configParam = new ConfigParam(req.body);8 ConfigParam.find({}, function (err, configParams) {9 if (err) {10 res.status(500).send(err);11 } else {12 if (configParams.length > 0) {13 res.status(500).send("Cannot create more than one config param");14 } else {15 new_configParam.save(function (err, configParam) {16 if (err) {17 if (err.name == 'ValidationError') {18 res.status(422).send(err);19 } else {20 console.log(configParam);21 res.status(500).send(err);22 }23 } else {24 res.status(200).json(configParam);25 }26 });27 }28 }29 });30};31exports.read_an_configParam = function (req, res) {32 ConfigParam.find({}, function (err, configParam) {33 if (err) {34 res.status(500).send(err);35 } else {36 res.status(200).json(configParam);37 }38 });39};40exports.update_an_configParam = function (req, res) {41 var configParamSystem = null;42 ConfigParam.find(function (err, configParam) {43 if (err) {44 res.status(500).send(err);45 } else {46 configParamSystem = configParam;47 if(configParam[0] != null){48 ConfigParam.findOneAndUpdate({49 _id: configParamSystem[0]._id50 }, req.body, {51 new: true,52 runValidators: true53 }, function (err, configParam) {54 if (err) {55 res.status(500).send(err);56 } else {57 res.json(configParam);58 }59 });60 } else {61 res.status(500).send("Configuration parameters are not initialized");62 }63 }64 });...
Using AI Code Generation
1import { configParam } from 'storybook-root-config';2import { withKnobs } from '@storybook/addon-knobs';3export default {4};5export const test = () => {6 const param = configParam('param');7 console.log(param);8 return `<div>${param}</div>`;9};10import { addParameters } from '@storybook/react';11import { withKnobs } from '@storybook/addon-knobs';12import * as config from 'storybook-root-config';13addParameters({14});15export const decorators = [withKnobs];16module.exports = {17};18import { addons } from '@storybook/addons';19import { themes } from '@storybook/theming';20addons.setConfig({21});22import { configure } from '@storybook/react';23import { addParameters } from '@storybook/react';24import { withKnobs } from '@storybook/addon-knobs';25import * as config from 'storybook-root-config';26addParameters({27});28export const decorators = [withKnobs];29export const parameters = {30 actions: { argTypesRegex: '^on[A-Z].*' },31};32const path = require('path');33module.exports = ({ config }) => {34 config.module.rules.push({35 test: /\.(ts|tsx)$/,36 include: path.resolve(__dirname, '../'),37 {38 loader: require.resolve('ts-loader'),39 },40 {41 loader: require.resolve('react-docgen-typescript-loader'),42 },43 });44 config.resolve.extensions.push('.ts', '.tsx');45 return config;46};47import { addParameters } from '@storybook/react';48import { withKnobs } from '@storybook/addon-knobs';49import * as config from 'storybook-root-config';50addParameters({51});52export const decorators = [withKnobs];53module.exports = {
Using AI Code Generation
1import { configParam } from 'storybook-root-decorator';2configParam('backgroundColor', 'blue');3configParam('padding', '10px');4configParam('border', '1px solid red');5configParam('borderRadius', '5px');6configParam('color', 'white');7configParam('width', '200px');8configParam('height', '200px');9configParam('fontSize', '20px');10configParam('fontWeight', 'bold');11configParam('textAlign', 'center');12configParam('lineHeight', '200px');13configParam('boxSizing', 'border-box');14configParam('display', 'inline-block');15configParam('margin', '10px');16configParam('textTransform', 'uppercase');17configParam('letterSpacing', '1px');18configParam('cursor', 'pointer');19configParam('userSelect', 'none');20configParam('transition', 'all 0.3s ease-in-out');21configParam('
Using AI Code Generation
1import { configParam } from 'storybook-root-decorator'2configParam({ name: 'foo', value: 'bar' })3import { withRootDecorator } from 'storybook-root-decorator'4import { withRootDecorator } from 'storybook-root-decorator'5import { withRootDecorator } from 'storybook-root-decorator'6import { withRootDecorator } from 'storybook-root-decorator'7import { withRootDecorator } from 'storybook-root-decorator'8import { withRootDecorator } from 'storybook-root-decorator'9import { withRootDecorator } from 'storybook-root-decorator'
Using AI Code Generation
1const configParam = require('storybook-root').configParam;2const config = configParam('myConfig');3module.exports = {4 webpackFinal: async (config, { configType }) => {5 return config;6 }7};8import { configure } from '@storybook/react';9configure(require.context('../stories', true, /\.stories\.js$/), module);10module.exports = ({ config, mode }) => {11 config.module.rules.push({
Using AI Code Generation
1import { configParam } from 'storybook-root';2const param = configParam('myParam');3console.log(param);4import { setConfigParam } from 'storybook-root';5setConfigParam('myParam', 'myValue');6import { setConfigParam } from 'storybook-root-v5';7setConfigParam('myParam', 'myValue');8import { configParam } from 'storybook-root-v5';9const param = configParam('myParam');10console.log(param);11Copyright (c) 2019-2020, Manoj Kumar
Using AI Code Generation
1const { configParam } = require('storybook-root-config');2const { config } = require('./main.js');3module.exports = configParam(config, 'test');4module.exports = {5};6const { configParam } = require('storybook-root-config');7const { config } = require('../main.js');8module.exports = configParam(config, 'config');9const { configParam } = require('storybook-root-config');10const { config } = require('../main.js');11module.exports = configParam(config, 'preview');12const { configParam } = require('storybook-root-config');13const { config } = require('../main.js');14module.exports = configParam(config, 'manager');15const { configParam } = require('storybook-root-config');16const { config } = require('../main.js');17module.exports = configParam(config, 'webpack');18const { configParam } = require('storybook-root-config');19const { config } = require('../main.js');20module.exports = configParam(config, 'addons');21const { configParam } = require('storybook-root-config');22const { config } = require('../main.js');23module.exports = configParam(config, 'babel');24const { configParam } = require('storybook-root-config');25const { config } = require('../main.js');26module.exports = configParam(config, 'tsconfig');27const { configParam } = require('storybook-root-config');28const { config } = require('../main.js');29module.exports = configParam(config, 'preview-head');30const { configParam } = require('storybook-root-config');31const { config } = require('../main.js');32module.exports = configParam(config, 'preview-body');33const { configParam } = require('storybook-root-config');34const { config } = require('../main.js');35module.exports = configParam(config, 'manager-head');36const { configParam } = require('
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!