Best JavaScript code snippet using ava
gulpfile.js
Source:gulpfile.js
...63 // The css and js paths are URLs, like '/misc/jquery.js'.64 // The following paths are relative to the generated style guide.65 css: [66 // base/special stylesheets67 path.relative(options.rootPath.styleGuide, options.theme.css + 'base.css'),68 path.relative(options.rootPath.styleGuide, options.theme.css + 'layouts.css'),69 path.relative(options.rootPath.styleGuide, options.theme.css + 'chroma-kss-styles.css'),70 path.relative(options.rootPath.styleGuide, options.theme.css + 'kss-only.css'),71 // component stylesheets72 path.relative(options.rootPath.styleGuide, options.theme.css + 'box.css'),73 path.relative(options.rootPath.styleGuide, options.theme.css + 'clearfix.css'),74 path.relative(options.rootPath.styleGuide, options.theme.css + 'comment.css'),75 path.relative(options.rootPath.styleGuide, options.theme.css + 'footer.css'),76 path.relative(options.rootPath.styleGuide, options.theme.css + 'header.css'),77 path.relative(options.rootPath.styleGuide, options.theme.css + 'hidden.css'),78 path.relative(options.rootPath.styleGuide, options.theme.css + 'highlight-mark.css'),79 path.relative(options.rootPath.styleGuide, options.theme.css + 'inline-links.css'),80 path.relative(options.rootPath.styleGuide, options.theme.css + 'inline-sibling.css'),81 path.relative(options.rootPath.styleGuide, options.theme.css + 'messages.css'),82 path.relative(options.rootPath.styleGuide, options.theme.css + 'print-none.css'),83 path.relative(options.rootPath.styleGuide, options.theme.css + 'responsive-video.css'),84 path.relative(options.rootPath.styleGuide, options.theme.css + 'visually-hidden.css'),85 path.relative(options.rootPath.styleGuide, options.theme.css + 'watermark.css'),86 path.relative(options.rootPath.styleGuide, options.theme.css + 'wireframe.css'),87 // form stylesheets88 path.relative(options.rootPath.styleGuide, options.theme.css + 'autocomplete.css'),89 path.relative(options.rootPath.styleGuide, options.theme.css + 'collapsible-fieldset.css'),90 path.relative(options.rootPath.styleGuide, options.theme.css + 'form-item.css'),91 path.relative(options.rootPath.styleGuide, options.theme.css + 'form-table.css'),92 path.relative(options.rootPath.styleGuide, options.theme.css + 'progress-bar.css'),93 path.relative(options.rootPath.styleGuide, options.theme.css + 'progress-throbber.css'),94 path.relative(options.rootPath.styleGuide, options.theme.css + 'resizable-textarea.css'),95 path.relative(options.rootPath.styleGuide, options.theme.css + 'table-drag.css'),96 // navigation stylesheets97 path.relative(options.rootPath.styleGuide, options.theme.css + 'breadcrumb.css'),98 path.relative(options.rootPath.styleGuide, options.theme.css + 'more-link.css'),99 path.relative(options.rootPath.styleGuide, options.theme.css + 'nav-menu.css'),100 path.relative(options.rootPath.styleGuide, options.theme.css + 'navbar.css'),101 path.relative(options.rootPath.styleGuide, options.theme.css + 'pager.css'),102 path.relative(options.rootPath.styleGuide, options.theme.css + 'skip-link.css'),103 path.relative(options.rootPath.styleGuide, options.theme.css + 'tabs.css')104 ],105 js: [106 ],107 homepage: 'homepage.md',108 title: 'STARTERKIT Style Guide'109};110// Define the paths to the JS files to lint.111options.eslint = {112 files : [113 options.rootPath.project + 'gulpfile.js',114 options.theme.js + '**/*.js',115 '!' + options.theme.js + '**/*.min.js',116 options.theme.components + '**/*.js',117 '!' + options.theme.build + '**/*.js'...
zip_resource_fetcher.js
Source:zip_resource_fetcher.js
1// Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.2//3// Redistribution and use in source and binary forms, with or without modification,4// are permitted provided that the following conditions are met:5// 1. Redistributions of source code must retain the above copyright notice, this6// list of conditions and the following disclaimer.7// 2. Redistributions in binary form must reproduce the above copyright notice,8// this list of conditions and the following disclaimer in the documentation and/or9// other materials provided with the distribution.10// 3. Neither the name of the organization nor the names of its contributors may be11// used to endorse or promote products derived from this software without specific12// prior written permission.13define(['jquery', 'URIjs', './discover_content_type', 'zip-ext', 'readium_shared_js/helpers'], function ($, URI, ContentTypeDiscovery, zip, Helpers) {14 var ZipResourceFetcher = function(parentFetcher, libDir) {15 var ebookURL = parentFetcher.getEbookURL();16 var ebookURL_filepath = parentFetcher.getEbookURL_FilePath();17 18 var _checkCrc32 = false;19 var _zipFs;20 var READIUM_ERROR_PREFIX = "READIUM -- ";21 // INTERNAL FUNCTIONS22 // Description: perform a function with an initialized zip filesystem, making sure that such filesystem is initialized.23 // Note that due to a race condition, more than one zip filesystem may be instantiated.24 // However, the last one to be set on the model object will prevail and others would be garbage collected later.25 function withZipFsPerform(callback, onerror) {26 // if (!(ebookURL instanceof Blob)) 27 // {onerror("SIMULATING ZIP LIB ERROR...");28 // return;}29 30 if (_zipFs) {31 callback(_zipFs, onerror);32 } else {33 if (libDir) {34 35 // The Web Worker requires standalone z-worker/inflate/deflate.js files in libDir (i.e. cannot be aggregated/minified/optimised in the final generated single-file build)36 zip.useWebWorkers = true; // (true by default)37 zip.workerScriptsPath = libDir;38 } else {39 40 zip.useWebWorkers = false; // (true by default)41 }42 _zipFs = new zip.fs.FS();43 if (ebookURL instanceof Blob || ebookURL instanceof File) {44 _zipFs.importBlob(45 ebookURL,46 function () { 47 callback(_zipFs, onerror); 48 },49 function () {50 console.error("ZIP ERROR");51 onerror.apply(this, arguments);52 }53 ); 54 } else {55 56 _zipFs.importHttpContent(57 ebookURL,58 true,59 function () {60 callback(_zipFs, onerror);61 },62 function () {63 console.error("ZIP ERROR");64 onerror.apply(this, arguments);65 }66 );67 }68 }69 }70 function fetchFileContents (relativePathRelativeToPackageRoot, readCallback, onerror) {71 if (typeof relativePathRelativeToPackageRoot === 'undefined') {72 throw 'Fetched file relative path is undefined!';73 }74 withZipFsPerform(75 function (zipFs, onerror) {76 77 var entry = zipFs.find(relativePathRelativeToPackageRoot);78 if (typeof entry === 'undefined' || entry === null) {79 onerror(new Error(READIUM_ERROR_PREFIX + 'Entry ' + relativePathRelativeToPackageRoot + ' not found in zip ' + ebookURL_filepath));80 } else {81 if (entry.directory) {82 onerror(new Error(READIUM_ERROR_PREFIX + 'Entry ' + relativePathRelativeToPackageRoot + ' is a directory while a file has been expected'));83 } else {84 readCallback(entry);85 }86 }87 },88 function() {89 90 var error = arguments ?91 (92 (arguments.length && (arguments[0] instanceof Error)) ?93 arguments[0]94 : ((arguments instanceof Error) ? arguments : undefined)95 )96 : undefined;97 98 // console.log(error);99 // if (!error) console.log(arguments);100 101 var isReadiumError = error ? (error.message.indexOf(READIUM_ERROR_PREFIX) == 0) : false;102 103 // we fallback to Blobl for all other types of errors (not just those emanating from the zip lib, but also from the readCallback())104 if (!isReadiumError && !(ebookURL instanceof Blob) && !(ebookURL instanceof File)) {105 console.log("Zip lib failed to load zipped EPUB via HTTP, trying alternative HTTP fetch... (" + ebookURL + ")");106 107 var xhr = new XMLHttpRequest();108 109 //xhr.addEventListener('load', function(){});110 111 xhr.onreadystatechange = function(){112 113 //console.log("XMLHttpRequest readyState: " + this.readyState);114 if (this.readyState != 4) return;115 116 var success = xhr.status >= 200 && xhr.status < 300 || xhr.status === 304;117 if (success) {118 ebookURL = this.response;119 //ebookURL_filepath = Helpers.getEbookUrlFilePath(ebookURL);120 //console.log(ebookURL_filepath);121 122 _zipFs = undefined;123 if (ebookURL instanceof Blob || ebookURL instanceof File) {124 fetchFileContents(relativePathRelativeToPackageRoot, readCallback, onerror);125 }126 else {127 onerror(new Error("XMLHttpRequest response not Blob!?"));128 }129 130 return;131 }132 133 onerror(xhr.statusText);134 };135 xhr.open('GET', ebookURL, true);136 xhr.responseType = 'blob';137 xhr.send(null); 138 // $.get(ebookURL, function(data) {139 // console.log(typeof data);140 // ebookURL_filepath = Helpers.getEbookUrlFilePath(ebookURL);141 // //fetchFileContents(relativePathRelativeToPackageRoot, readCallback, onerror);142 // }).fail(function(err) {143 // console.log(err);144 // onerror.apply(this, arguments);145 // });146 147 } else {148 onerror.apply(this, arguments);149 }150 }151 );152 }153 // PUBLIC API154 this.resolveURI = function (pathRelativeToPackageRoot) {155 156 var pathRelativeToPackageRootUri = undefined;157 try {158 pathRelativeToPackageRootUri = new URI(pathRelativeToPackageRoot);159 } catch(err) {160 console.error(err);161 console.log(pathRelativeToPackageRoot);162 }163 if (pathRelativeToPackageRootUri && pathRelativeToPackageRootUri.is("absolute")) return pathRelativeToPackageRoot; //pathRelativeToPackageRootUri.scheme() == "http://", "https://", "data:", etc.164 var url = ebookURL_filepath;165 166 try {167 //url = new URI(relativeUrl).absoluteTo(url).search('').hash('').toString();168 url = new URI(url).search('').hash('').toString();169 } catch(err) {170 console.error(err);171 console.log(url);172 }173 174 return url + (url.charAt(url.length-1) == '/' ? "" : "/") + pathRelativeToPackageRoot;175 };176 this.fetchFileContentsText = function(relativePathRelativeToPackageRoot, fetchCallback, onerror) {177 fetchFileContents(relativePathRelativeToPackageRoot, function (entry) {178 entry.getText(fetchCallback, undefined, _checkCrc32);179 }, onerror)180 };181 this.fetchFileContentsData64Uri = function(relativePathRelativeToPackageRoot, fetchCallback, onerror) {182 fetchFileContents(relativePathRelativeToPackageRoot, function (entry) {183 entry.getData64URI(ContentTypeDiscovery.identifyContentTypeFromFileName(relativePathRelativeToPackageRoot),184 fetchCallback, undefined, _checkCrc32);185 }, onerror)186 };187 this.fetchFileContentsBlob = function(relativePathRelativeToPackageRoot, fetchCallback, onerror) {188 var decryptionFunction = parentFetcher.getDecryptionFunctionForRelativePath(relativePathRelativeToPackageRoot);189 if (decryptionFunction) {190 var origFetchCallback = fetchCallback;191 fetchCallback = function (unencryptedBlob) {192 decryptionFunction(unencryptedBlob, function (decryptedBlob) {193 origFetchCallback(decryptedBlob);194 });195 };196 }197 fetchFileContents(relativePathRelativeToPackageRoot, function (entry) {198 entry.getBlob(ContentTypeDiscovery.identifyContentTypeFromFileName(relativePathRelativeToPackageRoot), fetchCallback,199 undefined, _checkCrc32);200 }, onerror)201 };202 };203 return ZipResourceFetcher;...
plain_resource_fetcher.js
Source:plain_resource_fetcher.js
1// Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.2// 3// Redistribution and use in source and binary forms, with or without modification, 4// are permitted provided that the following conditions are met:5// 1. Redistributions of source code must retain the above copyright notice, this 6// list of conditions and the following disclaimer.7// 2. Redistributions in binary form must reproduce the above copyright notice, 8// this list of conditions and the following disclaimer in the documentation and/or 9// other materials provided with the distribution.10// 3. Neither the name of the organization nor the names of its contributors may be 11// used to endorse or promote products derived from this software without specific 12// prior written permission.13define(['jquery', 'URIjs', './discover_content_type'], function ($, URI, ContentTypeDiscovery) {14 var PlainResourceFetcher = function(parentFetcher){15 var ebookURL = parentFetcher.getEbookURL();16 var ebookURL_filepath = parentFetcher.getEbookURL_FilePath();17 var self = this;18 // INTERNAL FUNCTIONS19 function fetchFileContents(pathRelativeToPackageRoot, readCallback, onerror) {20 var fileUrl = self.resolveURI(pathRelativeToPackageRoot);21 if (typeof pathRelativeToPackageRoot === 'undefined') {22 throw 'Fetched file relative path is undefined!';23 }24 var xhr = new XMLHttpRequest();25 xhr.open('GET', fileUrl, true);26 xhr.responseType = 'arraybuffer';27 xhr.onerror = onerror;28 xhr.onload = function (loadEvent) {29 readCallback(xhr.response);30 };31 xhr.send();32 }33 // PUBLIC API34 this.resolveURI = function (pathRelativeToPackageRoot) {35 36 var pathRelativeToPackageRootUri = undefined;37 try {38 pathRelativeToPackageRootUri = new URI(pathRelativeToPackageRoot);39 } catch(err) {40 console.error(err);41 console.log(pathRelativeToPackageRoot);42 }43 if (pathRelativeToPackageRootUri && pathRelativeToPackageRootUri.is("absolute")) return pathRelativeToPackageRoot; //pathRelativeToPackageRootUri.scheme() == "http://", "https://", "data:", etc.44 var url = ebookURL_filepath;45 46 try {47 //url = new URI(relativeUrl).absoluteTo(url).search('').hash('').toString();48 url = new URI(url).search('').hash('').toString();49 } catch(err) {50 console.error(err);51 console.log(url);52 }53 54 return url + (url.charAt(url.length-1) == '/' ? "" : "/") + pathRelativeToPackageRoot;55 };56 this.fetchFileContentsText = function(pathRelativeToPackageRoot, fetchCallback, onerror) {57 var fileUrl = self.resolveURI(pathRelativeToPackageRoot);58 if (typeof fileUrl === 'undefined') {59 throw 'Fetched file URL is undefined!';60 }61 $.ajax({62 // encoding: "UTF-8",63 // mimeType: "text/plain; charset=UTF-8",64 // beforeSend: function( xhr ) {65 // xhr.overrideMimeType("text/plain; charset=UTF-8");66 // },67 isLocal: fileUrl.indexOf("http") === 0 ? false : true,68 url: fileUrl,69 dataType: 'text', //https://api.jquery.com/jQuery.ajax/70 async: true,71 success: function (result) {72 fetchCallback(result);73 },74 error: function (xhr, status, errorThrown) {75 onerror(new Error(errorThrown));76 }77 });78 };79 this.fetchFileContentsBlob = function(pathRelativeToPackageRoot, fetchCallback, onerror) {80 var decryptionFunction = parentFetcher.getDecryptionFunctionForRelativePath(pathRelativeToPackageRoot);81 if (decryptionFunction) {82 var origFetchCallback = fetchCallback;83 fetchCallback = function (unencryptedBlob) {84 decryptionFunction(unencryptedBlob, function (decryptedBlob) {85 origFetchCallback(decryptedBlob);86 });87 };88 }89 fetchFileContents(pathRelativeToPackageRoot, function (contentsArrayBuffer) {90 var blob = new Blob([contentsArrayBuffer], {91 type: ContentTypeDiscovery.identifyContentTypeFromFileName(pathRelativeToPackageRoot)92 });93 fetchCallback(blob);94 }, onerror);95 };96 };97 return PlainResourceFetcher;...
Using AI Code Generation
1var path = require('path');2var pathObj = path.parse(__filename);3console.log(pathObj);4var os = require('os');5var totalMemory = os.totalmem();6var freeMemory = os.freemem();7console.log('Total Memory: ' + totalMemory);8console.log(`Total Memory: ${totalMemory}`);9console.log(`Free Memory: ${freeMemory}`);10const fs = require('fs');11const files = fs.readdirSync('./');12console.log(files);13fs.readdir('./', function(err, files) {14 if (err) console.log('Error', err);15 else console.log('Result', files);16});17const EventEmitter = require('events');18const Logger = require('./logger');19const logger = new Logger();20logger.on('messageLogged', (arg) => {21 console.log('Listener called', arg);22});23logger.log('message');24const http = require('http');25const server = http.createServer((req, res) => {26 if (req.url === '/') {27 res.write('Hello World');28 res.end();29 }30 if (req.url === '/api/courses') {31 res.write(JSON.stringify([1, 2, 3]));32 res.end();33 }34});35server.listen(3000);36console.log('Listening on port 3000...');
Using AI Code Generation
1const path = require('path');2const testFolder = './';3const fs = require('fs');4fs.readdir(testFolder, (err, files) => {5 files.forEach(file => {6 console.log(path.relative(testFolder, file));7 });8});
Using AI Code Generation
1var path = require('path');2var fs = require('fs');3const dirName = process.argv[2];4const extName = '.' + process.argv[3];5fs.readdir(dirName, function(err, list) {6 if (err) return console.error(err);7 list.forEach(function(file) {8 if (path.extname(file) === extName) {9 console.log(file);10 }11 });12});
Using AI Code Generation
1var path = require('path');2var pathObj = path.parse(__filename);3console.log(pathObj);4console.log(pathObj.root);5console.log(pathObj.base);6console.log(pathObj.ext);7console.log(pathObj.name);8console.log(pathObj.dir);9console.log(pathObj.base);10var os = require('os');11var totalMemory = os.totalmem();12var freeMemory = os.freemem();13console.log('Total Memory: ' + totalMemory);14console.log(`Total Memory: ${totalMemory}`);15console.log(`Free Memory: ${freeMemory}`);16const fs = require('fs');17fs.readdir('./', function(err, files) {18 if (err) console.log('Error', err);19 else console.log('Result', files);20});21const EventEmitter = require('events');22const Logger = require('./logger');23const logger = new Logger();24logger.on('messageLogged', (arg) => {25 console.log('Listener called', arg);26});27logger.log('message');28const http = require('http');29const server = http.createServer((req, res) => {30 if (req.url === '/') {31 res.write('Hello World');32 res.end();33 }34 if (req.url === '/api/courses') {35 res.write(JSON.stringify([1, 2, 3]));36 res.end();37 }38});39server.listen(3000);40console.log('Listening on port 3000...');
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!!