Skip to content

Commit

Permalink
Merge branch 'release/v0.16.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Jan 23, 2024
2 parents 0a7fa1a + 11fc690 commit db88e7b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.16.5",
"version": "0.16.6",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
16 changes: 8 additions & 8 deletions src/common/data/format.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { formatBytesToHuman, formatBytesToHumanBase1000, formatSecondsToTime } from './format'
import { formatBytesToHumanBase1000, formatBytesToHumanBase1024, formatSecondsToTime } from './format'

describe('format.spec', () => {
it('should format bytes in 1024 steps', async () => {
expect(formatBytesToHuman(123)).toMatchInlineSnapshot('"123 bytes"')
expect(formatBytesToHuman(16 * 1024)).toMatchInlineSnapshot('"16.00 KiB"')
expect(formatBytesToHuman(16 * 1024 * 1024)).toMatchInlineSnapshot('"16.00 MiB"')
expect(formatBytesToHuman(16 * 1024 + 123)).toMatchInlineSnapshot('"16.12 KiB"')
expect(formatBytesToHuman(16 * 1024 + 123, 0)).toMatchInlineSnapshot('"16 KiB"')
expect(formatBytesToHuman(-123)).toMatchInlineSnapshot('"0 bytes"')
expect(formatBytesToHuman(0)).toMatchInlineSnapshot('"0 bytes"')
expect(formatBytesToHumanBase1024(123)).toMatchInlineSnapshot('"123 bytes"')
expect(formatBytesToHumanBase1024(16 * 1024)).toMatchInlineSnapshot('"16.00 KiB"')
expect(formatBytesToHumanBase1024(16 * 1024 * 1024)).toMatchInlineSnapshot('"16.00 MiB"')
expect(formatBytesToHumanBase1024(16 * 1024 + 123)).toMatchInlineSnapshot('"16.12 KiB"')
expect(formatBytesToHumanBase1024(16 * 1024 + 123, 0)).toMatchInlineSnapshot('"16 KiB"')
expect(formatBytesToHumanBase1024(-123)).toMatchInlineSnapshot('"0 bytes"')
expect(formatBytesToHumanBase1024(0)).toMatchInlineSnapshot('"0 bytes"')
})

it('should format bytes in 1000 steps', async () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export function formatBytesToHumanBase1024(bytes: number, decimals = 2) {
return (`${(1 / h).toFixed(i > 0 ? decimals : 0).toLocaleString()} ${units[i]}`)
}

export const formatBytesToHuman = formatBytesToHumanBase1024

/** Just a simple yet fast helper. Alternatively you may use Intl formatters http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat */
export function formatBytesToHumanBase1000(bytes: number, decimals = 2) {
// https://en.wikipedia.org/wiki/Orders_of_magnitude_(data)
Expand Down
1 change: 1 addition & 0 deletions src/common/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './day'
export * from './decimal'
export * from './deep'
export * from './diff'
export * from './format'
export * from './html'
export * from './is'
export * from './json'
Expand Down

0 comments on commit db88e7b

Please sign in to comment.