How to use dir method in mountebank

Best JavaScript code snippet using mountebank

_gfxBidiSupport.js.uncompressed.js

Source:_gfxBidiSupport.js.uncompressed.js Github

copy

Full Screen

1define("dojox/gfx/_gfxBidiSupport", ["./_base", "dojo/_base/lang","dojo/_base/sniff", "dojo/dom", "dojo/_base/html", "dojo/_base/array",2 "./utils", "./shape", "./path", "dojox/string/BidiEngine"],3function(g, lang, has, dom, html, arr, utils, shapeLib, pathLib, BidiEngine){4 lang.getObject("dojox.gfx._gfxBidiSupport", true);5 /*=====6 // Prevent changes here from masking the definitions in _base.js from the doc parser7 var origG = g;8 g = {};9 =====*/10 switch (g.renderer){11 case 'vml':12 g.isVml = true;13 break;14 case 'svg':15 g.isSvg = true;16 if(g.svg.useSvgWeb){17 g.isSvgWeb = true;18 }19 break;20 case 'silverlight':21 g.isSilverlight = true;22 break;23 case 'canvas':24 case 'canvasWithEvents':25 g.isCanvas = true;26 break;27 }28 var bidi_const = {29 LRM : '\u200E',30 LRE : '\u202A',31 PDF : '\u202C',32 RLM : '\u200f',33 RLE : '\u202B'34 };35 /*===== g = origG; =====*/36 // the object that performs text transformations.37 var bidiEngine = new BidiEngine();38 lang.extend(g.shape.Surface, {39 // textDir: String40 // Will be used as default for Text/TextPath/Group objects that created by this surface41 // and textDir wasn't directly specified for them, though the bidi support was loaded.42 // Can be set in two ways:43 //44 // 1. When the surface is created and textDir value passed to it as fourth45 // parameter.46 // 2. Using the setTextDir(String) function, when this function is used the value47 // of textDir propagates to all of it's children and the children of children (for Groups) etc.48 textDir: "",49 setTextDir: function(/*String*/newTextDir){50 // summary:51 // Used for propagation and change of textDir.52 // newTextDir will be forced as textDir for all of it's children (Group/Text/TextPath).53 setTextDir(this, newTextDir);54 },55 getTextDir: function(){56 return this.textDir;57 }58 });59 lang.extend(g.Group, { 60 // textDir: String61 // Will be used for inheritance, or as default for text objects62 // that textDir wasn't directly specified for them but the bidi support was required.63 textDir: "",64 setTextDir: function(/*String*/newTextDir){65 // summary:66 // Used for propagation and change of textDir.67 // newTextDir will be forced as textDir for all of it's children (Group/Text/TextPath).68 setTextDir(this, newTextDir);69 },70 getTextDir: function(){71 return this.textDir;72 } 73 });74 75 lang.extend(g.Text, { 76 // summary:77 // Overrides some of dojox/gfx.Text properties, and adds some78 // for bidi support.79 80 // textDir: String81 // Used for displaying bidi scripts in right layout.82 // Defines the base direction of text that displayed, can have 3 values:83 //84 // 1. "ltr" - base direction is left to right.85 // 2. "rtl" - base direction is right to left.86 // 3. "auto" - base direction is contextual (defined by first strong character).87 textDir: "",88 formatText: function (/*String*/ text, /*String*/ textDir){89 // summary:90 // Applies the right transform on text, according to renderer.91 // text: 92 // the string for manipulation, by default return value.93 // textDir: 94 // Text direction.95 // Can be:96 //97 // 1. "ltr" - for left to right layout.98 // 2. "rtl" - for right to left layout99 // 3. "auto" - for contextual layout: the first strong letter decides the direction.100 // description:101 // Finds the right transformation that should be applied on the text, according to renderer.102 // Was tested in:103 //104 // Renderers (browser for testing):105 //106 // - canvas (FF, Chrome, Safari),107 // - vml (IE),108 // - svg (FF, Chrome, Safari, Opera),109 // - silverlight (IE, Chrome, Safari, Opera),110 // - svgWeb(FF, Chrome, Safari, Opera, IE).111 //112 // Browsers [browser version that was tested]:113 //114 // - IE [6,7,8], FF [3.6],115 // - Chrome (latest for March 2011),116 // - Safari [5.0.3],117 // - Opera [11.01].118 if(textDir && text && text.length > 1){119 var sourceDir = "ltr", targetDir = textDir;120 121 if(targetDir == "auto"){122 //is auto by default123 if(g.isVml){124 return text;125 }126 targetDir = bidiEngine.checkContextual(text);127 }128 129 if(g.isVml){130 sourceDir = bidiEngine.checkContextual(text);131 if(targetDir != sourceDir){132 if(targetDir == "rtl"){133 return !bidiEngine.hasBidiChar(text) ? bidiEngine.bidiTransform(text,"IRNNN","ILNNN") : bidi_const.RLM + bidi_const.RLM + text;134 }else{135 return bidi_const.LRM + text;136 }137 }138 return text;139 }140 141 if(g.isSvgWeb){142 if(targetDir == "rtl"){143 return bidiEngine.bidiTransform(text,"IRNNN","ILNNN");144 }145 return text;146 }147 148 if(g.isSilverlight){149 return (targetDir == "rtl") ? bidiEngine.bidiTransform(text,"IRNNN","VLYNN") : bidiEngine.bidiTransform(text,"ILNNN","VLYNN");150 }151 152 if(g.isCanvas){153 return (targetDir == "rtl") ? bidi_const.RLE + text + bidi_const.PDF : bidi_const.LRE + text + bidi_const.PDF;154 }155 156 if(g.isSvg){157 if(has("ff") < 4){158 return (targetDir == "rtl") ? bidiEngine.bidiTransform(text,"IRYNN","VLNNN") : bidiEngine.bidiTransform(text,"ILYNN","VLNNN");159 }else{160 return bidi_const.LRM + (targetDir == "rtl" ? bidi_const.RLE : bidi_const.LRE) + text + bidi_const.PDF;161 } 162 } 163 }164 return text;165 }, 166 bidiPreprocess: function(newShape){ 167 return newShape;168 }169 });170 lang.extend(g.TextPath, {171 // textDir: String172 // Used for displaying bidi scripts in right layout.173 // Defines the base direction of text that displayed, can have 3 values:174 //175 // 1. "ltr" - base direction is left to right.176 // 2. "rtl" - base direction is right to left.177 // 3. "auto" - base direction is contextual (defined by first strong character).178 textDir: "",179 formatText: function (/*String*/text, /*String*/textDir){180 // summary:181 // Applies the right transform on text, according to renderer.182 // text:183 // the string for manipulation, by default return value.184 // textDir:185 // text direction direction.186 // Can be:187 //188 // 1. "ltr" - for left to right layout.189 // 2. "rtl" - for right to left layout190 // 3. "auto" - for contextual layout: the first strong letter decides the direction.191 // description:192 // Finds the right transformation that should be applied on the text, according to renderer.193 // Was tested in:194 //195 // Renderers:196 // canvas (FF, Chrome, Safari), vml (IE), svg (FF, Chrome, Safari, Opera), silverlight (IE8), svgWeb(FF, Chrome, Safari, Opera, IE).197 //198 // Browsers:199 // IE [6,7,8], FF [3.6], Chrome (latest for February 2011), Safari [5.0.3], Opera [11.01].200 if(textDir && text && text.length > 1){201 var sourceDir = "ltr", targetDir = textDir;202 if(targetDir == "auto"){203 //is auto by default204 if(g.isVml){205 return text;206 }207 targetDir = bidiEngine.checkContextual(text);208 }209 if(g.isVml){210 sourceDir = bidiEngine.checkContextual(text);211 if(targetDir != sourceDir){212 if(targetDir == "rtl"){213 return !bidiEngine.hasBidiChar(text) ? bidiEngine.bidiTransform(text,"IRNNN","ILNNN") : bidi_const.RLM + bidi_const.RLM + text;214 }else{215 return bidi_const.LRM + text;216 }217 }218 return text;219 }220 if(g.isSvgWeb){221 if(targetDir == "rtl"){222 return bidiEngine.bidiTransform(text,"IRNNN","ILNNN");223 }224 return text;225 }226 //unlike the g.Text that is rendered in logical layout for Bidi scripts.227 //for g.TextPath in svg always visual -> bidi script is unreadable (except Opera and FF start from version 4)228 if(g.isSvg){229 if(has("opera") || has("ff") >= 4){230 text = bidi_const.LRM + (targetDir == "rtl"? bidi_const.RLE : bidi_const.LRE) + text + bidi_const.PDF;231 }else{232 text = (targetDir == "rtl") ? bidiEngine.bidiTransform(text,"IRYNN","VLNNN") : bidiEngine.bidiTransform(text,"ILYNN","VLNNN");233 }234 } 235 } 236 return text;237 },238 bidiPreprocess: function(newText){239 if(newText && (typeof newText == "string")){240 this.origText = newText;241 newText = this.formatText(newText,this.textDir);242 }243 return newText;244 }245 }); 246 247 var extendMethod = function(shape, method, before, after){248 // summary:249 // Some helper function. Used for extending methods of shape.250 // shape: Object251 // The shape we overriding it's method.252 // method: String253 // The method that is extended, the original method is called before or after254 // functions that passed to extendMethod.255 // before: function256 // If defined this function will be executed before the original method.257 // after: function258 // If defined this function will be executed after the original method.259 var old = shape.prototype[method];260 shape.prototype[method] = 261 function(){262 var rBefore;263 if (before){264 rBefore = before.apply(this, arguments);265 }266 var r = old.call(this, rBefore);267 if (after){268 r = after.call(this, r, arguments);269 }270 return r;271 };272 };273 var bidiPreprocess = function(newText){274 if (newText){ 275 if (newText.textDir){276 newText.textDir = validateTextDir(newText.textDir);277 }278 if (newText.text && (newText.text instanceof Array)){279 newText.text = newText.text.join(",");280 }281 }282 if(newText && (newText.text != undefined || newText.textDir) && (this.textDir != newText.textDir || newText.text != this.origText)){283 // store the original text. 284 this.origText = (newText.text != undefined) ? newText.text : this.origText;285 if(newText.textDir){286 this.textDir = newText.textDir;287 }288 newText.text = this.formatText(this.origText,this.textDir);289 }290 return this.bidiPreprocess(newText);291 };292 // Instead of adding bidiPreprocess to all renders one by one293 // use the extendMethod, at first there's a need for bidi transformation 294 // on text then call to original setShape.295 extendMethod(g.Text,"setShape", bidiPreprocess, null);296 extendMethod(g.TextPath,"setText", bidiPreprocess, null);297 298 var restoreText = function(origObj){299 var obj = lang.clone(origObj);300 if (obj && this.origText){301 obj.text = this.origText;302 }303 return obj;304 };305 // Instead of adding restoreText to all renders one by one306 // use the extendMethod, at first get the shape by calling the original getShape,307 // than resrore original text (without the text transformations).308 extendMethod(g.Text, "getShape", null, restoreText);309 extendMethod(g.TextPath, "getText", null, restoreText);310 var groupTextDir = function(group, args){311 var textDir;312 if (args && args[0]){313 textDir = validateTextDir(args[0]);314 }315 group.setTextDir(textDir ? textDir : this.textDir);316 return group; // dojox/gfx.Group317 };318 // In creation of Group there's a need to update it's textDir,319 // so instead of doing it in renders one by one (vml vs others)320 // use the extendMethod, at first the original createGroup is applied, the321 // groupTextDir which is setts Group's textDir as it's father's or if was defined322 // by user by this value.323 extendMethod(g.Surface, "createGroup", null, groupTextDir);324 extendMethod(g.Group, "createGroup", null, groupTextDir);325 var textDirPreprocess = function(text){326 // inherit from surface / group if textDir is defined there327 if(text){328 var textDir = text.textDir ? validateTextDir(text.textDir) : this.textDir;329 if(textDir){330 text.textDir = textDir;331 }332 }333 return text;334 };335 // In creation there's a need to some preprocess,336 // so instead of doing it in renders one by one (vml vs others)337 // use the extendMethod, at first the textDirPreprocess function handles the input338 // then the original createXXXXXX is applied.339 extendMethod(g.Surface,"createText", textDirPreprocess, null);340 extendMethod(g.Surface,"createTextPath", textDirPreprocess, null);341 extendMethod(g.Group,"createText", textDirPreprocess, null);342 extendMethod(g.Group,"createTextPath", textDirPreprocess, null);343 /*=====344 // don't mask definition of original createSurface() function from doc parser345 g = {};346 =====*/347 g.createSurface = function(parentNode, width, height, textDir) {348 var s = g[g.renderer].createSurface(parentNode, width, height);349 var tDir = validateTextDir(textDir);350 351 if(g.isSvgWeb){352 s.textDir = tDir ? tDir : html.style(dom.byId(parentNode),"direction");353 return s;354 }355 // if textDir was defined use it, else get default value.356 //s.textDir = tDir ? tDir : html.style(s.rawNode,"direction");357 if(g.isVml || g.isSvg || g.isCanvas){358 s.textDir = tDir ? tDir : html.style(s.rawNode,"direction");359 }360 if(g.isSilverlight){361 // allow this once rawNode will be able for the silverlight362 //s.textDir = tDir ? tDir : dojo.style(s.rawNode,"direction");363 s.textDir = tDir ? tDir : html.style(s._nodes[1],"direction");364 }365 366 return s;367 };368 /*===== g = origG; =====*/369 // some helper functions370 371 function setTextDir(/*Object*/ obj, /*String*/ newTextDir){372 var tDir = validateTextDir(newTextDir);373 if (tDir){374 g.utils.forEach(obj,function(e){375 if(e instanceof g.Surface || e instanceof g.Group){376 e.textDir = tDir;377 } 378 if(e instanceof g.Text){379 e.setShape({textDir: tDir});380 }381 if(e instanceof g.TextPath){382 e.setText({textDir: tDir})383 }384 }, obj);385 }386 return obj;387 }388 function validateTextDir(textDir){389 var validValues = ["ltr","rtl","auto"]; 390 if (textDir){391 textDir = textDir.toLowerCase();392 if (arr.indexOf(validValues, textDir) < 0){393 return null;394 }395 }396 return textDir;397 }398 return g; // return gfx api augmented with bidi support ...

Full Screen

Full Screen

dir.js

Source:dir.js Github

copy

Full Screen

...194 enumerable: false,195 writable: true,196 configurable: true,197});198function opendir(path, options, callback) {199 callback = typeof options === 'function' ? options : callback;200 validateCallback(callback);201 path = getValidatedPath(path);202 options = getOptions(options, {203 encoding: 'utf8'204 });205 function opendirCallback(error, handle) {206 if (error) {207 callback(error);208 } else {209 callback(null, new Dir(handle, path, options));210 }211 }212 const req = new FSReqCallback();213 req.oncomplete = opendirCallback;214 dirBinding.opendir(215 pathModule.toNamespacedPath(path),216 options.encoding,217 req218 );219}220function opendirSync(path, options) {221 path = getValidatedPath(path);222 options = getOptions(options, {223 encoding: 'utf8'224 });225 const ctx = { path };226 const handle = dirBinding.opendir(227 pathModule.toNamespacedPath(path),228 options.encoding,229 undefined,230 ctx231 );232 handleErrorFromBinding(ctx);233 return new Dir(handle, path, options);234}235module.exports = {236 Dir,237 opendir,238 opendirSync...

Full Screen

Full Screen

variables.js

Source:variables.js Github

copy

Full Screen

1const gulp = require('gulp')2const browserSync = require('browser-sync').create() // Локальный сервер3const babel = require('gulp-babel')4const del = require('del')5const less = require('gulp-less') // Препроцессор Less6const concat = require('gulp-concat') // Соединение в один файл7const postcss = require('gulp-postcss')8const argv = require('yargs').argv9const gulpIf = require('gulp-if')10const autoprefixer = require('autoprefixer') // Для прописывания префиксов11// const precss = require('precss')12const rename = require('gulp-rename')13const cssnano = require('cssnano') // Для отимизации и минификации выходных стилей14const fileinclude = require("gulp-file-include")15const minify = require('gulp-minify')16const sourcemaps = require('gulp-sourcemaps')17const dirSrc = './src'18const dirDist = './dist'19const dirLess = '/less'20const dirCss = '/css'21const dirFonts = '/fonts'22const dirAssets = '/assets'23const dirImg = '/img'24const dirJs = `/js`25const dirLib = `/lib`26const dirPages = `/pages`27const dirViews = `/views`28const dirTemplates = `/template`29const dirIncludes = `/includes`30const dirFavIcon = `/favicon`31const dirs = {32 dist: {33 index: `${dirDist}`,34 html: `${dirDist}`,35 css: `${dirDist}${dirAssets}${dirCss}`,36 js: `${dirDist}${dirAssets}${dirJs}`,37 jslib: `${dirDist}${dirAssets}${dirJs}${dirLib}`,38 img: `${dirDist}${dirAssets}${dirImg}`,39 favicon: `${dirDist}${dirAssets}${dirFavIcon}`,40 fonts: `${dirDist}${dirAssets}${dirFonts}`41 },42 srcPathFull: {43 fonts: `${dirSrc}${dirAssets}${dirFonts}/`,44 less: `${dirSrc}${dirAssets}${dirLess}/`,45 img: `${dirSrc}${dirAssets}${dirImg}/`,46 favicon: `${dirSrc}${dirAssets}${dirFavIcon}/`,47 },48 src: {49 index: `${dirSrc}/*.html`,50 html: [51 `${dirSrc}/**/*.html`,52 `!${dirSrc}/**/_*.html`53 ],54 less: `${dirSrc}${dirAssets}${dirLess}/style.less`,55 fonts: `${dirSrc}${dirAssets}${dirFonts}/**`,56 img: `${dirSrc}${dirAssets}${dirImg}/**`,57 favicon: `${dirSrc}${dirAssets}${dirFavIcon}/**`,58 js: [59 `${dirSrc}${dirAssets}${dirJs}/*.js`,60 ],61 vendorStyle: `${dirSrc}${dirAssets}${dirCss}/**/*.css`,62 vendorJs: [63 `${dirSrc}${dirAssets}${dirJs}${dirLib}/**/*.js`64 ]65 },66 watch: {67 index: `${dirSrc}/*.html`,68 html: `${dirSrc}/**/*.html`,69 template: `${dirSrc}${dirTemplates}/**/*.html`,70 less: `${dirSrc}${dirAssets}${dirLess}/**/*.less`,71 cssVendor: `${dirSrc}${dirAssets}${dirCss}/**/*.css`,72 img: `${dirSrc}${dirAssets}${dirImg}/**`,73 js: `${dirSrc}${dirAssets}${dirJs}/**/*.js`,74 jslib: `${dirSrc}${dirAssets}${dirJs}${dirLib}/**/*.js`,75 favicon: `${dirDist}${dirAssets}${dirFavIcon}/**`,76 }77}78module.exports = {79 // Variables path80 dirSrc,81 dirDist,82 dirLess,83 dirCss,84 dirFonts,85 dirImg,86 dirAssets,87 dirJs,88 dirViews,89 dirTemplates,90 dirPages,91 dirIncludes,92 dirFavIcon,93 dirs,94 // Plugins95 gulp,96 del,97 browserSync,98 autoprefixer,99 postcss,100 babel,101 gulpIf,102 minify,103 argv,104 less,105 concat,106 // pug,107 fileinclude,108 rename,109 cssnano,110 sourcemaps,...

Full Screen

Full Screen

direction.js

Source:direction.js Github

copy

Full Screen

1//////////////////////////////////////////////////////////////////////////////////////2// Directions3// (variables and utility functions for representing actor heading direction)4// direction enums (in counter-clockwise order)5// NOTE: changing the order of these enums may effect the enums.6// I've tried abstracting away the uses by creating functions to rotate them.7// NOTE: This order determines tie-breakers in the shortest distance turn logic.8// (i.e. higher priority turns have lower enum values)9var DIR_UP = 0;10var DIR_LEFT = 1;11var DIR_DOWN = 2;12var DIR_RIGHT = 3;13var getClockwiseAngleFromTop = function(dirEnum) {14 return -dirEnum*Math.PI/2;15};16var rotateLeft = function(dirEnum) {17 return (dirEnum+1)%4;18};19var rotateRight = function(dirEnum) {20 return (dirEnum+3)%4;21};22var rotateAboutFace = function(dirEnum) {23 return (dirEnum+2)%4;24};25// get direction enum from a direction vector26var getEnumFromDir = function(dir) {27 if (dir.x==-1) return DIR_LEFT;28 if (dir.x==1) return DIR_RIGHT;29 if (dir.y==-1) return DIR_UP;30 if (dir.y==1) return DIR_DOWN;31};32// set direction vector from a direction enum33var setDirFromEnum = function(dir,dirEnum) {34 if (dirEnum == DIR_UP) { dir.x = 0; dir.y =-1; }35 else if (dirEnum == DIR_RIGHT) { dir.x =1; dir.y = 0; }36 else if (dirEnum == DIR_DOWN) { dir.x = 0; dir.y = 1; }37 else if (dirEnum == DIR_LEFT) { dir.x = -1; dir.y = 0; }38};39// return the direction of the open, surrounding tile closest to our target40var getTurnClosestToTarget = function(tile,targetTile,openTiles) {41 var dx,dy,dist; // variables used for euclidean distance42 var minDist = Infinity; // variable used for finding minimum distance path43 var dir = {};44 var dirEnum = 0;45 var i;46 for (i=0; i<4; i++) {47 if (openTiles[i]) {48 setDirFromEnum(dir,i);49 dx = dir.x + tile.x - targetTile.x;50 dy = dir.y + tile.y - targetTile.y;51 dist = dx*dx+dy*dy;52 if (dist < minDist) {53 minDist = dist;54 dirEnum = i;55 }56 }57 }58 return dirEnum;59};60// retrieve four surrounding tiles and indicate whether they are open61var getOpenTiles = function(tile,dirEnum) {62 // get open passages63 var openTiles = {};64 openTiles[DIR_UP] = map.isFloorTile(tile.x, tile.y-1);65 openTiles[DIR_RIGHT] = map.isFloorTile(tile.x+1, tile.y);66 openTiles[DIR_DOWN] = map.isFloorTile(tile.x, tile.y+1);67 openTiles[DIR_LEFT] = map.isFloorTile(tile.x-1, tile.y);68 var numOpenTiles = 0;69 var i;70 if (dirEnum != undefined) {71 // count number of open tiles72 for (i=0; i<4; i++)73 if (openTiles[i])74 numOpenTiles++;75 // By design, no mazes should have dead ends,76 // but allow player to turn around if and only if it's necessary.77 // Only close the passage behind the player if there are other openings.78 var oppDirEnum = rotateAboutFace(dirEnum); // current opposite direction enum79 if (numOpenTiles > 1)80 openTiles[oppDirEnum] = false;81 }82 return openTiles;83};84// returns if the given tile coordinate plus the given direction vector has a walkable floor tile85var isNextTileFloor = function(tile,dir) {86 return map.isFloorTile(tile.x+dir.x,tile.y+dir.y);...

Full Screen

Full Screen

file.js

Source:file.js Github

copy

Full Screen

1/**2 * fs模块,文件操作3 */4const fs = require("fs");5let firstRun = true; // getDirTree首次执行6/**7 * 主体函数,获取目录下的文件树8 * @param {读取的路径} dir9 * @returns 返回 dir目录下的文件树10 */11function getDirTree(dir) {12 let obj = {13 dir: dir,14 childFiles: [],15 childDir: {},16 };17 let objStr = JSON.stringify(obj);18 if (firstRun && isFile(dir)) {19 return console.log(`${dir}: 不是文件夹`.redBG);20 }21 let files = readDir(dir);22 firstRun = false;23 // 遍历文件24 files.forEach((file) => {25 let tempDir = `${dir}\\${file}`;26 let dirname = getDirName(tempDir);27 let fullDir = `${dir}/${file}`;28 if (isFile(`${dir}/${file}`)) {29 obj.childFiles.push({30 short: file, // 文件名31 full: fullDir, // 完整路径32 });33 } else {34 // 在当前文件夹的对象下 childDir 属性(1),以文件夹名作为key(2),35 // (2)的值是该目录下 路径dir、childFiles子文件、childDir子文件夹组成的对象或null36 obj.childDir[dirname] = getDirTree(`${dir}/${file}`);37 }38 });39 return JSON.stringify(obj) === objStr ? null : obj;40}41/**42 * 读取路径下的文件、文件夹43 * @param {读取的路径} dir44 * @returns 返回 dir目录下的文件45 */46function readDir(dir) {47 return fs.readdirSync(dir, (err, files) => {48 if (err) throw err;49 if (firstRun && !files.length) console.log(`${dir}: 文件夹为空`.redBG);50 return files;51 });52}53/**54 * 判断制定路径是否是文件55 * @param {读取的路径} dir56 * @returns boolean57 */58function isFile(dir) {59 return fs.statSync(dir).isFile();60}61/**62 * 获取目录名63 * @param {读取的路径} dir64 * @returns 目录名65 */66function getDirName(dir) {67 return dir.substr(dir.lastIndexOf("\\") + 1, dir.length);68}69module.exports = {70 getDirTree,71 readDir,72 isFile,73 getDirName,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var imposter = {4 {5 {6 is: {7 }8 }9 }10};11mb.create(imposter, function (error, imposter) {12 console.log('Imposter created, now POSTing to it');13 fs.readFile('test.txt', function (err, data) {14 if (err) throw err;15 console.log(data.toString());16 });17 mb.post(imposter.port, { path: '/', body: 'test' }, function (error, response) {18 console.log('POSTed to imposter, now stopping');19 mb.stop(imposter.port, function () {20 console.log('Stopped');21 });22 });23});24var mb = require('mountebank');25var fs = require('fs');26var imposter = {27 {28 {29 is: {30 }31 }32 }33};34mb.create(imposter, function (error, imposter) {35 console.log('Imposter created, now POSTing to it');36 mb.dir(__dirname, function (err, data) {37 if (err) throw err;38 console.log(data.toString());39 });40 mb.post(imposter.port, { path: '/', body: 'test' }, function (error, response) {41 console.log('POSTed to imposter, now stopping');42 mb.stop(imposter.port, function () {43 console.log('Stopped');44 });45 });46});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*']}, function (error) {3 if (error) {4 console.error('Error creating mountebank', error);5 } else {6 console.log('Mountebank started');7 }8});9var mb = require('mountebank');10mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*']}, function (error) {11 if (error) {12 console.error('Error creating mountebank', error);13 } else {14 console.log('Mountebank started');15 }16});17var mb = require('mountebank');18mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*']}, function (error) {19 if (error) {20 console.error('Error creating mountebank', error);21 } else {22 console.log('Mountebank started');23 }24});25var mb = require('mountebank');26mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*']}, function (error) {27 if (error) {28 console.error('Error creating mountebank', error);29 } else {30 console.log('Mountebank started');31 }32});33Error creating mountebank { Error: listen EADDRINUSE :::252534 at Server.setupListenHandle [as _listen2] (net.js:1347:14)35 at listenInCluster (net.js:1396:12)36 at GetAddrInfoReqWrap.doListen [as callback] (net.js:1512:7)37 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2mb.start({3}, function () {4 console.log('mountebank started');5 const imposter = {6 {7 {8 equals: {9 }10 }11 {12 is: {13 headers: {14 },15 }16 }17 }18 };19 mb.post('/imposters', imposter, function (error, response) {20 console.log('POST /imposters', response.statusCode);21 mb.del('/imposters/' + response.body.port, function (error, response) {22 console.log('DELETE /imposters/' + response.body.port, response.statusCode);23 mb.stop(function () {24 console.log('mountebank stopped');25 });26 });27 });28});29const mb = require('mountebank');30mb.start({31}, function () {32 console.log('mountebank started');33 const imposter = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var Q = require('q');3var fs = require('fs');4var path = require('path');5var imposter = {6 {7 {8 is: {9 }10 }11 }12};13var options = {14};15mb.create(options)16 .then(function (mbServer) {17 return mbServer.post('/imposters', imposter)18 .then(function (response) {19 console.log(response.body);20 var imposters = JSON.parse(response.body);21 console.log(imposters[0].port);22 return mbServer.get('/imposters/' + imposters[0].port + '/requests');23 })24 .then(function (response) {25 console.log(response.body);26 return mbServer.del('/imposters/' + imposters[0].port);27 })28 .then(function (response) {29 console.log(response.body);30 return mbServer.stop();31 });32 })33 .done();34var mb = require('mountebank');35var Q = require('q');36var fs = require('fs');37var path = require('path');38var imposter = {39 {40 {41 is: {42 }43 }44 }45};46var options = {47};48mb.create(options)49 .then(function (mbServer) {50 return mbServer.post('/imposters', imposter)51 .then(function (response) {52 console.log(response.body);53 var imposters = JSON.parse(response.body);54 console.log(imposters[0].port);55 return mbServer.get('/imposters/' + imposters[0].port + '/requests');56 })57 .then(function (response) {58 console.log(response.body);59 return mbServer.del('/imposters/' + imposters[0].port);60 })61 .then(function (response)

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var imposter = {4 stubs: [{5 responses: [{6 is: {7 }8 }]9 }]10};11mb.create(port, imposter).then(function (response) {12 console.log('imposter created');13 return mb.get('/imposters', mbUrl);14}).then(function (response) {15 console.log('imposters retrieved');16 console.log(response.body);17}).catch(function (error) {18 console.error(error);19});20var mb = require('mountebank');21var port = 2525;22var imposter = {23 stubs: [{24 responses: [{25 is: {26 }27 }]28 }]29};30mb.create(port, imposter).then(function (response) {31 console.log('imposter created');32 return mb.get('/imposters', mbUrl);33}).then(function (response) {34 console.log('imposters retrieved');35 console.log(response.body);36}).catch(function (error) {37 console.error(error);38});39var mb = require('mountebank');40var port = 2525;41var imposter = {42 stubs: [{43 responses: [{44 is: {45 }46 }]47 }]48};49mb.create(port, imposter).then(function (response) {50 console.log('imposter created');51 return mb.get('/imposters', mbUrl);52}).then(function (response) {53 console.log('imposters retrieved');54 console.log(response.body);55}).catch(function (error) {56 console.error(error);57});58var mb = require('mountebank');

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var http = require('http');5var url = require('url');6var port = 2525;7var host = 'localhost';8var imposter = {9 {10 {11 is: {12 headers: {13 },14 body: JSON.stringify({message: 'Hello World!'})15 }16 }17 }18};19var options = {20 headers: {21 }22};23var server = http.createServer(function (request, response) {24 response.writeHead(200, {"Content-Type": "text/plain"});25 response.end("Hello World\n");26});

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const fs = require('fs');3const path = require('path');4const dir = path.join(__dirname, 'imposters');5const port = 2525;6mb.start({ port: port, pidfile: 'mb.pid', logfile: 'mb.log', dir: dir }, function (error) {7 if (error) {8 console.log(error);9 } else {10 console.log('mountebank started');11 }12});13const imposter = {14 {15 {16 is: {17 headers: {18 },19 body: {20 }21 }22 }23 }24};25const options = {26};27mb.post(options, function (error, response) {28 if (error) {29 console.log(error);30 } else {31 console.log(response.body);32 }33});34const imposter = {35 {36 {37 is: {38 headers: {39 },40 body: {41 }42 }43 }44 }45};46const options = {47};48mb.del(options, function (error, response) {49 if (error) {50 console.log(error);51 } else {52 console.log(response.body);53 }54});55const options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var Q = require('q');5var config = require('config');6var logger = require('winston');7var imposterPort = config.get('imposter.port');8var imposterProtocol = config.get('imposter.protocol');9var imposterName = config.get('imposter.name');10var imposterStubPath = config.get('imposter.stubPath');11var imposterStubFile = config.get('imposter.stubFile');12var imposterStubPath = path.join(imposterStubPath, imposterStubFile);13var imposterStub = require(imposterStubPath);14var imposter = {15};16var imposterOptions = {17};18var imposterConfig = {19};20var imposterConfigString = JSON.stringify(imposterConfig);21var deferred = Q.defer();22mb.create({ port: 2525 }, function (error, mbServer) {23 if (error) {24 deferred.reject(error);25 } else {26 logger.info('Mountebank server created successfully');27 mbServer.post('/imposters', imposterConfigString, function (error, response) {28 if (error) {29 deferred.reject(error);30 } else {31 logger.info('Imposter created successfully');32 deferred.resolve(response);33 }34 });35 }36});37deferred.promise.then(function (response) {38 logger.info('Imposter response is: ', response);39 var imposterId = response.body.id;40 var imposterPath = '/imposters/' + imposterId;41 mbServer.get(imposterPath, function (error, response) {42 if (error) {43 deferred.reject(error);44 } else {45 logger.info('Imposter response is: ', response);46 deferred.resolve(response);47 }48 });49}, function (error) {50 logger.error('Error is: ', error);51});52deferred.promise.then(function (response) {53 logger.info('Imposter response is: ', response);54 var imposterId = response.body.id;55 var imposterPath = '/imposters/' + imposterId;

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 mountebank 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