diff --git a/examples/context/server.js b/examples/context/server.js index 000dd59..6f1a3cb 100644 --- a/examples/context/server.js +++ b/examples/context/server.js @@ -1,6 +1,5 @@ 'use strict'; -const _ = require('lodash'); const jayson = require('jayson'); const jsonParser = require('body-parser').json; const express = require('express'); diff --git a/examples/faq_recommended_http_server/server.js b/examples/faq_recommended_http_server/server.js index 8e3f3b4..8ccfbc8 100644 --- a/examples/faq_recommended_http_server/server.js +++ b/examples/faq_recommended_http_server/server.js @@ -1,6 +1,5 @@ 'use strict'; -const _ = require('lodash'); const jayson = require('jayson'); const jsonParser = require('body-parser').json; const express = require('express'); @@ -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)); } }); diff --git a/examples/method_definitions/server.js b/examples/method_definitions/server.js index 028f1d9..683c575 100644 --- a/examples/method_definitions/server.js +++ b/examples/method_definitions/server.js @@ -1,7 +1,6 @@ 'use strict'; const jayson = require('jayson'); -const _ = require('lodash'); const methods = { @@ -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" @@ -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); } diff --git a/examples/method_wrapping/server.js b/examples/method_wrapping/server.js index 2b51a20..4359c46 100644 --- a/examples/method_wrapping/server.js +++ b/examples/method_wrapping/server.js @@ -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); }), }); @@ -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); diff --git a/examples/promise/server.js b/examples/promise/server.js index 95fcfdf..d0fed67 100644 --- a/examples/promise/server.js +++ b/examples/promise/server.js @@ -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; }, diff --git a/examples/promise_batches/server.js b/examples/promise_batches/server.js index e7afdd9..9f7a3bc 100644 --- a/examples/promise_batches/server.js +++ b/examples/promise_batches/server.js @@ -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); }); } diff --git a/test/promise.test.js b/test/promise.test.js index 4f01416..de1628b 100644 --- a/test/promise.test.js +++ b/test/promise.test.js @@ -1,6 +1,5 @@ 'use strict'; -const reduce = require('lodash/reduce'); const should = require('should'); const fetch = require('node-fetch'); const jayson = require('./../promise'); @@ -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); }); }, @@ -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); }}; } diff --git a/test/support/index.js b/test/support/index.js index c34a37f..eeb46f6 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -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'); @@ -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')); } @@ -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); }, diff --git a/typescript/test.ts b/typescript/test.ts index 88e78bf..ff7f53b 100644 --- a/typescript/test.ts +++ b/typescript/test.ts @@ -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'; @@ -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); }); } @@ -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" @@ -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); } @@ -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); }); },