# sandeep-utileo

> JS library with most common utils.

Latest version **2.13.0** (published 2021-03-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install sandeep-utileo
pnpm add sandeep-utileo
yarn add sandeep-utileo
bun add sandeep-utileo
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.13.0 |
| Published | 2021-03-15 |
| First published | 2021-02-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | WebChapter \| Bharatpe |
| Maintainers | sandeep-rawat |
| Keywords | browser-util-functions, util-function, js-utils, javascript-utils, javascript-utils-function, common-utils |

## Links

- npm: https://www.npmjs.com/package/sandeep-utileo
- Repository: https://github.com/bharatpe/utileo
- Homepage: https://github.com/bharatpe/utileo#readme
- Issues: https://github.com/bharatpe/utileo/issues
- npm.io page: https://npm.io/package/sandeep-utileo

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.13.0 (latest) — 2021-03-15
- 2.12.0 — 2021-03-15
- 2.11.0 — 2021-03-09
- 2.10.0 — 2021-03-09
- 2.9.0 — 2021-03-09
- 2.8.0 — 2021-03-09
- 2.7.0 — 2021-03-09
- 2.6.0 — 2021-03-09
- 2.5.0 — 2021-03-09
- 2.3.0 — 2021-03-09
- 2.2.0 — 2021-03-09
- 2.1.0 — 2021-03-09
- 2.0.0 — 2021-03-09
- 1.8.0 — 2021-03-09
- 1.7.0 — 2021-03-09
- … 7 more at https://npm.io/package/sandeep-utileo/versions

## README

# Utileo [![NPM version](https://img.shields.io/npm/v/utileo.svg)](https://www.npmjs.com/package/utileo) [![Downloads](http://img.shields.io/npm/dm/utileo.svg)](https://npmjs.org/package/utileo)

A JS library for most commonly used utils

![Utileo](/assets/utileo.png)

## Utils
 - Currency Utils
 - URL Utils
 - Common Utils
 - Geo Location Utils
 - History
 - Storage Utils
 - Date Utils

 # Getting Started (Installation)

```javascript
yarn add utileo

or

npm i utileo --save-dev
```

--------------------------------------------------------------------------------
## Currency Formatter Methods

  Method                          |     Params       |        Description
----------------------------------|------------------|------------------------------------------
  format                          | amount, isFloat  |  To display any and all amount-values, if isFloat is true, amount formatted to 2 decimal places
  parse                           |      amount      |  To parse amount-value back to number-only
  beforeAPIRequest                |      amount      |  Before-submitting on any API-requests

## Common Util Methods

  Method                            |     Params       |        Description
------------------------------------|------------------|---------------------------------------------------------------
  validateName                      |      string      |  Check if all characters in the string are alphabets
  validateOnlyNumber                |  string/number   |  Check if it is a number
  titleCase                         |     string       |  Convert a string to title case
  camelize                          |     string       |  Convert hello-world style strings to helloWorld style strings 
  removeSpacesAndLowerCase          |     string       |  Converting to lower case and remove spaces in a string. Ex:My Name - myname
  replaceSpaceWithUnderscore        |     string       |  Converting space to underscore in a string. Ex:My Name - My_Name
  replaceSpecialCharsWithUnderscore |     string       |  Replace special chars like @,$ to _ . Ex:abc@123%a$ - abc_123_a_
  addKeyToObject                    |     object       |  Adds key to objects
  getIndex                          |    arr,object    |  Find index of an Item from Array of objects.
  toNumber                          |      value       |  Convert a string to number
  partition                         |   arr, criteria  |  Partition array into two arrays based on criteria
  isArray                           |      value       |  Check for an Array
  isObject                          |      value       |  Check for an Object
  isFunction                        |      value       |  Check for a function
  isIOS                             |      none        |  Check device type is IOS or not


## Storage Util Methods

  Method                          |     Params       |        Description
----------------------------------|------------------|-----------------------------------------
  get                             |      key         |  Get value from localstorage by key name
  set                             |    key, value    |  Set value to localstorage
  has                             |      key         |  Check key available in localstorage
  remove                          |      key         |  Remove key from localstorage
  removeAll                       |       -          |  Remove all items from localstorage

## Geo Location Util Method

  Method                          |     Params       |        Description
----------------------------------|------------------|----------------------------
  getLatLong                      |     timeout      |  get lat and long

## URL Parameter Method

  Method                          |     Params           |        Description
----------------------------------|----------------------|----------------------------
  getURLParameter                 |  qrString, paramName |  get parameter value

## Date Util Methods

  Method                          |     Params       |        Description
----------------------------------|------------------|---------------------------------------------------------------------
  formatDate                      |      date        |  Returns an object of day, month, year
  getCurrentDate                  |        -         |  Returns current date
  getDateByDashFormat             |      date        |  Returns date with DD-MM-YYYY format
  getDateBySlashFormat            |      date        |  Returns date with DD/MM/YYYY format
  timestampToDate                 |    timestamp     |  Converting timestamp to date Ex : 1560211200000 to Tue Jun 11 2019
  getDateFromString               |     string       |  Converting string to date Ex : '6-11-2019' to Tue Jun 11 2019

----------------------------------------------------------------------------------------------------------------------------

## Usage
```javascript
import { CurrencyUtils, CommonUtils, StorageUtils, GeoLocationUtils, URLUtils, History, DateUtils } from 'utileo';

//---------------------------------- Currency Utils -------------------------//
CurrencyUtils.format('10000') // 10,000
CurrencyUtils.format('10000.1234',true) // 10,000.12
CurrencyUtils.parse('1,00,000') // 100000 

//---------------------------------- Common Utils -------------------------------------//
CommonUtils.validateName('only alphabets')// true
CommonUtils.validateOnlyNumber('1233')// true
CommonUtils.titleCase('main menu')// Main Menu
CommonUtils.camelize('main-menu')// mainMenu
CommonUtils.toNumber('1234')// 1234
CommonUtils.isArray([1,2,3]);// true
CommonUtils.isObject({"name": "abc", "age": 12})// true
CommonUtils.isFunction(CommonUtils.isObject);// true

var users = [
	{'user': 'barney', 'age': 36, 'active': false},
	{'user': 'fred', 'age': 40, 'active': true},
	{'user': 'pebbles', 'age': 1, 'active': false}
];

var groups = CommonUtils.partition(users, function (user) {
	return user.active;
});
// groups[0] has [{'user':'fred', 'age': 40, 'active': true}]
// groups[1] has [{'user':'barney', 'age': 36, 'active': false}, {'user': 'pebbles', 'age': 1, 'active': false}]

CommonUtils.getIndex(users,{'user': 'barney', 'age': 36, 'active': false});// 0

CommonUtils.addKeyToObject(users);// key(type) will be added
// [{type: "0", user: "barney", age: 36, active: false}
// {type: "1", user: "fred", age: 40, active: true}
// {type: "2", user: "pebbles", age: 1, active: false}]

//------------------------ Storage Utils -----------------------------//
StorageUtils.get('phoneNumber')// 9899224433
StorageUtils.set('phoneNumber',9899224433)
StorageUtils.has('phoneNumber')// true
StorageUtils.remove('token')
StorageUtils.removeAll()

//----------------------- Geo Location ----------------------------//
let latLong = GeoLocationUtils.getLatLong()// value of lat long
let latitude = latLong.lat
let longitude = latLong.long

//--------------------------------- URL Parameter ---------------------------------------//
var appVisa = URLUtils.getURLParameter(window.location.href, 'visa')// 12n23be3h3bhbbh34

//--------- History --------//
History.replace("/")
History.goBack()
History.push("/")

//------------------------------------------ Date Utils ------------------------------------------------//
const currDate = DateUtils.getCurrentDate();// Wed Jul 14 2020 13:07:57 GMT+0530 (India Standard Time)
const dateObj = DateUtils.formatDate(currDate);// {day: 14, month: 6, year: 2020}
DateUtils.getDateByDashFormat(currDate);// 14-07-2020
DateUtils.getDateBySlashFormat(currDate);// 14/07/2020
DateUtils.timestampToDate(1560211200000);// Tue Jun 11 2019 05:30:00 GMT+0530 (India Standard Time)
DateUtils.getDateFromString('2/10/2017');// Sat Feb 10 2017 00:00:00 GMT+0530 (India Standard Time)

```

## Contributors
Here [Contributors](https://github.com/bharatpe/utileo/graphs/contributors)


## License
MIT @[bharatpe](https://bharatpe.in)

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