# cu-common-utils

> A package having common functions requeired for JS.

Latest version **1.0.9** (published 2020-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install cu-common-utils
pnpm add cu-common-utils
yarn add cu-common-utils
bun add cu-common-utils
```

## 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.9 |
| Published | 2020-03-05 |
| First published | 2020-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ahmer Maqsood Hashmi |
| Maintainers | ahmermh |
| Keywords | npm, npm-utils, common, common-utils, utils, cu |

## Links

- npm: https://www.npmjs.com/package/cu-common-utils
- Repository: https://github.com/AhmerMH/angular-helpers/tree/master/common-utils
- npm.io page: https://npm.io/package/cu-common-utils

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2020-03-05
- 1.0.8 — 2020-02-12
- 1.0.7 — 2020-02-11
- 1.0.6 — 2020-02-06
- 1.0.5 — 2020-02-06
- 1.0.4 — 2020-02-06
- 1.0.3 — 2020-02-04
- 1.0.2 — 2020-02-04
- 1.0.1 — 2020-02-03
- 1.0.0 — 2020-02-03

## README

# Common Utils
Common utils is a library for JS projects having all the common functionalities while developing an angular/ node/ react project. 

## Installation
Use npm to install the package
```bash
npm install cu-common-utils
```

## Usage

For import syntax 
```bash
import * as cu from 'cu-common-utils';

let x = {};
console.log(cu.isEmptyObject(x));
```

For require syntax
```bash
var cu = require('cu-common-utils');
let x = {};
console.log(cu.isEmptyObject(x));
```

## Functions

| Function                                                                            | Parameters                                                                                                                                                                                                                                                                                                                                                              | Description                                                                                                 | Return Value                                                                                                                                   |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| isEmpty(value)                                                                      | value: The value that is to be checked                                                                                                                                                                                                                                                                                                                                  | Checks if the value is null/ undefined or empty                                                             | true/false                                                                                                                                     |
| isEmptyObject(object)                                                               | object: The object that is to be checked                                                                                                                                                                                                                                                                                                                                | Checks if object is null/ undefined or empty({})                                                            | true/false                                                                                                                                     |
| isArray(object)                                                                     | object: Object to be checked if it is an array or not                                                                                                                                                                                                                                                                                                                   | Checks if the passed object is array or not                                                                 | true/false                                                                                                                                     |
| getValidArray(object, path, defaultValue)                                           | object: The object to be traversed <br>path: Hierarchy of the key whose value is to be checked <br>defaultValue(Optional): The default value to be returned if value is not found.                                                                                                                                                                                      | Checks the path of the array and returns the value if there are no errors                                   | - path value (if there is no error) <br>- returns empty array [] in case of error by default                                                   |
| getValidObject(object, path, defaultValue)                                          | object: The object to be traversed <br>path: Hierarchy of the key whose value is to be checked <br>defaultValue(Optional): The default value to be returned if value is not found.                                                                                                                                                                                      | Checks the path of the object and returns the value if there are no errors                                  | - path value (if there is no error) <br>- returns empty object {} in case of error by default                                                  |
| getValidString(object, path, defaultValue)                                          | object: The object to be traversed <br>path: Hierarchy of the key whose value is to be checked <br>defaultValue(Optional): The default value to be returned if value is not found.                                                                                                                                                                                      | Checks the path of the string and returns the value if there are no errors                                  | - path value (if there is no error) <br>- returns empty string "" in case of error by default                                                  |
| getValidNumber(object, path, defaultValue)                                          | object: The object to be traversed <br>path: Hierarchy of the key whose value is to be checked <br>defaultValue(Optional): The default value to be returned if value is not found.                                                                                                                                                                                      | Checks the path of the number and returns the value if there are no errors                                  | - path value (if there is no error) <br>- returns 0 in case of error by default                                                                |
| mergeArrays(list1, list2)                                                           | list1: first list <br>list2: second list                                                                                                                                                                                                                                                                                                                                | Merge two lists and return a new list.                                                                      | - Returns merged list <br>- returns an empty list [] in case of an error                                                                       |
| cloneObject(object, defaultValue)                                                   | object: The object/value to be cloned <br>defaultValue(Optional): Value to be returned if object is null or an error occurs                                                                                                                                                                                                                                             | Creates a new object that is the clone of passed object.                                                    | - return new object without passing the reference <br>- return empty object {} in case of error                                                |
| stringifyJSON(object, defaultValue)                                                 | object: The object/value to be stringified <br>defaultValue(Optional): Value to be returned if object is null or an error occurs                                                                                                                                                                                                                                        | Convert JSON object to string.                                                                              | - returns stringified JSON <br>- returns empty string "" in case of an error as default value                                                  |
| parseJSON(objectString, defaultValue)                                               | objectString: The string whose value will be parsed <br>defaultValue(Optional): Value to be returned if object is null or an error occurs                                                                                                                                                                                                                               | Converts string value to JSON.                                                                              | - returns parsed JSON object from string <br>- returns empty object {} in case of an error as default value                                    |
| findObjectInList(list, compareObject, keyInList, defaultValue, keyForCompareObject) | list: The list from which object will be searched <br>compareObject: The object which is to be compared <br>keyInList: Object key value in list that will be compared <br>defaultValue(Optional): Default value that will be returned in case of an error <br>keyForCompareObject(Optional): key of the compareObject that will be compared with list objects key value | Find an object from the list.                                                                               | - returns the object if object is found <br>- returns undefined as default value                                                               |
| findElementInList(list, value, defaultValue)                                        | list: The list from which object will be searched <br>value: The value to be compared <br>defaultValue(Optional): Default value that will be returned in case of an error                                                                                                                                                                                               | Find value in the list                                                                                      | - returns the object if object is found <br>- returns undefined as default value                                                               |
| replaceAll(text, regex, replacement, defaultValue)                                  | text: The string in which regex will be searched<br>regex: The regular expression to which this string is to be matched<br>replacement (Optional): The string to be substituted for each element. By default it is ""<br>defaultValue (Optional): The default value to be returned in case of error/ exception                                                          | Replaces each substring of this string that matches the given regular expression with the given replacement | - Returns the replaced regex string in case of no error/ exception<br>- Returns empty string ("") as default value in case of error/ exception |
| indexOf(text, regex, startIndex, defaultValue)                                      | text: The string in which regex will be searched<br>regex: The regular expression to which this string is to be matched<br>startIndex (Optional): starting index from where regex will be matched. O by default<br>defaultValue (Optional): The default value to be returned in case of error/ exception. By default returns -1.<br>                                    | Searches starting index of a given string from the text.                                                    | - Returns starting index of the matched string<br>- Returns -1 if value is not found or in case of an error                                    |

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](https://choosealicense.com/licenses/mit/)

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