# sn-utilities

> SN Utilities

Latest version **1.0.138** (published 2020-04-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install sn-utilities
pnpm add sn-utilities
yarn add sn-utilities
bun add sn-utilities
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.138 |
| Published | 2020-04-02 |
| First published | 2016-11-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 55.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | SJC & TG |
| Maintainers | sjcloete |

## Links

- npm: https://www.npmjs.com/package/sn-utilities
- Repository: https://source.da-io.net/vrm/utilities
- npm.io page: https://npm.io/package/sn-utilities

## Dependencies (2)

- [log4js](https://npm.io/package/log4js.md) ^3.0.2
- [isobject](https://npm.io/package/isobject.md) ^3.0.1

## Recent versions

- 1.0.138 (latest) — 2020-04-02
- 1.0.137 — 2020-04-02
- 1.0.136 — 2019-07-22
- 1.0.135 — 2019-07-22
- 1.0.134 — 2019-07-01
- 1.0.133 — 2019-07-01
- 1.0.132 — 2019-06-19
- 1.0.131 — 2019-06-14
- 1.0.130 — 2019-06-14
- 1.0.129 — 2019-06-12
- 1.0.128 — 2019-06-10
- 1.0.127 — 2019-06-10
- 1.0.126 — 2019-06-10
- 1.0.125 — 2019-04-15
- 1.0.124 — 2019-04-05
- … 123 more at https://npm.io/package/sn-utilities/versions

## README

# Utilities
## function getParams(req, func)
### Parameters:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 req                | JSON        | HTTP request object containing HTTP parameters
 func               | function    | JavaScript function (example below)
```
#### Example of func parameter:
```
function getParams(source, target) {
    if (source) {
        if (source.id && !target.id) {
            target.id = source.id;
        }
        if (source.name && !target.name) {
            target.name = source.name;
        }
    }
    return target;
}
```

## function handleError(error, res)
### Parameters:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 error              | JSON        | JSON error object (format below)
 res                | JSON        | HTTP response object
```
#### Format of JSON error parameter:
```json
{
  "error": [{}],
  "status": [123]
}
```
##### Above JSON explained:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 error              | JSON        | The JSON object of the error thrown
 status             | INT         | (Optional) HTTP status code to be used if the status in error is not specified
```
##### Example of above JSON error:
```json
{
  "error": {
    "errors": [
      {
        "error": "invalid input syntax for uuid: \"3334c105-f842-98e7-603a\""
      }
    ],
    "name": "error",
    "length": 118,
    "severity": "ERROR",
    "code": "22P02",
    "detail": "undefined",
    "hint": "undefined",
    "position": "undefined",
    "internalPosition": "undefined",
    "internalQuery": "undefined",
    "where": "undefined",
    "schema": "undefined",
    "table": "undefined",
    "column": "undefined",
    "dataType": "undefined",
    "constraint": "undefined",
    "file": "uuid.c",
    "line": "129",
    "routine": "string_to_uuid"
  }
}
```

## function handleSuccess(success, res)
### Parameters:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 success            | JSON        | JSON success object (format below)
 res                | JSON        | HTTP response object
```
#### Format of JSON success parameter:
```json
{
  "success": {
  	"status": [123],
  	"message": ["abc"],
    "data": {}
  },
  "status": [123]
}
```
##### Above JSON explained:
```
 Parameter          | Type        | Description            
--------------------+-------------+-----------------------------------------------------------------------------------
 success->status    | INT         | (Optional) HTTP status code
 success->message   | TEXT        | Description of status
 success->data      | JSON        | (Optional) Metadata
 status             | INT         | (Optional) HTTP status code to be used if the status in success is not specified
```

## function handleContentTypeJSON(param, res)
### Parameters:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 param              | JSON        | JSON param object (format below)
 res                | JSON        | HTTP response object
```
#### Format of JSON param parameter:
```json
{
  "contentType": ["abc"]
}
```
##### Above JSON explained:
```
 Parameter           | Type        | Description            
---------------------+-------------+-------------------------------------------------
 contentType         | TEXT        | The content type of the request to be validated
```

## function createUUID(data)
### Parameters:
```
 Parameter          | Type        | Description            
--------------------+-------------+------------------------------------------
 data               | ANYTHING    | (Optional)
```

## function getLocalTimestampString()

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