Skip to content

Commit

Permalink
Merge pull request #514 from swrlab/dev/update-1.1.1
Browse files Browse the repository at this point in the history
Update 1.1.1
  • Loading branch information
rafaelmaeuer authored Feb 13, 2023
2 parents e6016d6 + da0a82d commit 2e6d9bf
Show file tree
Hide file tree
Showing 16 changed files with 732 additions and 440 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ name: Linter

on:
pull_request:
branches-ignore:
- dependabot/**
workflow_call:
inputs:
install-all:
description: 'Install dependencies using `install-all`'
description: "Install dependencies using `install-all`"
required: false
type: boolean
default: false
generate-keys:
description: 'Whether to run command for dummy key generation'
description: "Whether to run command for dummy key generation"
required: false
type: boolean
default: false
log-level:
description: 'Which log level to use for `super-linter`'
description: "Which log level to use for `super-linter`"
required: false
type: string
default: 'VERBOSE'
default: "VERBOSE"
validate-all-codebase:
description: 'Whether to run validation on all files'
description: "Whether to run validation on all files"
required: false
type: boolean
default: true
Expand Down Expand Up @@ -121,7 +123,7 @@ env:
jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest-16-cores
runs-on: ubuntu-latest-4-cores
timeout-minutes: 90
permissions:
contents: read
Expand All @@ -137,15 +139,15 @@ jobs:
with:
persist-credentials: false
repository: swrlab/node-utils
ref: 'main'
path: '.utils'
ref: "main"
path: ".utils"

- name: ⛺️ Install Node.js
- name: 🏗 Install Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
cache: "yarn"
cache-dependency-path: "**/yarn.lock"

- name: 📦 Install Dependencies (if `install:all`)
if: inputs.install-all == true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: 👀 Checkout Code
uses: actions/checkout@v3

