# oute-services-utility-sdk

> - Initialization

Latest version **0.0.64** (published 2024-06-27) · 0 weekly downloads

## Install

```sh
npm install oute-services-utility-sdk
pnpm add oute-services-utility-sdk
yarn add oute-services-utility-sdk
bun add oute-services-utility-sdk
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.64 |
| Published | 2024-06-27 |
| First published | 2023-06-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 63.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |

## Links

- npm: https://www.npmjs.com/package/oute-services-utility-sdk
- npm.io page: https://npm.io/package/oute-services-utility-sdk

## Dependencies (9)

- [qs](https://npm.io/package/qs.md) ^6.11.2
- [uuid](https://npm.io/package/uuid.md) ^9.0.1
- [dayjs](https://npm.io/package/dayjs.md) ^1.11.10
- [shlex](https://npm.io/package/shlex.md) ^2.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.12
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.isobject](https://npm.io/package/lodash.isobject.md) ^3.0.2
- [lodash.isplainobject](https://npm.io/package/lodash.isplainobject.md) ^4.0.6

## Recent versions

- 0.0.64 (latest) — 2024-06-27
- 0.0.63 — 2024-06-24
- 0.0.62 — 2024-06-21
- 0.0.61 — 2024-06-19
- 0.0.60 — 2024-06-17
- 0.0.59 — 2024-06-17
- 0.0.58 — 2024-06-17
- 0.0.57 — 2024-06-03
- 0.0.56 — 2024-05-31
- 0.0.55 — 2024-05-28
- 0.0.54 — 2024-05-28
- 0.0.53 — 2024-05-27
- 0.0.52 — 2024-05-27
- 0.0.51 — 2024-05-24
- 0.0.49 — 2024-05-24
- … 48 more at https://npm.io/package/oute-services-utility-sdk/versions

## README

# This module expose helper functions

- Initialization

```js
  var utility = require("oute-services-utility-sdk")
```

- Validate and parse string object

```js
  utility.validateAndParseObject("{}")
```

- Execute API

```js
  var options = {
    method: 'GET',
    url: 'http://localhost:3101/service/v0/variable/get/transformed',
    headers: {
      'token': "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidGVzdEBnb2ZvLmFwcCIsIm9yZ0lkcyI6WyJaekJmSk1wZlEiXSwiaWF0IjoxNjgyMjQ4MjcwLCJleHAiOjMzMjA4MjkwNjcwfQ.OADEKdh1IaABuKCEwFgskapkNVrg_IIjzj1cd0HoGdc",
      'Content-Type': 'application/json'
    },
    path_variable: {p: "123"},
    query_params: {asset_id: "asset"},
    convert_to_curl: false, //this will convert the request to curl and respond with curl
    timeout: 700, //This will be in milliseconds
    response_type: "stream", //possiblie value ["stream", null], This type is used for getting the response in specified format.
    body_info: {
      type: "", //form-data, x-www-form-urlencoded, binary, raw, none or ""
      sub_type: "" //if raw => json, text, html, xml, javascript
    }
  }
  await utility.executeAPI(options)
```

- Compare array

```js
  src_array = [1,2]
  comparing_array = [2,1]
  compare_type= "all" 
  // all => all element of both array should be same
  // any_one => any one element of comparing array should be in src array
  utility.compareArray(src_array, comparing_array, compare_type)
```

- Query array

```js
  src_array = [{a: "test", b: "mtro"},{a: "mets"}, {a: "test1", b: "mtro"}, {a: "test1", b: "wert"}]
  search_options = {a: /test/, b: /mt/}
  utility.queryArray(src_array, search_options)
```

- Invoke the function

```js
  //Note if trying to call the callback function then ensure the last args should be callback function
  //Callback function assumed as (error, result) => {}
  fn = (a)=>
    new Promise((resolve, reject) =>
      return reject(a)
    )
  func_itentity = "promise"
  await utility.invokeFunction(fn, func_itentity, {a: 1})
```

- Function call with retry and delay

```js
  max_retry = 1
  retry_delay_ms = 1000
  fn = (a)=>
    new Promise((resolve, reject) =>
      return reject(a)
    )
  fn_type = "promise"
  await utility.retry(max_retry, retry_delay_ms, fn, fn_type, {a: 1})
```

- sleep function

```js
  sleep_ms = 500
  await utility.sleep(sleep_ms)
```

- Parse cmd args

```js
  utility.parseArgs(process.argv)
```

## Transformations

- json to schema

```js
  object = { orderId : "123", items : [ {medicineId : "2", qty : "3"},{ankit : "ankit"} ], address : { line1 :  {medicineId : "2", qty : "3"}, line2 : 500033 }}
  schema_config = {}
  utility.jsonToSchema(object, schema_config)
