Skip to content

Add Increment and Decrement Functions #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 9, 2025
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Before submitting a pull request, please make sure the following is done:
- Fork the repository and create your feature branch from dev.
- Run `npm install` to have all dependencies.
- To start development run `npm run test:watch`.
- Write tests in `src/<scope>/<name>.test.ts` and implementation in `src/<scope>/<name>.ts`.
- Write tests in `src/<scope>/<name>.spec.ts` and implementation in `src/<scope>/<name>.ts`.
- Add the documentation page to the `docs/<scope>/<function>.mdx` and update `docs/<scope>/_meta.json` file.
- Ensure everything is ok `npm run verify`.

Expand Down
2 changes: 2 additions & 0 deletions docs/pages/number/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"clamp": "clamp",
"divide": "divide",
"inc": "inc",
"dec": "dec",
"fallback-number": "fallbackNumber",
"is-in-range": "isInRange",
"is-negative": "isNegative",
Expand Down
22 changes: 22 additions & 0 deletions docs/pages/number/dec.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# dec

Decrements the given number by 1. Useful for counters and mathematical operations.

### Import

```typescript copy
import { dec } from '@fullstacksjs/toolbox';
```

### Signature

```typescript copy
function dec(n: number): number {}
```

### Examples

```typescript copy
dec(3) // 2
dec(5) // 4
```
22 changes: 22 additions & 0 deletions docs/pages/number/inc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# inc

Increments the given number by 1. Useful for counters and mathematical operations.

### Import

```typescript copy
import { inc } from '@fullstacksjs/toolbox';
```

### Signature

```typescript copy
function inc(n: number): number {}
```

### Examples

```typescript copy
inc(3) // 4
inc(5) // 6
```
8 changes: 8 additions & 0 deletions src/number/dec.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { dec } from './dec';

describe('dec', () => {
it('should decrement by 1', () => {
expect(dec(2)).toBe(1);
expect(dec(5)).toBe(4);
});
});
14 changes: 14 additions & 0 deletions src/number/dec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Decrements a number by 1.
*
* @param {number} n - The number to decrement.
* @returns {number} The decremented number.
*
* @example
* dec(3) // 2
* dec(5) // 4
*/

export function dec(n: number): number {
return n - 1;
}
8 changes: 8 additions & 0 deletions src/number/inc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { inc } from './inc';

describe('inc', () => {
it('should increment by 1', () => {
expect(inc(0)).toBe(1);
expect(inc(5)).toBe(6);
});
});
14 changes: 14 additions & 0 deletions src/number/inc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Increments a number by 1.
*
* @param {number} n - The number to increment.
* @returns {number} The incremented number.
*
* @example
* inc(3) // 4
* inc(5) // 6
*/

export function inc(n: number): number {
return n + 1;
}
2 changes: 2 additions & 0 deletions src/number/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export { clamp } from './clamp.ts';
export { dec } from './dec.ts';
export { divide } from './divide.ts';
export { fallbackNumber } from './fallbackNumber.ts';
export { inc } from './inc.ts';
export { isInRange } from './isInRange.ts';
export { isNegative } from './isNegative.ts';
export { isPositive } from './isPositive.ts';
Expand Down
Loading