Skip to content

Commit

Permalink
remove lodash from test files and example dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
tedeh committed Aug 12, 2022
1 parent dcf354e commit d8c27fa
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 26 deletions.
1 change: 0 additions & 1 deletion examples/context/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const _ = require('lodash');
const jayson = require('jayson');
const jsonParser = require('body-parser').json;
const express = require('express');
Expand Down
3 changes: 1 addition & 2 deletions examples/faq_recommended_http_server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const _ = require('lodash');
const jayson = require('jayson');
const jsonParser = require('body-parser').json;
const express = require('express');
Expand All @@ -9,7 +8,7 @@ const app = express();
// create a plain jayson server
const server = new jayson.server({
add: function(numbers, callback) {
callback(null, _.reduce(numbers, (sum, val) => sum + val, 0));
callback(null, Object.keys(numbers).reduce((sum, key) => sum + numbers[key], 0));
}
});

Expand Down
6 changes: 3 additions & 3 deletions examples/method_definitions/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const jayson = require('jayson');
const _ = require('lodash');

const methods = {

Expand All @@ -27,7 +26,7 @@ const methods = {
// this method returns true when it gets an array (which it always does)
isArray: new jayson.Method({
handler: function(args, done) {
const result = _.isArray(args);
const result = Array.isArray(args);
done(null, result);
},
params: Array // could also be "Object"
Expand All @@ -46,7 +45,8 @@ server.http().listen(3000);

// sums all numbers in an array or object
function sum(list) {
return _.reduce(list, function(sum, val) {
return Object.keys(list).reduce(function(sum, key) {
const val = list[key];
return sum + val;
}, 0);
}
5 changes: 2 additions & 3 deletions examples/method_wrapping/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const jayson = require('jayson');
const _ = require('lodash');

const server = new jayson.server({
add: validateReturnsNumber(function (args, done) {
const result = _.reduce(args, (sum, val) => sum + val, 0);
const result = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
done(null, result);
}),
});
Expand All @@ -18,7 +17,7 @@ function validateReturnsNumber (fn) {
const self = this;
return fn(args, function (err, result) {
if (err) return done(err);
if (!_.isFinite(result)) {
if (!isFinite(result)) {
return done(self.error(500, 'not a finite number'));
}
return done(null, result);
Expand Down
3 changes: 1 addition & 2 deletions examples/promise/server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict';

const jayson = require('jayson/promise');
const _ = require('lodash');

const server = new jayson.server({

add: async function(args) {
const sum = _.reduce(args, function(sum, value) { return sum + value; }, 0);
const sum = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
return sum;
},

Expand Down
3 changes: 1 addition & 2 deletions examples/promise_batches/server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

const jayson = require('jayson/promise');
const _ = require('lodash');

const server = new jayson.server({

add: function(args) {
return new Promise(function(resolve, reject) {
const sum = _.reduce(args, function(sum, value) { return sum + value; }, 0);
const sum = Object.keys(args).reduce((sum, value) => sum + value, 0);
resolve(sum);
});
}
Expand Down
5 changes: 2 additions & 3 deletions test/promise.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const reduce = require('lodash/reduce');
const should = require('should');
const fetch = require('node-fetch');
const jayson = require('./../promise');
Expand Down Expand Up @@ -273,7 +272,7 @@ describe('jayson/promise', function() {
const handlers = {
sum: function(args) {
return new Promise(function(resolve, reject) {
const sum = reduce(args, function(sum, arg) { return sum + arg; }, 0);
const sum = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
resolve(sum);
});
},
Expand All @@ -286,7 +285,7 @@ describe('jayson/promise', function() {
// returns a "Promise-like" object
thenable: function(args) {
return {then: function(resolve, reject) {
const sum = reduce(args, function(sum, arg) { return sum + arg; }, 0);
const sum = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
resolve(sum);
}};
}
Expand Down
7 changes: 2 additions & 5 deletions test/support/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

const reduce = require('lodash/reduce');
const isArray = require('lodash/isArray');
const isNumber = require('lodash/isNumber');
const should = require('should');
const jayson = require('./../../');
const fs = require('fs');
Expand All @@ -27,7 +24,7 @@ exports.server.methods = () => ({
},

incrementCounterBy: function(args, callback) {
const {counter, value} = isArray(args) ? {counter: args[0], value: args[1]} : args;
const {counter, value} = Array.isArray(args) ? {counter: args[0], value: args[1]} : args;
if(!(counter instanceof exports.Counter)) {
return callback(this.error(-1000, 'Argument not an instance of Counter'));
}
Expand All @@ -36,7 +33,7 @@ exports.server.methods = () => ({
},

add: function(args, callback) {
const result = reduce(args, (sum, arg) => isNumber(arg) ? sum + arg : sum, 0);
const result = Object.keys(args).reduce((sum, key) => sum + (typeof args[key] === 'number' ? args[key] : 0), 0);
callback(null, result);
},

Expand Down
10 changes: 5 additions & 5 deletions typescript/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as jayson from './..';
import * as jaysonPromise from './../promise';
import jaysonBrowserClient from './../lib/client/browser';
import jaysonPromiseBrowserClient from './../promise/lib/client/browser';
import { reduce, isArray } from 'lodash';
import { Express } from 'express-serve-static-core';
import WebSocket from 'isomorphic-ws';

Expand Down Expand Up @@ -167,7 +166,7 @@ export function test_example_10() {

add: function(args:any) {
return new Promise(function(resolve, reject) {
const sum = reduce(args, function(sum:number, value:number) { return sum + value; }, 0);
const sum = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
resolve(sum);
});
}
Expand Down Expand Up @@ -312,7 +311,7 @@ export function test_example_17() {
// this method returns true when it gets an array (which it always does)
isArray: new jayson.Method({
handler: function(args:any, done:any) {
const result = isArray(args);
const result = Array.isArray(args);
done(null, result);
},
params: Array // could also be "Object"
Expand All @@ -329,7 +328,8 @@ export function test_example_17() {

// sums all numbers in an array
function sum(list:any) {
return reduce(list, function(sum:any, val:any) {
return Object.keys(list).reduce(function(sum:any, key:string) {
const val = list[key];
return sum + val;
}, 0);
}
Expand Down Expand Up @@ -390,7 +390,7 @@ export function test_example_21() {

add: function(args:any) {
return new Promise(function(resolve, reject) {
const sum = reduce(args, function(sum:any, value:any) { return sum + value; }, 0);
const sum = Object.keys(args).reduce((sum, key) => sum + args[key], 0);
resolve(sum);
});
},
Expand Down

0 comments on commit d8c27fa

Please sign in to comment.