- name: ⛺️ Install Node.js
- name: 🏗 Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ by [**SWR Audio Lab**](https://lab.swr.de/)

## Changelog

- 2023-02-13 - v1.1.1
- feat: add `addTrailingZeros` to numbers package
- feat: add `addLeadingZero` to numbers package
- feat: add `getDiff` to numbers package
- feat: add `getAverage` to numbers package
- feat: add `getSum` to numbers package
- feat: add `getRandomInRange` to numbers package
- feat: add `roundTo` to numbers package

- 2022-12-19 - v1.1.0
- feat: add test workflow to github/actions
- feat: add helpers package (with `sleep` function)
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swrlab/utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "Wrapping common SWR Audio Lab utils",
"main": "./src/index.js",
"engines": {
Expand All @@ -23,22 +23,22 @@
"license": "MIT",
"private": false,
"dependencies": {
"@google-cloud/storage": "^6.8.0",
"@google-cloud/storage": "^6.9.2",
"abort-controller": "^3.0.0",
"aws-sdk": "^2.1277.0",
"aws-sdk": "^2.1313.0",
"chai": "^4.3.7",
"node-crc": "swrlab/node-crc#v2.1.0",
"undici": "^5.14.0",
"undici": "^5.19.1",
"uuid": "9.0.0"
},
"devDependencies": {
"@swrlab/eslint-plugin-swr": "^0.2.0",
"@swrlab/swr-prettier-config": "^0.2.0",
"dotenv": "^16.0.3",
"eslint": "^8.30.0",
"eslint": "^8.34.0",
"eslint-plugin-json": "^3.1.0",
"mocha": "^10.2.0",
"prettier": "^2.8.1"
"prettier": "^2.8.4"
},
"prettier": "@swrlab/swr-prettier-config"
}
168 changes: 167 additions & 1 deletion packages/numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Common number and math helpers.

- [SWR Audio Lab / Numbers](#swr-audio-lab--numbers)
- [Install](#install)
- [`addLeadingZero` - add leading zero to number](#addleadingzero---add-leading-zero-to-number)
- [`addTrailingZeros` - add trailing zeros to number](#addtrailingzeros---add-trailing-zeros-to-number)
- [`getAverage` - get average from array of numbers](#getaverage---get-average-from-array-of-numbers)
- [`getDiff` - get difference of two numbers](#getdiff---get-difference-of-two-numbers)
- [`getRandomInRange` - get random int between min and max](#getrandominrange---get-random-int-between-min-and-max)
- [`getSum` - get sum from array of numbers](#getsum---get-sum-from-array-of-numbers)
- [`isEven` - check if a value is even](#iseven---check-if-a-value-is-even)
- [`roundTo` - round float to a specified decimal place](#roundto---round-float-to-a-specified-decimal-place)
- [`toReadable` - get a number in readable format](#toreadable---get-a-number-in-readable-format)

## Install
Expand All @@ -15,6 +22,144 @@ Add the parent package to your dependencies:
yarn add @swrlab/utils
```

## `addLeadingZero` - add leading zero to number

- `value` (required) - Value to add leading zero

Import the library:

```js
const { addLeadingZero } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
addLeadingZero(1)
// '01'

addLeadingZero(10)
// '10'
```

## `addTrailingZeros` - add trailing zeros to number

- `value` (required) - Value to add trailing zeros
- `length` (required) - Amount of the digits after delimiter
- `delimiter` (optional) - Delimiter for trailing zeros (default .)

Import the library:

```js
const { addTrailingZeros } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
addTrailingZeros(1, 5)
// '1.00000'

addTrailingZeros(1.1, 5)
// '1.10000'

addTrailingZeros('1.2', 5)
// '1.20000'

addTrailingZeros(2, 2, ',')
// '2,00'

addTrailingZeros(2.1, 2, ',')
// '2,10'

addTrailingZeros('2,2', 2, ',')
// '2,20'
```

## `getAverage` - get average from array of numbers

- `array` (required) - Array of numbers
- `decimal` (optional) - Decimal places to round (default 2)

Import the library:

```js
const { getAverage } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
getAverage([1, 2, 3])
// 2

getAverage([1.2, 2.4, 3.6], 1)
// 2.4
```

## `getDiff` - get difference of two numbers

- `value a` (required) - value to subtract from
- `value b` (required) - value to subtract

Import the library:

```js
const { getDiff } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
getDiff(2, 1)
// 1

getDiff(1, 2)
// -1
```

## `getRandomInRange` - get random int between min and max

- `min` (required) - Min value (inclusive)
- `max` (required) - Max value (inclusive)

Import the library:

```js
const { getRandomInRange } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
getRandomInRange(1, 5)
// 1,2,3,4 or 5

getRandomInRange(5, 9)
// 5,6,7,8 or 9
```

## `getSum` - get sum from array of numbers

- `array` (required) - Array of numbers
- `decimal` (optional) - Decimal places to round (default 2)

Import the library:

```js
const { getSum } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
getSum([1, 2, 3])
// 6

getSum([1.2, 2.4, 3.6], 1)
// 7.2
```

## `isEven` - check if a value is even

- `value` (required) - Value to check
Expand All @@ -35,6 +180,27 @@ isEven(1)
// false
```

## `roundTo` - round float to a specified decimal place

- `value` (required) - Float value to round
- `decimal` (optional) - Decimal places to round (default 2)

Import the library:

```js
const { roundTo } = require('@swrlab/utils/packages/numbers')
```

Then use the toolkit:

```js
roundTo(1.23456)
// 1.23

roundTo(1.23456, 4)
// 1.2346
```

## `toReadable` - get a number in readable format

- `value` (required) - Value to convert
Expand All @@ -49,5 +215,5 @@ Then use the toolkit:

```js
toReadable(1234567)
// 1.234.567
// '1.234.567'
```
14 changes: 14 additions & 0 deletions packages/numbers/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// import packages
const addLeadingZero = require('../../utils/numbers/addLeadingZero')
const addTrailingZeros = require('../../utils/numbers/addTrailingZeros')
const getAverage = require('../../utils/numbers/getAverage')
const getDiff = require('../../utils/numbers/getDiff')
const getRandomInRange = require('../../utils/numbers/getRandomInRange')
const getSum = require('../../utils/numbers/getSum')
const isEven = require('../../utils/numbers/isEven')
const roundTo = require('../../utils/numbers/roundTo')
const toReadable = require('../../utils/numbers/toReadable')

// export packages
module.exports = {
addLeadingZero,
addTrailingZeros,
getAverage,
getDiff,
getRandomInRange,
getSum,
isEven,
roundTo,
toReadable,
}
8 changes: 4 additions & 4 deletions packages/strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ yarn add @swrlab/utils

## `capitalize` - get capitalized string

- `value` (required) - Value to capitalize
- `value` (required) - String to capitalize

Import the library:

Expand Down Expand Up @@ -271,7 +271,7 @@ notNullOrUndefined(undefined)

## `pluralize` - get pluralized string

- `value` (required) - Value to pluralize
- `value` (required) - String to pluralize

Import the library:

Expand All @@ -297,7 +297,7 @@ pluralize(2, 'Child', 'Children')

## `removeDoubleSpaces` - take a string and remove its duplicate spaces

- `value` (required) - Value to convert
- `value` (required) - String to convert

Import the library:

Expand All @@ -317,7 +317,7 @@ removeDoubleSpaces('hello world once again')

## `toHex` - take a string convert it to a hex string

- `value` (required) - Value to convert
- `value` (required) - String to convert

Import the library:

Expand Down
Loading

0 comments on commit 2e6d9bf

Please sign in to comment.