Best JavaScript code snippet using wpt
20201203100604-update-integer-and-float-to-numeric-values.js
Source:20201203100604-update-integer-and-float-to-numeric-values.js
1'use strict'2const Sequelize = require('sequelize')3const DatabaseStandards = require('../database-standards')4const tablesToUpdate = [5 {6 tableName: 'payment',7 attributes: [8 {9 name: 'amount',10 previousType: Sequelize.INTEGER,11 nextType: DatabaseStandards.DECIMAL_TYPE12 },13 {14 name: 'psp_fee',15 previousType: Sequelize.INTEGER,16 nextType: DatabaseStandards.DECIMAL_TYPE17 }18 ]19 },20 {21 tableName: 'policy_insurance',22 attributes: [23 {24 name: 'monthly_price',25 previousType: Sequelize.FLOAT,26 nextType: DatabaseStandards.DECIMAL_TYPE27 },28 {29 name: 'default_deductible',30 previousType: Sequelize.FLOAT,31 nextType: DatabaseStandards.DECIMAL_TYPE32 },33 {34 name: 'default_ceiling',35 previousType: Sequelize.FLOAT,36 nextType: DatabaseStandards.DECIMAL_TYPE37 }38 ]39 },40 {41 tableName: 'quote_insurance',42 attributes: [43 {44 name: 'monthly_price',45 previousType: Sequelize.FLOAT,46 nextType: DatabaseStandards.DECIMAL_TYPE47 },48 {49 name: 'default_deductible',50 previousType: Sequelize.FLOAT,51 nextType: DatabaseStandards.DECIMAL_TYPE52 },53 {54 name: 'default_ceiling',55 previousType: Sequelize.FLOAT,56 nextType: DatabaseStandards.DECIMAL_TYPE57 }58 ]59 },60 {61 tableName: 'policy',62 attributes: [63 {64 name: 'premium',65 previousType: Sequelize.FLOAT,66 nextType: DatabaseStandards.DECIMAL_TYPE67 }68 ]69 },70 {71 tableName: 'quote',72 attributes: [73 {74 name: 'premium',75 previousType: Sequelize.FLOAT,76 nextType: DatabaseStandards.DECIMAL_TYPE77 }78 ]79 }80]81module.exports = {82 up: async (queryInterface) => {83 return upMigrationColumns(tablesToUpdate, queryInterface)84 },85 down: async (queryInterface) => {86 return downMigrationColumns(tablesToUpdate, queryInterface)87 }88}89function upMigrationColumns (columnsToUpdate, queryInterface) {90 return _updateTables(columnsToUpdate, queryInterface, true)91}92function downMigrationColumns (columnsToUpdate, queryInterface) {93 return _updateTables(columnsToUpdate, queryInterface, false)94}95function _updateTables (tablesToUpdate, queryInterface, isUpMigration) {96 return tablesToUpdate.map((tableToUpdate) => {97 return tableToUpdate.attributes.map((attribute) => {98 return queryInterface.changeColumn(tableToUpdate.tableName, attribute.name, {99 type: isUpMigration ? attribute.nextType : attribute.previousType100 })101 })102 })...
fieldUtils.js
Source:fieldUtils.js
1'use strict';23import _ from 'underscore'4import nodeUUID from 'node-uuid'5import morph from 'morph'67export const INTEGER_TYPE = 'integer'8export const STRING_TYPE = 'string'9export const DECIMAL_TYPE = 'decimal'10export const PERCENT_TYPE = 'percent'11export const FIELD_TYPES = [INTEGER_TYPE,STRING_TYPE,DECIMAL_TYPE,PERCENT_TYPE]12export const FIELD_DEFAULTS = { 13 "name":"", "id":"", 14 "isPrimaryKey":false, 15 "isVisible":true, 16 "label":"", 17 "type":DECIMAL_TYPE18}19/**20 * Class to encapsulate some 21 * rules about how DataSet fields are 22 * structured and typed.23 */24export class FieldBuilder {2526 /**27 * @private28 * best guess typing for supplied value.29 * @param {js primative} val sample value30 * @param {String} name column header or hint as to type.31 * @return {one of FIELD_TYPES} 32 */33 guessType(val, name='') {34 let type = STRING_TYPE35 if (typeof(val) == 'string') {36 if (val.endsWith('%')) {37 type = PERCENT_TYPE38 } else if (! isNaN(parseFloat(val))) {39 if (-1 < val.indexOf('.')) {40 type = DECIMAL_TYPE41 } else {42 type = INTEGER_TYPE43 }44 45 }46 } else if (typeof(val) == 'number') {47 if ( val == Math.floor(val)) {48 type = INTEGER_TYPE49 } else {50 type = DECIMAL_TYPE51 }52 }53 if ( type != PERCENT_TYPE && 54 ((-1 < name.toLowerCase().indexOf('percent')) || (-1 < name.indexOf('%'))) ) {55 type = PERCENT_TYPE56 }57 return type58 }5960 /**61 * @private62 * Based on supplied data row, build array of field info objects63 * which include a unique field-id for each property on the row.64 * @param {datarow} sample representative row of data65 * @param { DataSet} dataset parent DataSet66 * @return { array of object} intial properties for each field67 */68 buildFieldInfo(sample, dataset) {69 let fields = new Array()70 _.each(_.keys(sample), (key,index) => {71 let type = this.guessType(sample[key], key)72 let currField = _.findWhere(dataset.fields, {name: key})73 if (currField) {74 currField.type = type75 fields.push(currField)76 } else if (! _.contains(["id", "dataset", "createdAt", "updatedAt"], key)) {77 let fieldObj = _.clone(FIELD_DEFAULTS)78 fieldObj.name = key79 fieldObj.id = this._generateUniqueId()80 fieldObj.label = morph.toTitle(key)81 fieldObj.type = type82 fields.push(fieldObj)83 }84 })85 return fields86 }878889 _generateUniqueId() {90 return nodeUUID.v1();91 }
...
database-standards.js
Source:database-standards.js
1'use strict'2const Sequelize = require('sequelize')3const DEFAULT_DECIMAL_PRECISION = 144const DEFAULT_DECIMAL_SCALE = 65const DECIMAL_TYPE = Sequelize.DECIMAL(DEFAULT_DECIMAL_PRECISION, DEFAULT_DECIMAL_SCALE)6const DECIMAL_TYPE_SCALE_FIVE = Sequelize.DECIMAL(DEFAULT_DECIMAL_PRECISION, 5)7module.exports = {8 DECIMAL_TYPE,9 DECIMAL_TYPE_SCALE_FIVE...
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const path = require('path');4const csv = require('csv-parser');5const csvWriter = require('csv-write-stream');6const writer = csvWriter();7let data = [];8let data2 = [];9let data3 = [];10let data4 = [];11let data5 = [];12let data6 = [];13let data7 = [];14let data8 = [];15let data9 = [];16let data10 = [];17let data11 = [];18let data12 = [];19let data13 = [];20let data14 = [];21let data15 = [];22let data16 = [];23let data17 = [];24let data18 = [];25let data19 = [];26let data20 = [];27let data21 = [];28let data22 = [];29let data23 = [];30let data24 = [];31let data25 = [];32let data26 = [];33let data27 = [];34let data28 = [];35let data29 = [];36let data30 = [];37let data31 = [];38let data32 = [];39let data33 = [];40let data34 = [];41let data35 = [];42let data36 = [];43let data37 = [];44let data38 = [];45let data39 = [];46let data40 = [];47let data41 = [];48let data42 = [];49let data43 = [];50let data44 = [];51let data45 = [];52let data46 = [];53let data47 = [];54let data48 = [];55let data49 = [];56let data50 = [];57let data51 = [];58let data52 = [];59let data53 = [];60let data54 = [];61let data55 = [];62let data56 = [];63let data57 = [];64let data58 = [];65let data59 = [];66let data60 = [];67let data61 = [];68let data62 = [];69let data63 = [];70let data64 = [];71let data65 = [];72let data66 = [];73let data67 = [];74let data68 = [];75let data69 = [];76let data70 = [];77let data71 = [];78let data72 = [];79let data73 = [];80let data74 = [];81let data75 = [];82let data76 = [];83let data77 = [];84let data78 = [];85let data79 = [];86let data80 = [];87let data81 = [];88let data82 = [];89let data83 = [];90let data84 = [];91let data85 = [];92let data86 = [];93let data87 = [];94let data88 = [];95let data89 = [];
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var decimal_type = wptoolkit.decimal_type;3var decimal = decimal_type.create(5, 2);4console.log(decimal);5decimal.set(5.5);6console.log(decimal);7decimal.set(5.55);8console.log(decimal);9decimal.set(5.555);10console.log(decimal);11decimal.set(5.5555);12console.log(decimal);13decimal.set(5.55555);14console.log(decimal);15decimal.set(5.555555);16console.log(decimal);17decimal.set(5.5555555);18console.log(decimal);19decimal.set(5.55555555);20console.log(decimal);21decimal.set(5.555555555);22console.log(decimal);23decimal.set(5.5555555555);24console.log(decimal);25decimal.set(5.55555555555);26console.log(decimal);27decimal.set(5.555555555555);28console.log(decimal);29decimal.set(5.5555555555555);30console.log(decimal);31decimal.set(5.55555555555555);32console.log(decimal);33decimal.set(5.555555555555555);34console.log(decimal);35decimal.set(5.5555555555555555);36console.log(decimal);37decimal.set(5.55555555555555555);38console.log(decimal);39decimal.set(5.555555555555555555);40console.log(decimal);41decimal.set(5.5555555555555555555);42console.log(decimal);43decimal.set(5.55555555555555555555);44console.log(decimal);45decimal.set(5.555555555555555555555);46console.log(decimal);47decimal.set(5.5555555555555555555555);48console.log(decimal);49decimal.set(5.55555555555555555555555);50console.log(decimal);51decimal.set(5.555555555555555555555555);52console.log(decimal);53decimal.set(5.5555555555555555555555555);54console.log(decimal);55decimal.set(5.55555555555555555555555555);56console.log(decimal);57decimal.set(5.555555555555555555555555555);58console.log(decimal);59decimal.set(5.5555555555555555555555555555);60console.log(decimal);61decimal.set(5.55555555555555555555555555555);62console.log(decimal);63decimal.set(5.555555555555555
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!!