diff options
author | Florrie <towerofnix@gmail.com> | 2018-12-15 11:50:46 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-12-15 11:50:46 -0400 |
commit | c4fdc7792286090c631f29ebac66a813ecba7ddc (patch) | |
tree | 1cfbc65578f8fed7edd46467400a9f54f0d7f68a /playlist-utils.js | |
parent | 2e8038264af755d10f19af39461c2880ed48dc73 (diff) |
Label showing # of items / total items in menu
Diffstat (limited to 'playlist-utils.js')
-rw-r--r-- | playlist-utils.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/playlist-utils.js b/playlist-utils.js index f20ec98..64c1df4 100644 --- a/playlist-utils.js +++ b/playlist-utils.js @@ -175,6 +175,19 @@ function flattenGrouplike(grouplike) { } } +function countTotalItems(grouplike) { + // Returns the total number of items in a grouplike, including items in any + // descendant groups. Basically the same as flattenGrouplike().items.length. + + return grouplike.items.map(item => { + if (isGroup(item)) { + return countTotalItems(item) + } else { + return 1 + } + }).reduce((a, b) => a + b, 0) +} + function collectGrouplikeChildren(grouplike, filter = null) { // Collects all descendants of a grouplike into a single flat array. // Can be passed a filter function, which will decide whether or not to add @@ -492,7 +505,7 @@ module.exports = { updatePlaylistFormat, updateGroupFormat, updateTrackFormat, cloneGrouplike, filterTracks, - flattenGrouplike, + flattenGrouplike, countTotalItems, partiallyFlattenGrouplike, collapseGrouplike, filterGrouplikeByProperty, filterPlaylistByPathString, filterGrouplikeByPath, |