```

- schema to json

```js
  schema_config = {"schema":[{"type":"string","key":"name","sample_value":"Asd","path":["name"],"pathStr":"name"},{"type":"string","key":"orderId","sample_value":"123","path":["orderId"],"pathStr":"orderId"},{"type":"object","key":"items","schema":[{"type":"array","key":"items2","schema":[{"type":"string","key":"medicineId","sample_value":"2","path":["items","items2","medicineId"],"pathStr":"{items}.[items2].medicineId"},{"type":"string","key":"qty","sample_value":"3","path":["items","items2","qty"],"pathStr":"{items}.[items2].qty"},{"type":"string","key":"ankit","sample_value":"ankit","path":["items","items2","ankit"],"pathStr":"{items}.[items2].ankit"}],"path":["items"],"pathStr":"{items}.items2"},{"type":"string","key":"medicineId","sample_value":"2","path":["items","medicineId"],"pathStr":"{items}.medicineId"},{"type":"string","key":"qty","sample_value":"3","path":["items","qty"],"pathStr":"{items}.qty"}],"path":[],"pathStr":"items"}],"path":[],"keys":["name","orderId","items","{items}.items2","{items}.[items2].medicineId","{items}.[items2].qty","{items}.[items2].ankit","{items}.medicineId","{items}.qty"],"flattened_schema":[{"type":"string","key":"name","sample_value":"Asd","path":["name"],"pathStr":"name"},{"type":"string","key":"orderId","sample_value":"123","path":["orderId"],"pathStr":"orderId"},{"type":"object","key":"items","path":["items"],"pathStr":"{items}"},{"type":"array","key":"items2","path":["items","items2"],"pathStr":"{items}.items2"},{"type":"string","key":"medicineId","sample_value":"2","path":["items","items2","medicineId"],"pathStr":"{items}.[items2].medicineId"},{"type":"string","key":"qty","sample_value":"3","path":["items","items2","qty"],"pathStr":"{items}.[items2].qty"},{"type":"string","key":"ankit","sample_value":"ankit","path":["items","items2","ankit"],"pathStr":"{items}.[items2].ankit"},{"type":"string","key":"medicineId","sample_value":"2","path":["items","medicineId"],"pathStr":"{items}.medicineId"},{"type":"string","key":"qty","sample_value":"3","path":["items","qty"],"pathStr":"{items}.qty"}]}
  utility.schemaToJson(schema_config)
```

- get default value and type for key

```js
  path_str = "{a}.{b}.c"
  key_index = 1
  key_separator = "."
  utility.getDefaultValueAndTypeForKey(path_str, key_index, key_separator)
```

- Check, parse and format the date

```js
  //This function usasage the dayjs lib to parse and validate please check the doc for more info
  [docs](https://day.js.org/docs/en/installation/installation)
  date = "2024-03-19T07:38:01.172Z"
  src_format = undefined //Date original format
  out_format = "YYYY-MM-DD HH:mm:ss" //Format for the ouput date string
  tz_string = undefined //timezone string to parse basis of timezone
  utility.processDate(date, src_format, out_format, tz_string)
```

- Clean the object based of conditions

```js
  inputs = [] || {}
  filterFn = (value) => return (value != "") //default is to filter the undefined keys
  utility_instance.cleanObjectBy(inputs, filterFn)
```

- Check if value is empty

```js
  value = {} //{}, [], "", null, undefinded returns true else false
  utility.isEmpty(value)
```

- Check if the value is null or empty

```js
  value = {} //"", null, undefinded returns true else false
  utility.isEmptyOrNull(value)
```

- Json config to curl

```js
  value = { method: 'POST', url: 'google.com/service/v0/variable/get/transformed?asset_id=asset', headers: { 'Content-Type': 'application/json' }, body: { a: 'assa' } }
  utility.jsonToCurl(value)
```

- Curl to json

```js
  value = "curl -L -X POST google.com/service/v0/variable/get/transformed?asset_id=asset -H 'Content-Type: application/x-www-form-urlencoded' -F 'a=\"assa\"'"
  utility.curlToJson(value)
```

- Get the date instance

```js
  let date = "2024-03-19T07:38:01.172Z";
  let src_format = undefined;
  let out_format = "YYYY-MM-DD HH:mm:ss";
  let tz_string = undefined;
  let date_instance = utility.getDateInstance();
  console.log("RESULT", date_instance(date, src_format).tz(tz_string).format(out_format));
```

- Update the request based on the config

```js
  let date = "2024-03-19T07:38:01.172Z";
  let src_format = undefined;
  let out_format = "YYYY-MM-DD HH:mm:ss";
  let tz_string = undefined;
  let date_instance = utility.getDateInstance();
  console.log("RESULT", date_instance(date, src_format).tz(tz_string).format(out_format));
```

- Get the UUID instance

```js
  let uuid_instance = utility.getUuidInstance();
  console.log("RESULT", uuid_instance.v4());
```

- Convert db type

```js
  let raw_type = "varchar";
  let result = utility.convertDbType(raw_type);
  console.log("RESULT", result);
```

---
_Source: https://npm.io/package/oute-services-utility-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
