Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82788205
rows.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 13, 10:41
Size
1 KB
Mime Type
text/x-c++
Expires
Sun, Sep 15, 10:41 (2 d)
Engine
blob
Format
Raw Data
Handle
20753677
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
rows.js
View Options
const
arrayify
=
require
(
'array-back'
)
const
Cell
=
require
(
'./cell'
)
const
t
=
require
(
'typical'
)
/**
*
*/
class
Rows
{
constructor
(
rows
,
columns
)
{
this
.
list
=
[]
this
.
load
(
rows
,
columns
)
}
load
(
rows
,
columns
)
{
arrayify
(
rows
).
forEach
(
row
=>
{
this
.
list
.
push
(
new
Map
(
objectToIterable
(
row
,
columns
)))
})
}
static
removeEmptyColumns
(
data
)
{
const
distinctColumnNames
=
data
.
reduce
((
columnNames
,
row
)
=>
{
Object
.
keys
(
row
).
forEach
(
key
=>
{
if
(
columnNames
.
indexOf
(
key
)
===
-
1
)
columnNames
.
push
(
key
)
})
return
columnNames
},
[])
const
emptyColumns
=
distinctColumnNames
.
filter
(
columnName
=>
{
const
hasValue
=
data
.
some
(
row
=>
{
const
value
=
row
[
columnName
]
return
(
t
.
isDefined
(
value
)
&&
typeof
value
!==
'string'
)
||
(
typeof
value
===
'string'
&&
/\S+/
.
test
(
value
))
})
return
!
hasValue
})
return
data
.
map
(
row
=>
{
emptyColumns
.
forEach
(
emptyCol
=>
delete
row
[
emptyCol
])
return
row
})
}
}
function
objectToIterable
(
row
,
columns
)
{
return
columns
.
list
.
map
(
column
=>
{
return
[
column
,
new
Cell
(
row
[
column
.
name
],
column
)
]
})
}
/**
* @module rows
*/
module
.
exports
=
Rows
Event Timeline
Log In to Comment