Skip to content

Commit 5d5e0c3

Browse files
committed
fix: implement flattenDeep so lodash isn't required
1 parent 1315302 commit 5d5e0c3

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": "tsc --project .",
1515
"lint": "tslint **/*.ts",
1616
"pretest": "npm run build",
17-
"test": "test:unit",
17+
"test": "npm run test:unit",
1818
"test:unit": "ava dist/test **/__tests__/*.js",
1919
"posttest": "npm run lint",
2020
"semantic-release": "semantic-release pre && npm publish && semantic-release post",

scripts/generate-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const generateClientImplementation = async (getCommands: typeof getFullCommands)
4646
` * ${commandInfo.docs}`,
4747
` */`,
4848
`${commandInfo.name}(...args: any[]) {`,
49-
` const flattenedArgs = _.flattenDeep(args);`,
49+
` const flattenedArgs = flattenDeep(args);`,
5050
` return new Promise<any>((resolve, reject) => {`,
5151
` (this.redis as any).${commandInfo.name}.apply(`,
5252
` this.redis,`,
@@ -61,7 +61,7 @@ const generateClientImplementation = async (getCommands: typeof getFullCommands)
6161
});
6262

6363
return [
64-
`import * as _ from "lodash";`,
64+
`import { flattenDeep } from "../flatten";`,
6565
`import { RedisClient } from "redis";`,
6666
`import { IHandyRedis } from "./interface";`,
6767
`class HandyRedis implements IHandyRedis {`,

src/__tests__/flatten.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test from "ava";
2+
import { flattenDeep } from "../flatten";
3+
4+
test("already flat", t => {
5+
t.deepEqual(flattenDeep([1, 2, 3]), [1, 2, 3]);
6+
});
7+
8+
test("flatten shallow", t => {
9+
t.deepEqual(flattenDeep([1, 2, [3, 4]]), [1, 2, 3, 4]);
10+
});
11+
12+
test("flatten deep", t => {
13+
t.deepEqual(flattenDeep([1, 2, [3, [4, [5]]]]), [1, 2, 3, 4, 5]);
14+
});

src/flatten.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const flattenDeep = (args: any[]): any[] => {
2+
if (!Array.isArray(args)) {
3+
return args;
4+
}
5+
return [].concat(...args.map(flattenDeep) as any);
6+
};

src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ClientOpts, createClient, RedisClient } from "redis";
22
import { createHandyClient as _createHandyClient } from "./generated/client";
33
import { IHandyRedis } from "./generated/interface";
44

5-
export * from "redis";
65
export * from "./generated/interface";
76

87
export interface ICreateHandyClient {

0 commit comments

Comments
 (0)