Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These are supported funding model platforms

github: [sindresorhus]
tidelift: npm/pretty-bytes
custom: https://sindresorhus.com/donate
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug Report
about: Create a report to help improve the project
title: "[BUG] "
labels: bug
assignees: ''
---

## Description
<!-- A clear and concise description of what the bug is -->

## Reproduction Steps
<!-- Steps to reproduce the behavior -->

## Expected Behavior
<!-- A clear and concise description of what you expected to happen -->

## Environment
- Node.js version:
- pretty-bytes version:
- OS:

## Additional Context
<!-- Add any other context about the problem here -->
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Thank you for contributing to pretty-bytes! -->

## Description
<!-- Briefly describe what this PR does -->

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation
- [ ] Refactoring
- [ ] Other (please describe):

## Checklist
- [ ] I have read the CONTRIBUTING.md file
- [ ] My code follows the code style of this project
- [ ] I have added tests that prove my fix is effective or my feature works
- [ ] New and existing tests pass locally with my changes
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
versioning-strategy: increase
groups:
dev-dependencies:
dependency-type: "development"
update-types:
- "minor"
- "patch"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 10
32 changes: 28 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: CI
on:
- push
- pull_request
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read

jobs:
test:
name: Node.js ${{ matrix.node-version }}
Expand All @@ -17,5 +23,23 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test

coverage:
runs-on: ubuntu-latest
needs: test
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run coverage
run: npm run coverage
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
yarn.lock
coverage
package-lock.json
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package-lock=false
registry=https://registry.npmjs.org/
package-lock=true
save-exact=true
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing

Thank you for considering contributing to pretty-bytes!

## Development

1. Fork this repository and clone it to your local machine
2. Install dependencies with `npm install`
3. Make your changes
4. Run tests with `npm test`
5. Submit a pull request

## Pull Request Guidelines

- Follow the existing code style and formatting (using XO)
- Add or update tests for your changes
- Ensure all tests pass locally before submitting
- Keep your PR focused on a single topic
- Update documentation if necessary

## Testing

We use AVA for testing. Run the test suite with:

```sh
npm test
```

This will run the linter (XO), tests (AVA) and TypeScript definition tests (TSD).

## Release Process

The package release is handled by the maintainers using:

1. Update version in package.json
2. Create a Git tag
3. Push to GitHub
4. Publish to npm
37 changes: 37 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import {expectType} from 'tsd';
import prettyBytes from './index.js';

// Basic type tests
expectType<string>(prettyBytes(1337));
expectType<string>(prettyBytes(42, {signed: true}));
expectType<string>(prettyBytes(1337, {locale: 'de'}));
expectType<string>(prettyBytes(1337, {locale: true}));
expectType<string>(prettyBytes(1337, {bits: true}));
expectType<string>(prettyBytes(1337, {binary: true}));
expectType<string>(prettyBytes(1337, {space: true}));

// Advanced type tests
expectType<string>(prettyBytes(BigInt(9_007_199_254_740_991))); // Max safe integer as BigInt
expectType<string>(prettyBytes(-1337));
expectType<string>(prettyBytes(0));

// Options combinations
expectType<string>(prettyBytes(1337, {
bits: true,
binary: true,
signed: true,
space: false,
}));

// Locale options
expectType<string>(prettyBytes(1337, {locale: ['fr', 'en']}));

// Precision options
expectType<string>(prettyBytes(1337, {
minimumFractionDigits: 2,
maximumFractionDigits: 4,
}));

// All options combined
expectType<string>(prettyBytes(1337, {
bits: true,
binary: true,
signed: true,
space: false,
locale: 'de',
minimumFractionDigits: 1,
maximumFractionDigits: 3,
}));

// Note: Runtime error checks are performed in test.js
// Type safety is enforced by TypeScript compiler
Loading