Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
fix code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianing committed Aug 7, 2020
1 parent c0cf892 commit 24d769f
Show file tree
Hide file tree
Showing 10 changed files with 6,852 additions and 19 deletions.
34 changes: 34 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"plugins": ["prettier", "@typescript-eslint"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"impliedStrict": true
},
"rules": {
"no-sparse-arrays": 0,
"no-self-assign": 0,
"no-unused-vars": 0, // @typescript-eslint/no-unused-vars
"no-inner-declarations": 0,
"prettier/prettier": 2,
"@typescript-eslint/no-unused-vars": 1,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-use-before-define": [2, { "functions": false }],
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/type-annotation-spacing": 0,
"@typescript-eslint/no-empty-function": 1
}
}
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"printWidth": 120,
"arrowParens": "always"
}
Empty file added __tests__
Empty file.
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"fix": "eslint --ext .ts ./src --fix && prettier --write ./src",
"lint": "eslint --ext .ts"
},
"repository": {
"type": "git",
Expand All @@ -17,9 +19,27 @@
},
"homepage": "https://github.com/ProtoTeam/intern-repo#readme",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^3.8.0",
"lodash": "^4.17.19"
},
"devDependencies": {
"@types/lodash": "^4.14.159"
"@types/lodash": "^4.14.159",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"prettier": "^2.0.5",
"typescript": "^3.9.7",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-angular": "^8.2.0",
"@types/jest": "^25.2.1",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"conventional-changelog-cli": "^2.0.28",
"eslint-plugin-prettier": "^3.1.0",
"jest": "^26.0.1",
"jest-extended": "^0.11.2",
"lint-staged": "^10.0.7",
"npm-run-all": "^4.1.5",
"ts-jest": "^25.4.0",
"ts-loader": "^7.0.0"
}
}
3 changes: 1 addition & 2 deletions src/data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Query } from './query';

/** 前端数据集模块 */
export class DataSet {

private data = [];

constructor(data: Data) {
Expand All @@ -31,4 +30,4 @@ export class DataSet {
public query() {
return new Query(this.data);
}
}
}
10 changes: 5 additions & 5 deletions src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Field } from './types';

/**
* 聚合求和
* @param field
* @param field
*/
export function SUM(field: string): Field {
return {
Expand All @@ -13,7 +13,7 @@ export function SUM(field: string): Field {

/**
* 聚合 MAX
* @param field
* @param field
*/
export function MAX(field: string): Field {
return {
Expand All @@ -24,7 +24,7 @@ export function MAX(field: string): Field {

/**
* 聚合 MIN
* @param field
* @param field
*/
export function MIN(field: string): Field {
return {
Expand All @@ -35,11 +35,11 @@ export function MIN(field: string): Field {

/**
* 无聚合字段
* @param field
* @param field
*/
export function RAW(field: string): Field {
return {
aggregate: 'raw',
field,
};
}
}
11 changes: 5 additions & 6 deletions src/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data, Field, Options, Order, Datum, Groups } from "./types";
import _ from "lodash";
import { Data, Field, Options, Order, Datum, Groups } from './types';
import _ from 'lodash';

export class Query {
private data: Data;
Expand Down Expand Up @@ -30,7 +30,7 @@ export class Query {
* @param asc
*/
public orderBy(fields: string, asc?: boolean): Query {
const order: Order = { order: asc ? "asc" : "desc", orderBy: fields };
const order: Order = { order: asc ? 'asc' : 'desc', orderBy: fields };

this.options = {
...this.options,
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Query {
public record(): Data {
const { select, orders, limit, gKey } = this.options;

const agg = select.find((e) => e.aggregate !== "raw");
const agg = select.find((e) => e.aggregate !== 'raw');

if (!agg) {
return _.orderBy(
Expand Down Expand Up @@ -107,13 +107,12 @@ export class Query {
}
default:
}

});

return _.orderBy(
res,
orders.map((e) => e.orderBy),
orders.map((e) => e.order)
);;
);
}
}
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export type Field = {
readonly aggregate: 'sum' | 'max' | 'min' | 'raw'; // 可扩展
/** 字段名 */
readonly field: string;
}
};

export type Order = {
order?: 'asc' | 'desc';
orderBy?: string;
}
};

export type Options = {
select?: Field[];
orders?: Order[];
limit?: number;
gKey?: string;
}
};

export type Groups = Map<string, Data>;
Loading

0 comments on commit 24d769f

Please sign in to comment.