Skip to content

Commit

Permalink
Merge pull request #115 from lzear/lodash-es
Browse files Browse the repository at this point in the history
Update `lodash` to `lodash-es`
  • Loading branch information
lzear authored Feb 27, 2024
2 parents 4e1b432 + 63568c3 commit 6e9c4ca
Show file tree
Hide file tree
Showing 27 changed files with 1,248 additions and 2,716 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-mirrors-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"votes": major
---

Update `lodash` to `lodash-es`. Change the package to be ESM by default.
7 changes: 4 additions & 3 deletions votes/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "votes",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"version": "2.2.2",
Expand Down Expand Up @@ -63,7 +64,7 @@
},
"dependencies": {
"javascript-lp-solver": "0.4.15",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"javascript-lp-solver": ">=0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion votes/src/classes/method.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { scoresToRanking } from '../utils/scores'

Expand Down
2 changes: 1 addition & 1 deletion votes/src/classes/random-matrix-method.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import type { Matrix, ScoreObject } from '../types'
import { shuffleArray } from '../utils/shuffle-array'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/baldwin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { RoundBallotMethod } from '../../classes/round-ballot-method'
import type { Ballot, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/biggest-support/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { BallotMethod } from '../../classes/ballot-method'
import type { Ballot } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/bottom-two-runoff/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { RoundBallotMethod } from '../../classes/round-ballot-method'
import type { Ballot, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/coombs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { RoundBallotMethod } from '../../classes/round-ballot-method'
import type { Ballot, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/copeland/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { MatrixScoreMethod } from '../../classes/matrix-score-method'
import type { Matrix, ScoreObject } from '../../types'
Expand Down
3 changes: 1 addition & 2 deletions votes/src/methods/kemeny/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import range from 'lodash/range'
import zipObject from 'lodash/zipObject'
import { range, zipObject } from 'lodash-es'

import { MatrixScoreMethod } from '../../classes/matrix-score-method'
import type { Matrix, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/majority-judgment/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { BallotMethod } from '../../classes/ballot-method'
import type { Ballot, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/maximal-lotteries/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zipObject from 'lodash/zipObject'
import { zipObject } from 'lodash-es'

import { RandomMatrixMethod } from '../../classes/random-matrix-method'
import { findNashEquilibrium } from '../../simplex/find-nash-equilibrium'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/minimax-td/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import type { Matrix, ScoreObject } from '../../types'
import { findSmithSet } from '../../utils/condorcet'
Expand Down
5 changes: 2 additions & 3 deletions votes/src/methods/nanson/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import sum from 'lodash/sum'
import _ from 'lodash-es'

import { RoundBallotMethod } from '../../classes/round-ballot-method'
import type { Ballot, ScoreObject } from '../../types'
Expand All @@ -16,7 +15,7 @@ const round = (
const borda = new Borda({ candidates, ballots })
const bordaScores = borda.scores()
const scores = Object.values(bordaScores)
const avg = sum(scores) / scores.length
const avg = _.sum(scores) / scores.length
const eliminated = candidates.filter((c) => bordaScores[c] <= avg)
const qualified = _.difference(candidates, eliminated)
return { eliminated, qualified, scores: bordaScores }
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/random-candidates/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zipObject from 'lodash/zipObject'
import { zipObject } from 'lodash-es'

import { RandomMethod } from '../../classes/random-method'
import type { ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/ranked-pairs/generate-acyclic-graph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { Tarjan } from './tarjan'
import { Vertex } from './vertex'
Expand Down
4 changes: 1 addition & 3 deletions votes/src/methods/ranked-pairs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import groupBy from 'lodash/groupBy'
import range from 'lodash/range'
import zipObject from 'lodash/zipObject'
import { groupBy, range, zipObject } from 'lodash-es'

import { MatrixScoreMethod } from '../../classes/matrix-score-method'
import type { Matrix, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/schulze/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import range from 'lodash/range'
import { range } from 'lodash-es'

import { MatrixScoreMethod } from '../../classes/matrix-score-method'
import type { Matrix, ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/methods/two-round-runoff/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import { RoundBallotMethod } from '../../classes/round-ballot-method'
import type { ScoreObject } from '../../types'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/test/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import range from 'lodash/range'
import { range } from 'lodash-es'

export const product = (a: number[][], b: number[][]): number[][] => {
const dimA = [a.length, a[0].length]
Expand Down
2 changes: 1 addition & 1 deletion votes/src/test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fill from 'lodash/fill'
import { fill } from 'lodash-es'

import type { Ballot } from '../types'
import { toWeightedBallots } from '../utils'
Expand Down
2 changes: 1 addition & 1 deletion votes/src/utils/condorcet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import type { Matrix } from '../types'

Expand Down
4 changes: 1 addition & 3 deletions votes/src/utils/make-matrix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import difference from 'lodash/difference'
import range from 'lodash/range'
import times from 'lodash/times'
import { difference, range, times } from 'lodash-es'

import type { Ballot, Matrix } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion votes/src/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash-es'

import type { Ballot } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion votes/src/utils/scores-zero.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import zipObject from 'lodash/zipObject'
import { zipObject } from 'lodash-es'

import type { ScoreObject } from '../types'

Expand Down
4 changes: 1 addition & 3 deletions votes/src/utils/scores.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import groupBy from 'lodash/groupBy'
import sortBy from 'lodash/sortBy'
import toPairs from 'lodash/toPairs'
import { groupBy, sortBy, toPairs } from 'lodash-es'

export const scoresToRanking = (scores: {
[candidate: string]: number
Expand Down
Loading

0 comments on commit 6e9c4ca

Please sign in to comment.