Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change lodash imports #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:8.4
- image: circleci/node:8.9.0

working_directory: ~/repo

Expand All @@ -27,7 +27,7 @@ jobs:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run: yarn lint
- run: yarn test

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "mocha",
"test-watch": "mocha --watch",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this script in here as well to make it easier to make fixes and test at the same time.

"lint": "eslint src test",
"build": "babel src --out-dir lib && webpack-cli -p && cp package.json README.md index.d.ts ./lib",
"release": "yarn lint && yarn test && yarn version && yarn build && yarn push",
Expand Down
3 changes: 2 additions & 1 deletion src/collector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { filter, matches } from 'lodash';
import filter from 'lodash/filter';
import matches from 'lodash/matches';
import { findExistingMetric } from './utils';

export default class Collector {
Expand Down
3 changes: 2 additions & 1 deletion src/histogram.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { reduce, sum } from 'lodash';
import reduce from 'lodash/reduce';
import sum from 'lodash/sum';

import { resetAll } from './mixins';
import Collector from './collector';
Expand Down
3 changes: 2 additions & 1 deletion src/mixins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { each, omit } from 'lodash';
import each from 'lodash/each';
import omit from 'lodash/omit';

export function add(amount, labels) {
if (typeof amount !== 'number') {
Expand Down
7 changes: 6 additions & 1 deletion src/registry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { zipObject, has, each, reduce, find, valuesIn } from 'lodash';
import zipObject from "lodash/zipObject";
import has from "lodash/has";
import each from "lodash/each";
import reduce from "lodash/reduce";
import find from "lodash/find";
import valuesIn from "lodash/valuesIn";

import { formatHistogramOrSummary, formatCounterOrGauge } from './utils';
import Counter from './counter';
Expand Down
19 changes: 8 additions & 11 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
isEqual,
omit,
keys,
map,
find,
reduce
} from 'lodash';
import isEqual from 'lodash/isEqual';
import omit from 'lodash/omit';
import reduce from 'lodash/reduce';
import find from 'lodash/find';

const getPairs = data => Object.keys(data).map(key => `${key}="${data[key]}"`);

function getLabelPairs(metric) {
const pairs = map(omit(metric, 'value'), (v, k) => `${k}="${v}"`);
const pairs = getPairs(omit(metric, 'value'));
return pairs.length === 0 ? '' : `${pairs.join(',')}`;
}

Expand Down Expand Up @@ -49,9 +46,9 @@ export function formatCounterOrGauge(name, metric) {
const value = ` ${metric.value.toString()}`;
// If there are no keys on `metric`, it doesn't have a label;
// return the count as a string.
if (keys(metric).length === 1 && typeof metric.value === 'number') {
if (Object.keys(metric).length === 1 && typeof metric.value === 'number') {
return `${name}${value}\n`;
}
const pair = map(omit(metric, 'value'), (v, k) => `${k}="${v}"`);
const pair = getPairs(omit(metric, 'value'));
return `${name}{${pair.join(',')}}${value}\n`;
}
Loading