https://github.com/ialopezg/commonjs
Common Utilities
https://github.com/ialopezg/commonjs
Last synced: 27 days ago
JSON representation
Common Utilities
- Host: GitHub
- URL: https://github.com/ialopezg/commonjs
- Owner: ialopezg
- License: mit
- Created: 2022-05-07T03:31:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-11T17:49:29.000Z (2 months ago)
- Last Synced: 2025-04-19T05:16:33.465Z (about 1 month ago)
- Language: TypeScript
- Size: 1.42 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# CommonJS
> A collection of utility functions for handling strings, numbers, dates, objects, booleans, paths,
> and more.[](https://www.npmjs.com/package/@ialopezg/commonjs)
[](https://coveralls.io/github/ialopezg/CommonJS?branch=main)
[](http://standardjs.com)

[](https://bundlephobia.com/result?p=my-awesome-lib)## Installation
```bash
npm install @ialopezg/commonjs
```## Usage
```javascript
import '@ialopezg/commonjs';// strings
const cardNumber = '1234-5678-9098-7654';
const part1 = (cardNumber.slice(0, 4) + '-').padWithChar('*', 9, 'right');
const part2 = ('-' + cardNumber.slice(-4)).padWithChar('*', 9, 'left');
console.log([part1, part2].join('-')); // Will produce 1234-****-****-7654// numbers
console.log('41'.padWithChar('*', 4, 'right')); // will produce 42**
console.log((42).padWithChar('0', 4, 'left')); // will produce 0042// dates
console.log(new Date(2010, 1, 14, 15, 25, 50, 125).humanize('w, l D1 Y, h:m2:s2 a')); // will procuce Monday, February 1st 2025, 3:30:00 pm
```## Documentation
The library is organized into several helper modules. Click on the links below for detailed usage
and examples:| Helper | Description | Extension |
|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|:---------:|
| [Date](docs/core/date/README.md) | Extends native Date and DateConstructor type with extra functionalities such as: `humanize`, `humanizeTimeDiff`, `relativeTime`, `timeDiff` | ✓ |
| [Number](docs/helpers/number.md) | Extends native Number and NumberConstructor type with extra functionalities such as: `getOrdinal`, `padWithChar` | ✓ |
| [String](docs/helpers/string.md) | Extends native string type with extra functionalities such as: `padWitchChar` | ✓ |## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
## License
This project is under [MIT License](LICENSE).