Thank you for your interest in contributing to filesize.js! This document outlines the process for contributing to the project.
- Getting Started
- Reporting Issues
- Development Workflow
- Testing
- Code Style
- Commit Messages
- Pull Request Process
- License
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/filesize.js.git cd filesize.js - Install dependencies:
npm install
- Start development mode:
npm run dev
Before reporting an issue, please search existing issues to avoid duplicates.
When creating a new issue, include:
- A clear, descriptive title
- Steps to reproduce the problem
- Expected vs. actual behavior
- Environment details (Node.js version, OS, browser)
- Code samples if applicable
filesize.js/
├── src/
│ ├── filesize.js # Main implementation
│ ├── helpers.js # Helper functions
│ └── constants.js # Constants and lookup tables
├── tests/
│ └── unit/ # Unit tests
├── dist/ # Built distributions (generated)
└── types/ # TypeScript definitions
npm run build # Build all distributions
npm run build:watch # Watch mode for development
npm run build:analyze # Analyze bundle sizesdist/filesize.cjs- CommonJSdist/filesize.js- ES Moduledist/filesize.min.js- Minified ES Moduledist/filesize.umd.js- UMD (browser)dist/filesize.umd.min.js- Minified UMD
npm test # Run all tests (lint + node:test)
npm run test:watch # Live test watching- 100% test coverage is required for all changes
- Coverage includes: statements, branches, functions, and lines
- Run with coverage:
npm test
Tests use Node.js built-in test runner (node:test):
import assert from 'node:assert';
import { describe, it } from 'node:test';
import { filesize } from '../../src/filesize.js';
describe('Feature', () => {
it('should do something', () => {
const result = filesize(1024);
assert.strictEqual(result, '1.02 kB');
});
});------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
------------|---------|----------|---------|---------|-------------------
We use oxlint (Rust-based, fast):
npm run lint # Check code style
npm run lint:fix # Auto-fix issuesWe use oxfmt (Rust-based, fast):
npm run format:fix # Format code- JSDoc: Use JSDoc standard for all functions and classes
- Naming:
- Functions: camelCase (
handleZeroValue,applyPrecisionHandling) - Constants: UPPER_SNAKE_CASE (
IEC,JEDEC,BINARY_POWERS)
- Functions: camelCase (
- Imports: Group by source, alphabetize
- Principles: DRY, KISS, YAGNI, SOLID
- Security: OWASP best practices
/**
* Description
* @param {type} param - Description
* @returns {type} Description
*/
export function functionName(param) {
// Implementation
}
// Constants
export const CONSTANT_NAME = 'value';
// Imports: group by source, alphabetize
import {
ARRAY,
BIT,
BYTE
} from './constants.js';
import {
helperFunction
} from './helpers.js';We follow Conventional Commits:
<type>(<scope>): <description>
[optional body]
[optional footer]
feat: New featurefix: Bug fixdocs: Documentationrefactor: Code restructuringbuild: Build system changestest: Test additions/fixeschore: Maintenance tasks
feat: add precision option for significant digits
fix: correct bits auto-increment with forced exponent
docs: update README with TypeScript examples
refactor: simplify exponent auto-detection logic
build: update rollup configuration
test: add coverage for NaN exponent edge case
-
Create a branch:
git checkout -b feature/your-feature-name
-
Make your changes and ensure:
- All tests pass (
npm test) - 100% test coverage is maintained
- Code is formatted (
npm run format:fix) - No linting errors (
npm run lint)
- All tests pass (
-
Build the project:
npm run build
-
Commit your changes:
git commit -m "type: description" -
Push to your fork:
git push origin feature/your-feature-name
-
Open a Pull Request:
- Provide a clear title and description
- Reference any related issues
- Include test coverage for changes
- Tests pass (
npm test) - 100% test coverage maintained
- Code is formatted
- No linting errors
- Documentation updated (if applicable)
- Build successful (
npm run build)
By contributing to filesize.js, you agree that your contributions will be licensed under the BSD-3 license.
Thank you for contributing to filesize.js!