Best JavaScript code snippet using wpt
index.js
Source:index.js
1module.exports = function PgOrderByMultiColumnIndexPlugin(2 builder,3 { orderByNullsLast }4) {5 builder.hook("build", build => {6 const pkg = require("./package.json");7 // Check dependencies8 if (!build.versions) {9 throw new Error(10 `Plugin ${pkg.name}@${pkg.version} requires graphile-build@^4.1.0 in order to check dependencies (current version: ${build.graphileBuildVersion})`11 );12 }13 const depends = (name, range) => {14 if (!build.hasVersion(name, range)) {15 throw new Error(16 `Plugin ${pkg.name}@${pkg.version} requires ${name}@${range} (${17 build.versions[name]18 ? `current version: ${build.versions[name]}`19 : "not found"20 })`21 );22 }23 };24 depends("graphile-build-pg", "^4.1.0");25 // Register this plugin26 build.versions = build.extend(build.versions, { [pkg.name]: pkg.version });27 return build;28 });29 builder.hook("inflection", inflection => {30 return Object.assign(inflection, {31 orderByMultiColumnIndexEnum(specs) {32 const nullOrderingSuffix = (ascending, nullsFirst) => {33 // Only include a null ordering suffix if it differs34 // from the application default (specified using35 // `graphileBuildOptions.orderByNullsLast`).36 if (orderByNullsLast === true) {37 // Defaults are ASC NULLS LAST and DESC NULLS LAST, so38 // ASC NULLS FIRST and DESC NULLS FIRST need a suffix:39 if (ascending === true && nullsFirst === true) {40 return "-nulls-first";41 } else if (ascending === false && nullsFirst === true) {42 return "-nulls-first";43 } else {44 return "";45 }46 } else {47 // Defaults are ASC NULLS LAST and DESC NULLS FIRST, so48 // ASC NULLS FIRST and DESC NULLS LAST need a suffix:49 if (ascending === true && nullsFirst === true) {50 return "-nulls-first";51 } else if (ascending === false && nullsFirst === false) {52 return "-nulls-last";53 } else {54 return "";55 }56 }57 };58 return `${specs59 .map(([attr, ascending, nullsFirst]) =>60 this.constantCase(61 `${this.orderByColumnEnum(attr, ascending)}${nullOrderingSuffix(62 ascending,63 nullsFirst64 )}`65 )66 )67 .join("__")}`;68 },69 });70 });71 builder.hook("GraphQLEnumType:values", (values, build, context) => {72 const {73 extend,74 inflection,75 pgIntrospectionResultsByKind: introspectionResultsByKind,76 describePgEntity,77 } = build;78 const {79 scope: { isPgRowSortEnum, pgIntrospection: table },80 } = context;81 if (!isPgRowSortEnum || !table || table.kind !== "class") {82 return values;83 }84 return extend(85 values,86 introspectionResultsByKind.index87 .filter(index => index.class.id === table.id)88 .reduce((memo, index) => {89 const attributes = index.attributeNums.map(nr =>90 index.class.attributes.find(attr => attr.num === nr)91 );92 if (attributes.length <= 1 || attributes.includes(undefined)) {93 // Not a multi-column index94 return memo;95 }96 // Specs for scanning the index forward97 const forwardSpecs = attributes.map((attr, idx) => [98 attr,99 index.attributePropertiesAsc[idx],100 index.attributePropertiesNullsFirst[idx],101 ]);102 // Specs for scanning the index backward (flip asc/desc and nulls first/last)103 const backwardSpecs = attributes.map((attr, idx) => [104 attr,105 !index.attributePropertiesAsc[idx],106 !index.attributePropertiesNullsFirst[idx],107 ]);108 const forwardEnumName = inflection.orderByMultiColumnIndexEnum(109 forwardSpecs110 );111 const backwardEnumName = inflection.orderByMultiColumnIndexEnum(112 backwardSpecs113 );114 memo = extend(115 memo,116 {117 [forwardEnumName]: {118 value: {119 alias: forwardEnumName.toLowerCase(),120 specs: forwardSpecs.map(([attr, ascending, nullsFirst]) => [121 attr.name,122 ascending,123 nullsFirst,124 ]),125 },126 },127 },128 `Adding multi-column index forward orderBy enum value for ${attributes129 .map(attr => describePgEntity(attr))130 .join(", ")}.`131 );132 memo = extend(133 memo,134 {135 [backwardEnumName]: {136 value: {137 alias: backwardEnumName.toLowerCase(),138 specs: backwardSpecs.map(([attr, ascending, nullsFirst]) => [139 attr.name,140 ascending,141 nullsFirst,142 ]),143 },144 },145 },146 `Adding multi-column index backward orderBy enum value for ${attributes147 .map(attr => describePgEntity(attr))148 .join(", ")}.`149 );150 return memo;151 }, {}),152 `Adding multi-column index order values for table '${table.name}'`153 );154 });...
order.test.js
Source:order.test.js
1const { sq, query } = require('../tape')2describe('order', () => {3 query({4 name: 'simple',5 query: sq.from`book`.orderBy`title`,6 text: 'select * from book order by title',7 args: []8 })9 query({10 name: 'two',11 query: sq.from`book`.orderBy`title`.orderBy`year, author`,12 text: 'select * from book order by title, year, author',13 args: []14 })15 query({16 name: 'multiple',17 query: sq.from`book`.orderBy`title`.orderBy`year`.orderBy`author`,18 text: 'select * from book order by title, year, author',19 args: []20 })21 query({22 name: 'string',23 query: sq.from('book').orderBy('title'),24 text: 'select * from book order by title',25 args: []26 })27 query({28 name: 'two strings',29 query: sq.from('book').orderBy('title', 'year'),30 text: 'select * from book order by title, year',31 args: []32 })33 query({34 name: 'string args',35 query: sq.from('book').orderBy('title', 'year', 'author'),36 text: 'select * from book order by title, year, author',37 args: []38 })39 query({40 name: 'subquery args',41 query: sq42 .from('book')43 .orderBy(sq.txt`title asc`, sq.txt`year desc`, sq.txt`author`),44 text: 'select * from book order by title asc, year desc, author',45 args: []46 })47 query({48 name: 'object arg - by',49 query: sq.from`book`.orderBy({ by: 'title' }, { by: 'year' }),50 text: 'select * from book order by title, year',51 args: []52 })53 query({54 name: 'object arg - sort asc',55 query: sq.from`book`.orderBy({ by: 'title', sort: 'asc' }),56 text: 'select * from book order by title asc',57 args: []58 })59 query({60 name: 'object arg - sort desc',61 query: sq.from`book`.orderBy({ by: 'title', sort: 'desc' }),62 text: 'select * from book order by title desc',63 args: []64 })65 query({66 name: 'object arg - sort using',67 query: sq.from`book`.orderBy({ by: 'title', using: '~<~' }),68 text: 'select * from book order by title using ~<~',69 args: []70 })71 query({72 name: 'object arg - nulls first',73 query: sq.from`book`.orderBy({ by: 'title', nulls: 'first' }),74 text: 'select * from book order by title nulls first',75 args: []76 })77 query({78 name: 'object arg - nulls first',79 query: sq.from`book`.orderBy({ by: 'title', nulls: 'last' }),80 text: 'select * from book order by title nulls last',81 args: []82 })83 query({84 name: 'object arg - sort desc nulls last',85 query: sq.from`book`.orderBy({ by: 'title', sort: 'desc', nulls: 'last' }),86 text: 'select * from book order by title desc nulls last',87 args: []88 })89 query({90 name: 'object arg - sort asc nulls first',91 query: sq.from`book`.orderBy({ by: 'title', sort: 'asc', nulls: 'first' }),92 text: 'select * from book order by title asc nulls first',93 args: []94 })95 query({96 name: 'object arg - sort using nulls first',97 query: sq.from`book`.orderBy({ by: 'title', using: '<', nulls: 'first' }),98 text: 'select * from book order by title using < nulls first',99 args: []100 })101 query({102 name: 'object arg - sort using nulls last',103 query: sq.from`book`.orderBy({ by: 'title', using: '<', nulls: 'last' }),104 text: 'select * from book order by title using < nulls last',105 args: []106 })107 query({108 name: 'multiple complex object args',109 query: sq.from`book`.orderBy(110 { by: 'title', sort: 'asc' },111 { by: 'year', sort: '<', nulls: 'last' },112 { by: 'author', nulls: 'last' }113 ),114 text:115 'select * from book order by title asc, year using < nulls last, author nulls last',116 args: []117 })118 query({119 name: 'multiple args - object, string, subquery',120 query: sq.from`book`.orderBy(121 { by: 'title', sort: 'asc' },122 'year using < nulls last',123 sq.txt`author nulls last`124 ),125 text:126 'select * from book order by title asc, year using < nulls last, author nulls last',127 args: []128 })...
DataGroupingTest.js
Source:DataGroupingTest.js
1var DataGroupingTest = TestCase("DataGroupingTest");2DataGroupingTest.prototype.testApproxSum = function () {3 // Case 1: nulls exclusively4 var arr = [];5 arr.hasNulls = true;6 assertNull('Sum non-null values', approximations.sum(arr));7 // Case 2: nulls and numbers8 var arr = [1,2,3,4];9 arr.hasNulls = true;10 assertEquals('Sum nulls and numbers', 10, approximations.sum(arr));11 // Case 3: numbers only12 var arr = [1,2,3,4];13 assertEquals('Sum non-null values', 10, approximations.sum(arr));14 // Case 4: no values at all15 var arr = [];16 assertUndefined('Sum empty array', approximations.sum(arr));17};18DataGroupingTest.prototype.testApproxAverage = function () {19 // Case 1: nulls exclusively20 var arr = [];21 arr.hasNulls = true;22 assertNull('Average non-null values', approximations.average(arr));23 // Case 2: nulls and numbers24 var arr = [1,2,3,4];25 arr.hasNulls = true;26 assertEquals('Average nulls and numbers', 2.5, approximations.average(arr));27 // Case 3: numbers only28 var arr = [1,2,3,4];29 assertEquals('Average non-null values', 2.5, approximations.average(arr));30 // Case 4: no values at all31 var arr = [];32 assertUndefined('Average empty array', approximations.average(arr));33};34DataGroupingTest.prototype.testApproxOpen = function () {35 // Case 1: nulls exclusively36 var arr = [];37 arr.hasNulls = true;38 assertNull('Open non-null values', approximations.open(arr));39 // Case 2: nulls and numbers40 var arr = [1,2,3,4];41 arr.hasNulls = true;42 assertEquals('Open nulls and numbers', 1, approximations.open(arr));43 // Case 3: numbers only44 var arr = [1,2,3,4];45 assertEquals('Open non-null values', 1, approximations.open(arr));46 // Case 4: no values at all47 var arr = [];48 assertUndefined('Open empty array', approximations.open(arr));49};50DataGroupingTest.prototype.testApproxHigh = function () {51 // Case 1: nulls exclusively52 var arr = [];53 arr.hasNulls = true;54 assertNull('High non-null values', approximations.high(arr));55 // Case 2: nulls and numbers56 var arr = [1,2,3,4,3];57 arr.hasNulls = true;58 assertEquals('High nulls and numbers', 4, approximations.high(arr));59 // Case 3: numbers only60 var arr = [1,2,3,4,3];61 assertEquals('High non-null values', 4, approximations.high(arr));62 // Case 4: no values at all63 var arr = [];64 assertUndefined('High empty array', approximations.high(arr));65};66DataGroupingTest.prototype.testApproxLow = function () {67 // Case 1: nulls exclusively68 var arr = [];69 arr.hasNulls = true;70 assertNull('Low non-null values', approximations.low(arr));71 // Case 2: nulls and numbers72 var arr = [2,1,2,3,4,3];73 arr.hasNulls = true;74 assertEquals('Low nulls and numbers', 1, approximations.low(arr));75 // Case 3: numbers only76 var arr = [2,1,2,3,4,3];77 assertEquals('Low non-null values', 1, approximations.low(arr));78 // Case 4: no values at all79 var arr = [];80 assertUndefined('Low empty array', approximations.low(arr));81};82DataGroupingTest.prototype.testGroupData = function() {83 // One value each84 var xData = [0, 1, 2, 3],85 yData = [3, 2, 1, 0],86 groupPositions = [0, 1, 2, 3];87 // Add an empty options dataset88 Series.prototype.options = [];89 assertEquals('Sum', '3,2,1,0', Series.prototype.groupData(xData, yData, groupPositions, 'sum')[1].join(','));90 // Two values each91 var xData = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5],92 yData = [1, 1, 1, 1, 1, 1, 1, 1],93 groupPositions = [0, 1, 2, 3];94 assertEquals('Sum', '2,2,2,2', Series.prototype.groupData(xData, yData, groupPositions, 'sum')[1].join(','));...
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var async = require('async');4var _ = require('underscore');5var request = require('request');6var jsonfile = require('jsonfile');7var file = 'data.json';8var data = require('./data.json');9var data2 = require('./data2.json');10var data3 = require('./data3.json');11var data4 = require('./data4.json');12var data5 = require('./data5.json');13var data6 = require('./data6.json');14var data7 = require('./data7.json');15var data8 = require('./data8.json');16var data9 = require('./data9.json');17var data10 = require('./data10.json');18var data11 = require('./data11.json');19var data12 = require('./data12.json');20var data13 = require('./data13.json');21var data14 = require('./data14.json');22var data15 = require('./data15.json');23var data16 = require('./data16.json');24var data17 = require('./data17.json');25var data18 = require('./data18.json');26var data19 = require('./data19.json');27var data20 = require('./data20.json');28var data21 = require('./data21.json');29var data22 = require('./data22.json');30var data23 = require('./data23.json');31var data24 = require('./data24.json');32var data25 = require('./data25.json');33var data26 = require('./data26.json');34var data27 = require('./data27.json');35var data28 = require('./data28.json');36var data29 = require('./data29.json');37var data30 = require('./data30.json');38var data31 = require('./data31.json');39var data32 = require('./data32.json');40var data33 = require('./data33.json');41var data34 = require('./data34.json');42var data35 = require('./data35.json');43var data36 = require('./data36.json');44var data37 = require('./data37.json');45var data38 = require('./data38.json');46var data39 = require('./data39.json');47var data40 = require('./data40.json');48var data41 = require('./data41.json');49var data42 = require('./data42.json');50var data43 = require('./data43.json');51var data44 = require('./data44.json');
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2 if (err) {3 console.log(err);4 } else {5 console.log(result);6 }7});8### nullsSync(url)9var wptoolkit = require('wptoolkit');10console.log(result);11### headers(url, callback)12var wptoolkit = require('wptoolkit');13 if (err) {14 console.log(err);15 } else {16 console.log(result);17 }18});19### headersSync(url)20var wptoolkit = require('wptoolkit');21console.log(result);22### htmlSize(url, callback)
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var result = wptoolkit.nulls(1);3console.log(result);4var wptoolkit = require('wptoolkit');5var result = wptoolkit.nulls(2);6console.log(result);7var wptoolkit = require('wptoolkit');8var result = wptoolkit.nulls(3);9console.log(result);10var wptoolkit = require('wptoolkit');11var result = wptoolkit.nulls(4);12console.log(result);13var wptoolkit = require('wptoolkit');14var result = wptoolkit.nulls(5);15console.log(result);16var wptoolkit = require('wptoolkit');17var result = wptoolkit.nulls(6);18console.log(result);19var wptoolkit = require('wptoolkit');20var result = wptoolkit.nulls(7);21console.log(result);22var wptoolkit = require('wptoolkit');23var result = wptoolkit.nulls(8);24console.log(result);25var wptoolkit = require('wptoolkit');26var result = wptoolkit.nulls(9);27console.log(result);28var wptoolkit = require('wptoolkit');29var result = wptoolkit.nulls(10);30console.log(result);
Using AI Code Generation
1const wptools = require('wptools')2const fs = require('fs')3function getData(page) {4 wptools.page(page).get().then(data => {5 let pageData = {6 }7 data.push(pageData)8 console.log(pageData)9 })10}11pages.forEach(page => {12 getData(page)13})14fs.writeFile(outputFile, JSON.stringify(data, null, 2), function (err) {15 if (err) return console.log(err)16 console.log('Data written to ' + outputFile)17})
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!!