Skip to content

Commit

Permalink
feat: add many to one conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-Karia committed Aug 18, 2024
1 parent 9159202 commit 4984af0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
8 changes: 8 additions & 0 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ var convertMultiple = function (str, to) {
commands.push(convert(str, to[index]));
});
}
// many to one
else if (Array.isArray(str) && typeof to === 'string') {
str.forEach(function (s, index) {
commands.push(convert(s, to));
});
}
// many to many
else ;
return commands;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/npm-to-yarn.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/npm-to-yarn.umd.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const convertMultiple = (str: string | string[], to: Command | Command[])
}
// many to one
else if (Array.isArray(str) && typeof to === 'string') {
str.forEach((s, index) => {

Check warning on line 35 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (14.x)

'index' is defined but never used

Check warning on line 35 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (16.x)

'index' is defined but never used

Check warning on line 35 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (18.x)

'index' is defined but never used
commands.push(convert(s, to))
})
}
// many to many
else if (Array.isArray(str) && Array.isArray(to)) {

Check failure on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (14.x)

Empty block statement

Check failure on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (16.x)

Empty block statement

Check failure on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Build (18.x)

Empty block statement
Expand Down
48 changes: 43 additions & 5 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global it, expect, describe */

import {convert, convertMultiple, type Command } from '../src'
import { convert, convertMultiple, type Command } from '../src'

describe('NPM tests', () => {
const tests: [npm: string, yarn: string, pnpm: string, bun: string][] = [
Expand Down Expand Up @@ -462,11 +462,49 @@ describe("Multiple Convert Tests", () => {
},
]

// many to one
const manyToOneTests: {
command: string[],
managers: Command,
result: string[]
}[] = [
{
command: ["npm install react", "npm install react-dom"],
managers: "yarn",
result: ["yarn add react", "yarn add react-dom"]
},
{
command: ["npm install squirrelly --save", "npm install react --save-optional"],
managers: "pnpm",
result: ["pnpm add squirrelly", "pnpm add react --save-optional"]
},
{
command: ["npm install squirrelly -E", "npm install react --save-prod"],
managers: "bun",
result: ["bun add squirrelly --exact", "bun add react --production"]
},
{
command: ["npm install squirrelly --save-optional", "npm install react --save-prod"],
managers: "yarn",
result: ["yarn add squirrelly --optional", "yarn add react --production"]
},
{
command: ["npm outdated", "npm outdated react"],
managers: "pnpm",
result: ["pnpm outdated", "pnpm outdated react"]
},
]
// many to many

describe("One to Many", () => {
it.each(oneToManyTests)('%s', (tests) => {
expect(convertMultiple(tests.command, tests.managers)).toEqual(tests.result)
it.each(oneToManyTests)('%s', (test) => {
expect(convertMultiple(test.command, test.managers)).toEqual(test.result)
})
})

describe("Many to One", () => {
it.each(manyToOneTests)('%s', (test) => {
expect(convertMultiple(test.command, test.managers)).toEqual(test.result)
})
})
// many to one
// many to many
})

0 comments on commit 4984af0

Please sign in to comment.