Skip to content

Commit

Permalink
Merge pull request #524 from swrlab/dev/update-1.1.2
Browse files Browse the repository at this point in the history
Update v1.1.2
  • Loading branch information
rafaelmaeuer authored Feb 20, 2023
2 parents 2e6d9bf + f6de357 commit b664b68
Show file tree
Hide file tree
Showing 33 changed files with 839 additions and 326 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ by [**SWR Audio Lab**](https://lab.swr.de/)

## Changelog

- 2023-02-15 - v1.1.2
- feat: add `revYearMonthDay` to date package
- feat: add `date` package with iso time functions
- feat: add `arrayToObjectCount` to helpers package
- feat: add `getJsonKeys` to helpers package
- feat: add `normalize` to numbers package
- feat: add `isEmptyString` to strings package

- 2023-02-13 - v1.1.1
- feat: add `addTrailingZeros` to numbers package
- feat: add `addLeadingZero` to numbers package
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const undici = require('@swrlab/utils/packages/undici')
Scripts are meant to be run locally, therefore clone the repository and first install dependencies. We prefer `yarn` for this:

```sh
yarn install
yarn install @swrlab/utils
```

Then run the desired script.
Expand Down
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
node-utils by SWR audio lab
frequently used node-packages and helpers
*/

// import packages
const ard = require('./packages/ard')
const helpers = require('./packages/helpers')
const numbers = require('./packages/numbers')
const storage = require('./packages/storage-wrapper')
const strings = require('./packages/strings')
const undici = require('./packages/undici')

// export packages
module.exports = {
ard,
helpers,
numbers,
storage,
strings,
undici,
}
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@swrlab/utils",
"version": "1.1.1",
"version": "1.1.2",
"description": "Wrapping common SWR Audio Lab utils",
"main": "./src/index.js",
"main": "./index.js",
"engines": {
"node": ">=16"
},
Expand All @@ -16,19 +16,20 @@
"ard:publishers": "node -r dotenv/config scripts/ard/publishers.js",
"ard:pub-sort": "node -r dotenv/config scripts/ard/sortPubByExtId.js",
"lint": "eslint .",
"test": "mocha test/test.js -r dotenv/config",
"test": "mocha tests/**.js -r dotenv/config",
"reinstall": "rm -rf node_modules && rm yarn.lock && yarn"
},
"author": "SWR Audio Lab <[email protected]>",
"license": "MIT",
"private": false,
"dependencies": {
"@google-cloud/storage": "^6.9.2",
"@google-cloud/storage": "^6.9.3",
"abort-controller": "^3.0.0",
"aws-sdk": "^2.1313.0",
"aws-sdk": "^2.1318.0",
"chai": "^4.3.7",
"luxon": "^3.2.1",
"node-crc": "swrlab/node-crc#v2.1.0",
"undici": "^5.19.1",
"undici": "^5.20.0",
"uuid": "9.0.0"
},
"devDependencies": {
Expand Down
158 changes: 158 additions & 0 deletions packages/date/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# SWR Audio Lab / Date

Date functions and time helpers.

- [SWR Audio Lab / Date](#swr-audio-lab--date)
- [Install](#install)
- [`getDateHourMinutes` - get date with hours and minutes](#getdatehourminutes---get-date-with-hours-and-minutes)
- [`getDayMonthYear` - get date with month and year](#getdaymonthyear---get-date-with-month-and-year)
- [`getFullRelativeTime` - get full date with relative years](#getfullrelativetime---get-full-date-with-relative-years)
- [`getHourMinutes` - get hours and minutes from iso date](#gethourminutes---get-hours-and-minutes-from-iso-date)
- [`getIsoRelativeTime` - get iso date with relative years](#getisorelativetime---get-iso-date-with-relative-years)
- [`getRelativeTime` - get relative years from iso date](#getrelativetime---get-relative-years-from-iso-date)
- [`getYearMonthDay` - get YYYYMMDD from iso date](#getyearmonthday---get-yyyymmdd-from-iso-date)
- [`revYearMonthDay` - get DDMMYYYY from YYYYMMDD](#revyearmonthday---get-ddmmyyyy-from-yyyymmdd)

## Install

Add the parent package to your dependencies:

```sh
yarn add @swrlab/utils
```

## `getDateHourMinutes` - get date with hours and minutes

- `value` (required) - Date as ISO string

Import the library:

```js
const { getDateHourMinutes } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getDateHourMinutes('2038-01-19T03:14:08.000')
// 'Di, 19. Januar 2038 - 03:14 Uhr'
```

## `getDayMonthYear` - get date with month and year

- `value` (required) - Date as ISO string

Import the library:

```js
const { getDayMonthYear } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getDayMonthYear('2038-01-19T03:14:08.000')
// 'Di, 19. Januar 2038'
```

## `getFullRelativeTime` - get full date with relative years

- `value` (required) - Date as ISO string

Import the library:

```js
const { getFullRelativeTime } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getFullRelativeTime('2038-01-19T03:14:08.000')
// 'Di, 19. Januar 2038 - 03:14 Uhr (in YY Jahren)'
```

## `getHourMinutes` - get hours and minutes from iso date

- `value` (required) - Date as ISO string

Import the library:

```js
const { getHourMinutes } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getHourMinutes('2038-01-19T03:14:08.000')
// '03:14'
```

## `getIsoRelativeTime` - get iso date with relative years

- `value` (required) - Date as ISO string

Import the library:

```js
const { getIsoRelativeTime } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getIsoRelativeTime('2038-01-19T03:14:08.000')
// '2038-01-19T03:14:08.000 (in YY Jahren)'
```

## `getRelativeTime` - get relative years from iso date

- `value` (required) - Date as ISO string

Import the library:

```js
const { getRelativeTime } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getRelativeTime('2038-01-19T03:14:08.000')
// '(in YY Jahren)'
```

## `getYearMonthDay` - get YYYYMMDD from iso date

- `value` (required) - Date as ISO string

Import the library:

```js
const { getYearMonthDay } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
getYearMonthDay('2038-01-19T03:14:08.000')
// '20380119'
```

## `revYearMonthDay` - get DDMMYYYY from YYYYMMDD

- `value` (required) - Date as `YYYYMMDD` string

Import the library:

```js
const { revYearMonthDay } = require('@swrlab/utils/packages/date')
```

Then use the toolkit:

```js
revYearMonthDay('20380119')
// '19012038'
```
21 changes: 21 additions & 0 deletions packages/date/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// import packages
const getDateHourMinutes = require('../../utils/date/getDateHourMinutes')
const getDayMonthYear = require('../../utils/date/getDayMonthYear')
const getFullRelativeTime = require('../../utils/date/getFullRelativeTime')
const getHourMinutes = require('../../utils/date/getHourMinutes')
const getIsoRelativeTime = require('../../utils/date/getIsoRelativeTime')
const getRelativeTime = require('../../utils/date/getRelativeTime')
const getYearMonthDay = require('../../utils/date/getYearMonthDay')
const revYearMonthDay = require('../../utils/date/revYearMonthDay')

// export packages
module.exports = {
getDateHourMinutes,
getDayMonthYear,
getFullRelativeTime,
getHourMinutes,
getIsoRelativeTime,
getRelativeTime,
getYearMonthDay,
revYearMonthDay,
}
36 changes: 36 additions & 0 deletions packages/helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Common functions and helpers.

- [SWR Audio Lab / Helpers](#swr-audio-lab--helpers)
- [Install](#install)
- [`arrayToObjectCount` - reduce array elements to object with count](#arraytoobjectcount---reduce-array-elements-to-object-with-count)
- [`getJsonKeys` - get all keys of json input](#getjsonkeys---get-all-keys-of-json-input)
- [`sleep` - sleep a given time (async)](#sleep---sleep-a-given-time-async)

## Install
Expand All @@ -14,6 +16,40 @@ Add the parent package to your dependencies:
yarn add @swrlab/utils
```

## `arrayToObjectCount` - reduce array elements to object with count

- `value` (required) - Array to get entries from

Import the library:

```js
const { arrayToObjectCount } = require('@swrlab/utils/packages/helpers')
```

Then use the toolkit:

```js
arrayToObjectCount(['foo', 'bar', 'bar'])
// { bar: 2, foo: 1 }
```

## `getJsonKeys` - get all keys of json input

- `value` (required) - Json to get keys from

Import the library:

```js
const { getJsonKeys } = require('@swrlab/utils/packages/helpers')
```

Then use the toolkit:

```js
getJsonKeys({ hello: 'world', foo: 'bar' })
// ['hello', 'foo']
```

## `sleep` - sleep a given time (async)

- `value` (required) - Value to sleep (in ms)
Expand Down
4 changes: 4 additions & 0 deletions packages/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// import packages
const arrayToObjectCount = require('../../utils/helpers/arrayToObjectCount')
const getJsonKeys = require('../../utils/helpers/getJsonKeys')
const sleep = require('../../utils/helpers/sleep')

// export packages
module.exports = {
arrayToObjectCount,
getJsonKeys,
sleep,
}
22 changes: 22 additions & 0 deletions packages/numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Common number and math helpers.
- [`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)
- [`normalize` - normalize a value by given maximum](#normalize---normalize-a-value-by-given-maximum)
- [`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)

Expand Down Expand Up @@ -180,6 +181,27 @@ isEven(1)
// false
```

## `normalize` - normalize a value by given maximum

- `value` (required) - Value to normalize
- `max` (required) - Maximum for normalization

Import the library:

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

Then use the toolkit:

```js
normalize(2, 100)
// 0.02

normalize(80, 100)
// 0.8
```

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

- `value` (required) - Float value to round
Expand Down
2 changes: 2 additions & 0 deletions packages/numbers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 normalize = require('../../utils/numbers/normalize')
const roundTo = require('../../utils/numbers/roundTo')
const toReadable = require('../../utils/numbers/toReadable')

Expand All @@ -18,6 +19,7 @@ module.exports = {
getRandomInRange,
getSum,
isEven,
normalize,
roundTo,
toReadable,
}
Loading

0 comments on commit b664b68

Please sign in to comment.