Skip to content

Commit

Permalink
Bump smart-round to newest deps and TS (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
gndelia authored Feb 21, 2025
1 parent 818f72a commit 3002b91
Show file tree
Hide file tree
Showing 25 changed files with 8,542 additions and 6,772 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

23 changes: 20 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"extends": [
"bloq"
]
"extends": ["bloq", "prettier"],
"ignorePatterns": ["_cjs/*", "_esm/*", "_types/*"],
"overrides": [
{
"extends": ["bloq/typescript", "prettier"],
"files": ["src/**/*.ts"]
},
{
"extends": ["bloq/markdown"],
"files": ["*.md"]
},
{
"extends": ["bloq/vitest"],
"files": ["*.spec.ts"]
}
],
"parserOptions": {
"sourceType": "module"
},
"root": true
}
15 changes: 15 additions & 0 deletions .github/workflows/js-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: JS Checks

on:
pull_request:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
js-checks:
uses: bloq/actions/.github/workflows/js-checks.yml@v1.5.0
with:
node-versions: '["18", "20", "22"]'
14 changes: 14 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: NPM Publish

on:
release:
types:
- published

jobs:
npm-publish:
permissions:
contents: read
id-token: write
secrets: inherit
uses: bloq/actions/.github/workflows/npm-publish.yml@v1.5.0
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
_cjs
_esm
_types
.eslintcache
.nyc_output
.vscode
coverage
es5
node_modules
npm-debug.log
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"quoteProps": "consistent"
}
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

27 changes: 14 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
The MIT License (MIT)
MIT License

Copyright (c) Autonomous Software
Copyright (c) 2018-2024 Bloq, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 16 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# smart-round

[![Build Status](https://travis-ci.com/autonomoussoftware/smart-round.svg?branch=master)](https://travis-ci.com/autonomoussoftware/smart-round)
[![Code Style](https://img.shields.io/badge/code%20style-bloq-0063a6.svg)](https://github.com/bloq/eslint-config-bloq)
[![Known Vulnerabilities](https://snyk.io/test/github/autonomoussoftware/smart-round/badge.svg?targetFile=package.json)](https://snyk.io/test/github/autonomoussoftware/smart-round:package.json)
![NPM Version](https://img.shields.io/npm/v/smart-round)

Round big numbers with arbitrary precision
Round big numbers with arbitrary precision.

## Installation

```bash
$ npm install --save smart-round
```sh
npm install --save smart-round
```

## Usage
Expand All @@ -24,34 +22,25 @@ The module exports a function that let you initialize a rounder function.

### `rounder(number, shouldFormat)`

`number`: The value to round as any type supported by [`bignumber.js`](https://github.com/MikeMcl/bignumber.js) package.
`shouldFormat`: Whether the returned string should be formatted or not, using [`accounting`](https://github.com/openexchangerates/accounting.js) package.
`input`: The value to round. Accepts any type supported by [`bignumber.js`](https://github.com/MikeMcl/bignumber.js) package.
`options`: An optional object to customize the formatting:

- `options.locale`: Optional. Format used to format when `options.shouldFormat`is true. Defaults to `en-US`.
- `options.roundingMode` Optional. Specifies the rounding method. Accepted values: `round-up`, `round-down` ,`round-ceil`, `round-floor`, `round-half-up`, `round-half-down`, `round-half-even`, `round-half-ceil`, `round-half-floor`. Defaults to `round-half-up`.
- `options.shouldFormat`: Optional. Defaults to `false`. Indicates whether the string should be formatted using [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat),

## Example

```js
const smartRound = require('smart-round')
import { smartRound } from "smart-round";

const rounder1 = smartRound(6, 0, 6)
const rounder1 = smartRound(6, 0, 6);

console.log(rounder1('1234.56789', false)) // '1234.57'
console.log(rounder1('1234.56789', true)) // '1,234.56'
console.log(rounder1("1234.56789")); // '1234.57'
console.log(rounder1("1234.56789", { shouldFormat: true })); // '1,234.56'

const rounder2 = smartRound(4, 2, 6)
const rounder2 = smartRound(4, 2, 6);

console.log(rounder2('1234', true)) // '1,234.00'
console.log(rounder2('0.000123456', true)) // '0.000123'
console.log(rounder2("1234", { shouldFormat: true })); // '1,234.00'
console.log(rounder2("0.000123456", { shouldFormat: true })); // '0.000123'
```

### ES5 support

A transpiled version is available in `es5/index.js`. To use that specific version, this syntax is also supported:

```js
var smartRound = require('smart-round/es5');
```

## License

MIT
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
extends: ["bloq"],
};
8 changes: 8 additions & 0 deletions knip.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @type {import('knip').KnipConfig}
*/
const config = {
ignoreDependencies: ["@vitest/coverage-v8", "eslint-config-prettier"],
};

export default config;
9 changes: 9 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const formatFiles = "prettier --ignore-unknown --write";
const lintFiles = "eslint --cache --fix --quiet";
const sortPackageJson = "better-sort-package-json";

export default {
"!(*.{js,json,md,ts,tsx,yml}|package.json)": [formatFiles],
"*.{js,md,ts,tsx,yml}": [lintFiles, formatFiles],
"package.json": [sortPackageJson, formatFiles],
};
Loading

0 comments on commit 3002b91

Please sign in to comment.