-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expand package.json files in npm.dependencies (#914)
* refactor: remove always-true checks * feat: expand package.json files in npm.dependencies * feat: introduce human readable byte units * feat: dislay human readable units
- Loading branch information
1 parent
77a9777
commit a493cce
Showing
4 changed files
with
101 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package human | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
func Bytes(b int64) string { | ||
sizes := []string{"B", "kB", "MB", "GB"} | ||
e := math.Floor(math.Log(float64(b)) / math.Log(1000)) | ||
suffix := sizes[int(math.Min(e, float64(len(sizes)-1)))] | ||
val := float64(b) / math.Pow(1000, e) | ||
return fmt.Sprintf("%.0f %s", val, suffix) | ||
} |
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,18 @@ | ||
package human | ||
|
||
import "fmt" | ||
|
||
func ExampleBytes_gigaByte() { | ||
fmt.Println(Bytes(3000000000)) | ||
// Output: 3 GB | ||
} | ||
|
||
func ExampleBytes_megaByte() { | ||
fmt.Println(Bytes(82854982)) | ||
// Output: 83 MB | ||
} | ||
|
||
func ExampleBytes_kiloByte() { | ||
fmt.Println(Bytes(828549)) | ||
// Output: 829 kB | ||
} |
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,33 @@ | ||
package zip | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"gotest.tools/v3/fs" | ||
) | ||
|
||
func TestExpandDependencies(t *testing.T) { | ||
dir := fs.NewDir(t, "test-project", | ||
fs.WithFile("package.json", `{ | ||
"dependencies": { | ||
"i-am-regular": "0.1.2" | ||
}, | ||
"devDependencies": { | ||
"i-am-dev": "0.1.2" | ||
} | ||
} | ||
`)) | ||
defer dir.Remove() | ||
|
||
deps := []string{"i-am-extra", "package.json"} | ||
expanded, err := ExpandDependencies(dir.Path(), deps) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
expected := []string{"i-am-extra", "i-am-regular", "i-am-dev"} | ||
if !cmp.Equal(expected, expanded) { | ||
t.Errorf("unexpected expanded dependencies: %s", cmp.Diff(expected, expanded)) | ||
} | ||
} |