-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
184 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import _select from '../engine/select'; | ||
import resolve from '../helpers/selection'; | ||
|
||
export default function(table, columns) { | ||
const map = new Map(); | ||
table.columnNames(x => (map.set(x, x), 0)); | ||
return _select(table, resolve(table, columns, map)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import tape from 'tape'; | ||
import tableEqual from '../table-equal'; | ||
import { table } from '../../src'; | ||
|
||
tape('rename renames columns', t => { | ||
const data = { | ||
a: [1, 3, 5, 7], | ||
b: [2, 4, 6, 8], | ||
c: 'abcd'.split('') | ||
}; | ||
|
||
tableEqual(t, | ||
table(data).rename({ a: 'z'}), | ||
{ z: data.a, b: data.b, c: data.c }, | ||
'renamed data, single column' | ||
); | ||
|
||
tableEqual(t, | ||
table(data).rename({ a: 'z', b: 'y' }), | ||
{ z: data.a, y: data.b, c: data.c }, | ||
'renamed data, multiple columns' | ||
); | ||
|
||
t.deepEqual( | ||
table(data).rename({ a: 'z', c: 'x' }).columnNames(), | ||
['z', 'b', 'x'], | ||
'renamed data, preserves order' | ||
); | ||
|
||
tableEqual(t, | ||
table(data).rename('a', 'b'), | ||
data, | ||
'renamed data, no rename' | ||
); | ||
|
||
tableEqual(t, | ||
table(data).rename(), | ||
data, | ||
'renamed data, no arguments' | ||
); | ||
|
||
tableEqual(t, | ||
table(data).rename({ a: 'z'}, { c: 'x' }), | ||
{ z: data.a, b: data.b, x: data.c }, | ||
'renamed data, multiple arguments' | ||
); | ||
|
||
t.end(); | ||
}); |