Skip to content

Commit

Permalink
improved sortBy
Browse files Browse the repository at this point in the history
  • Loading branch information
Breck Yunits authored and Breck Yunits committed May 10, 2024
1 parent 1e0e499 commit 596fbcb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "scroll-cli",
"version": "85.5.0",
"version": "85.6.0",
"description": "A language for bloggers. A curated collection of tools for thoughts.",
"main": "scroll.js",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Expand Up @@ -4,6 +4,9 @@ title Scroll Release Notes

thinColumns

# 85.6.0 5/10/2024
- 🎉 `sortBy` can now sort on multiple columns and handle asc/desc

# 85.5.0 5/10/2024
- 🎉 `writeConcepts` and `writeMeasures` can now take multiple filenames in one line and also include a `sortBy` condition.

Expand Down
12 changes: 10 additions & 2 deletions scroll.js
Expand Up @@ -300,15 +300,23 @@ class ScrollFile {
return tree.toString()
}

makeOrderByArr(str) {
const part1 = str.split(" ")
const part2 = part1.map(col => (col.startsWith("-") ? "desc" : "asc"))
return [part1.map(col => col.replace(/^\-/, "")), part2]
}

compileConcepts(format = "csv", sortBy = "") {
if (!sortBy) return this._compileArray(format, this.concepts)
return this._compileArray(format, lodash.sortBy(this.concepts, sortBy))
const orderBy = this.makeOrderByArr(sortBy)
return this._compileArray(format, lodash.orderBy(this.concepts, orderBy[0], orderBy[1]))
}

compileMeasures(format = "csv", sortBy = "") {
const withStats = addMeasureStats(this.concepts, this.measures)
if (!sortBy) return this._compileArray(format, withStats)
return this._compileArray(format, lodash.sortBy(withStats, sortBy))
const orderBy = this.makeOrderByArr(sortBy)
return this._compileArray(format, lodash.orderBy(withStats, orderBy[0], orderBy[1]))
}

evalVariables(code, originalScrollCode) {
Expand Down

0 comments on commit 596fbcb

Please sign in to comment.