Best JavaScript code snippet using best
index.json.js
Source:index.json.js
1import * as fs from 'fs';2import send from '@polka/send';3import { extract_frontmatter } from '@sveltejs/site-kit/utils/markdown';4let json;5function get_tutorials() {6 const slugs = new Set();7 const tutorials = {};8 fs.readdirSync(`content/projects`)9 .filter((dir) => /^\d+/.test(dir))10 .forEach((dir) => {11 let meta;12 let tutorialSlugs = new Set();13 try {14 meta = JSON.parse(15 fs.readFileSync(`content/projects/${dir}/meta.json`, 'utf-8')16 );17 } catch (err) {18 throw new Error(`Error reading metadata for ${dir}`);19 }20 tutorials[dir.replace(/^\d+-/, '')] = {21 tutorial: {22 title: meta.title,23 img: meta.img,24 description: meta.description,25 dir: dir,26 slug: dir.replace(/^\d+-/, ''),27 },28 chapters: fs29 .readdirSync(`content/projects/${dir}`)30 .filter((dir) => /^\d+/.test(dir))31 .map((tutorial) => {32 try {33 const md = fs.readFileSync(34 `content/projects/${dir}/${tutorial}/text.md`,35 'utf-8'36 );37 const { metadata } = extract_frontmatter(md);38 const slug = tutorial.replace(/^\d+-/, '');39 if (tutorialSlugs.has(slug))40 throw new Error(`Duplicate slug: ${slug}`);41 tutorialSlugs.add(slug);42 return {43 slug,44 title: metadata.title,45 tutorial_dir: dir,46 chapter_dir: tutorial,47 };48 } catch (err) {49 throw new Error(50 `Error building tutorial ${dir}/${tutorial}: ${err.message}`51 );52 }53 }),54 };55 });56 return tutorials;57}58export function get(req, res) {59 try {60 if (!json || process.env.NODE_ENV !== 'production') {61 json = get_tutorials();62 }63 send(res, 200, json);64 } catch (err) {65 send(res, 500, {66 message: err.message,67 });68 }...
config.js
Source:config.js
1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6 */7const fs = require('fs');8const path = require('path');9const SITE_CONFIG = require('../config');10const SRC_DIR = path.resolve(__dirname, '../src/client');11const DIST_DIR = path.resolve(__dirname, '../dist');12const DOCS_DIR = path.resolve(__dirname, '../content/docs');13const TUTORIAL_DIR = path.resolve(__dirname, '../content/tutorial');14const COMMUNITY_DIR = path.resolve(__dirname, '../content/community');15const BLOG_DIR = path.resolve(__dirname, '../content/blog');16const PAGE_STYLESHEETS_PROD_DIR = path.join(DIST_DIR, '/assets/css/prod');17const PAGE_STYLESHEETS = [18 '/assets/css/normalize.css',19 '/assets/css/main.css',20 '/assets/css/docs.css',21 '/assets/css/blog.css',22 '/assets/css/prismjs/themes/prism.css',23];24const __ENV__ = process.env.NODE_ENV || 'development';25const __PROD__ = __ENV__ === 'production';26const LWC_COMPILER_CONFIG = {27 exclude: ['**/codeMirror/**'],28 resolveFromPackages: false,29 stylesheetConfig: {30 customProperties: {31 allowDefinition: true,32 },33 },34};35const LWC_VERSION = '100';36const LWC_ENGINE_PATH = require.resolve('@lwc/engine/dist/umd/es2017/engine');37const DOCS_LIST = SITE_CONFIG.docs.pages;38function getStyleSheets() {39 if (__PROD__) {40 if (fs.existsSync(PAGE_STYLESHEETS_PROD_DIR)) {41 return fs.readdirSync(PAGE_STYLESHEETS_PROD_DIR).map((f) => path.join('/assets/css/prod', f));42 } else {43 return [];44 }45 } else {46 return PAGE_STYLESHEETS;47 }48}49module.exports = {50 SRC_DIR,51 DIST_DIR,52 DOCS_DIR,53 BLOG_DIR,54 TUTORIAL_DIR,55 COMMUNITY_DIR,56 __ENV__,57 __PROD__,58 LWC_COMPILER_CONFIG,59 LWC_ENGINE_PATH,60 LWC_VERSION,61 DOCS_LIST,62 PAGE_STYLESHEETS,63 PAGE_STYLESHEETS_PROD_DIR,64 getStyleSheets,...
Using AI Code Generation
1var path = require('path');2var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');3var path = require('path');4var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');5var path = require('path');6var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');7var path = require('path');8var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');9var path = require('path');10var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');11var path = require('path');12var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');13var path = require('path');14var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');15var path = require('path');16var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');17var path = require('path');18var TUTORIAL_DIR = path.join(__dirname, 'TUTORIAL_DIR');
Using AI Code Generation
1var tutorial = require('tutorial');2console.log('Sum of numbers: ' + tutorial.sum(1, 2));3console.log('PI value: ' + tutorial.PI);4console.log(new tutorial.SomeMathObject());5module.exports = {6 sum: function (num1, num2) {7 return num1 + num2;8 },9 SomeMathObject: function () {10 this.value = 0;11 this.increment = function (inc) {12 this.value += typeof inc === 'number' ? inc : 1;13 };14 }15};16var tutorial = require('tutorial');17console.log('Sum of numbers: ' + tutorial.sum(1, 2));18console.log('PI value: ' + tutorial.PI);19console.log(new tutorial.SomeMathObject());20module.exports = {21 sum: function (num1, num2) {22 return num1 + num2;23 },24 SomeMathObject: function () {25 this.value = 0;26 this.increment = function (inc) {27 this.value += typeof inc === 'number' ? inc : 1;28 };29 }30};31var tutorial = require('tutorial');32console.log('Sum of numbers: ' + tutorial.sum(1, 2));33console.log('PI value: ' + tutorial.PI);34console.log(new tutorial.SomeMathObject());35module.exports = {36 sum: function (num1, num2) {37 return num1 + num2;38 },39 SomeMathObject: function () {40 this.value = 0;41 this.increment = function (inc) {42 this.value += typeof inc === 'number' ? inc : 1;43 };44 }45};46var tutorial = require('tutorial');47console.log('Sum of numbers: ' + tutorial
Using AI Code Generation
1var path = require('path');2var TUTORIAL_DIR = path.join(__dirname, 'tutorials');3var tutorial = require(TUTORIAL_DIR + '/tutorial');4tutorial.printTutorial();5var path = require('path');6var TUTORIAL_DIR = path.join(__dirname, 'tutorials');7var tutorial = require(TUTORIAL_DIR + '/tutorial');8tutorial.printTutorial();9var path = require('path');10var TUTORIAL_DIR = path.join(__dirname, 'tutorials');11var tutorial = require(TUTORIAL_DIR + '/tutorial');12tutorial.printTutorial();13var path = require('path');14var TUTORIAL_DIR = path.join(__dirname, 'tutorials');15var tutorial = require(TUTORIAL_DIR + '/tutorial');16tutorial.printTutorial();17var path = require('path');18var TUTORIAL_DIR = path.join(__dirname, 'tutorials');19var tutorial = require(TUTORIAL_DIR + '/tutorial');20tutorial.printTutorial();21var path = require('path');22var TUTORIAL_DIR = path.join(__dirname, 'tutorials');23var tutorial = require(TUTORIAL_DIR + '/tutorial');24tutorial.printTutorial();25var path = require('path');26var TUTORIAL_DIR = path.join(__dirname, 'tutorials');27var tutorial = require(TUTORIAL_DIR + '/tutorial');28tutorial.printTutorial();29var path = require('path');30var TUTORIAL_DIR = path.join(__dirname, 'tutorials');31var tutorial = require(TUTORIAL_DIR + '/tutorial');32tutorial.printTutorial();33var path = require('path');34var TUTORIAL_DIR = path.join(__dirname, 'tutorials');35var tutorial = require(TUTORIAL_DIR + '/tutorial
Using AI Code Generation
1var bp = require('./bestPractice.js');2var path = bp.TUTORIAL_DIR();3console.log(path);4var path = require('path');5var dir = path.join(__dirname, 'tutorial');6exports.TUTORIAL_DIR = function() {7 return dir;8};9var bp = require('./bestPractice.js');10var path = bp.TUTORIAL_DIR();11console.log(path);12var path = require('path');13var dir = path.join(__dirname, 'tutorial');14exports.TUTORIAL_DIR = function() {15 return dir;16};17var path = require('path');18var dir = path.basename(__dirname);19console.log(dir);20var path = require('path');21var file = path.basename(__filename);22console.log(file);23var path = require('path');24var dir = path.basename(path.join(__dirname, '..'));25console.log(dir);
Using AI Code Generation
1var path = require('path');2var tutorialDir = path.join(__dirname, 'tutorials');3var tutorials = require('bestpractice')(tutorialDir);4module.exports = {5 {6 },7 {8 }9};10module.exports = {11 {12 },13 {14 }15};16module.exports = {17 {18 },19 {20 }21};22var path = require('path');23var tutorialDir = path.join(__dirname, 'tutorials');24var tutorials = require('bestpractice')(tutorialDir);25module.exports = {26 {27 },28 {
Using AI Code Generation
1var path = require('path');2console.log('Normal path string: ' + __dirname);3console.log('Normal path string: ' + __filename);4console.log('Join path: ' + path.join(__dirname, 'www', 'files', 'uploads'));5console.log('Resolved path: ' + path.resolve('www', 'files', 'uploads'));6console.log('Normalized path: ' + path.normalize('www/files/uploads/'));7console.log('Base name: ' + path.basename(__filename));8console.log('Directory name: ' + path.dirname(__filename));9console.log('Extension name: ' + path.extname(__filename));10console.log(path.parse(__filename));11console.log(path.format({12}));13console.log('File separator: ' + path.sep);14console.log('Path delimiter: ' + path.delimiter);15console.log('POSIX path: ' + path.posix);16console.log('Windows path: ' + path.win32);17console.log('Absolute path: ' + path.isAbsolute('/home/nodejs'));18console.log('Relative path: ' + path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb'));19console.log('Namespaced path: ' + path.toNamespacedPath('/foo/bar'));20console.log('Directory name: ' + path.dirname(__filename));21console.log('Extension name: ' + path.extname(__filename));22console.log(path.parse(__filename));23console.log(path.format({
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!!