Skip to content

Commit

Permalink
refactor: prepare for initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
joelgnansounou committed Sep 1, 2024
1 parent 67afd37 commit eaae0df
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": true,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
node-version: '20.x'

- name: Install dependencies
run: npm install
Expand Down
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BigNumberArrUtils } from 'bignumber-arr-utils';

## Example Usage

### ***Creating an Instance***
### **_Creating an Instance_**

Creates an instance of `BigNumberArrUtils` and initializes the array with valid `BigNumber` instances.

Expand All @@ -32,16 +32,16 @@ Creates an instance of `BigNumberArrUtils` and initializes the array with valid
const arr = new BigNumberArrUtils(1, '2', new BigNumber(3));
```

### ***Getting the items on the array***
### **_Getting the items on the array_**

Returns the list of BigNumber instances in the array.

```typescript
const arr = new BigNumberArrUtils(1, '2', new BigNumber(3));
console.log(arr.items); // [BigNumber(1), BigNumber(2), BigNumber(3)]
console.log(arr.items); // [BigNumber(1), BigNumber(2), BigNumber(3)]
```

### ***Adding Items***
### **_Adding Items_**

Adds a new BigNumber instance to the array. Returns false if the given input is not a valid BigNumber.Value. Returns true if the new BigNumber instance has been added to the array.

Expand All @@ -50,47 +50,49 @@ Adds a new BigNumber instance to the array. Returns false if the given input is

```typescript
const arr = new BigNumberArrUtils();
console.log(arr.add(-0.8)); // true
console.log(arr.add('abc')); // false
console.log(arr.add(3e+18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(3e+18)]
console.log(arr.add(-0.8)); // true
console.log(arr.add('abc')); // false
console.log(arr.add(3e18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(3e+18)]
```

### ***Removing Items***
### **_Removing Items_**

Removes an instance of BigNumber from the array. Returns false if the given input is not found in the array. Returns true if the BigNumber has been removed from the array.

- **Parameters:**
- `n` - The value to be removed from the array.

```typescript
const arr = new BigNumberArrUtils(-0.8, 3e+18, 1.0000000000000001);
console.log(arr.remove(-1)); // false
console.log(arr.remove(3e+18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(1.0000000000000001)]
const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.remove(-1)); // false
console.log(arr.remove(3e18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(1.0000000000000001)]
```

### ***Calculating the Sum***
### **_Calculating the Sum_**

Returns the sum of all BigNumber instances in the array.

```typescript
const arr = new BigNumberArrUtils(-0.8, 3e+18, 1.0000000000000001);
console.log(arr.sum().toString()); // "3000000000000000001.2"
const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.sum().toString()); // "3000000000000000001.2"
```

# Contributing
## Contributing

If you want to contribute to this project, please follow these steps:

1. Fork the repository.
2. Create a new branch (git checkout -b feature/your-feature).
3. Commit your changes (git commit -am 'Add some feature').
4. Push to the branch (git push origin feature/your-feature).
5. Create a new Pull Request.
<ol>
<li>Fork the repository.</li>
<li>Create a new branch (git checkout -b feature/your-feature).</li>
<li>Commit your changes (git commit -am 'Add some feature').</li>
<li>Push to the branch (git push origin feature/your-feature).</li>
<li>Create a new Pull Request.</li>
</ol>

## Licence

The MIT Licence.

See [LICENCE](https://github.com/joelgnansounou/bignumber-arr-utils/tree/master?tab=MIT-1-ov-file).
See [LICENCE](https://github.com/joelgnansounou/bignumber-arr-utils/tree/master?tab=MIT-1-ov-file).
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"type": "module",
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.4",
"@types/bignumber.js": "^5.0.0",
"@changesets/cli": "^2.27.7",
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
Expand All @@ -46,6 +46,7 @@
"check-exports": "attw --pack .",
"test": "vitest run",
"dev": "vitest",
"ci": "npm run build && npm run prettier:check-format && npm run check-exports && npm run test"
"ci": "npm run build && npm run prettier:check-format && npm run check-exports && npm run test",
"local-release": "npm run ci && changeset version && changeset publish"
}
}
14 changes: 7 additions & 7 deletions src/bignumber-arr-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,37 +194,37 @@ describe('BigNumberArrUtils', () => {
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber(0));
});

test('should return the single item if array has only one item', () => {
const bigNumberArrUtils = new BigNumberArrUtils(5);
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber(5));
});

test('should correctly sum multiple items', () => {
const bigNumberArrUtils = new BigNumberArrUtils(1, 2, 3, 4, 5);
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber(15));
});

test('should correctly sum items with decimal values', () => {
const bigNumberArrUtils = new BigNumberArrUtils('1.5', '2.5', '3.5');
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber('7.5'));
});

test('should correctly sum negative numbers', () => {
const bigNumberArrUtils = new BigNumberArrUtils(-1, -2, -3, -4, -5);
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber(-15));
});

test('should correctly sum a mix of positive and negative numbers', () => {
const bigNumberArrUtils = new BigNumberArrUtils(-1, 2, -3, 4, -5);
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber(-3));
});

test('should correctly sum items with large values', () => {
const bigNumberArrUtils = new BigNumberArrUtils(
'1e+18',
Expand All @@ -234,7 +234,7 @@ describe('BigNumberArrUtils', () => {
const result = bigNumberArrUtils.sum();
expect(result).toStrictEqual(new BigNumber('6e+18'));
});

test('should correctly sum items with high precision decimal values', () => {
const bigNumberArrUtils = new BigNumberArrUtils(
'1.0000000000000001',
Expand Down

0 comments on commit eaae0df

Please sign in to comment.