# applicaster-utils

> Applicaster js utilities package

Latest version **1.0.1** (published 2016-05-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install applicaster-utils
pnpm add applicaster-utils
yarn add applicaster-utils
bun add applicaster-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.1 |
| Published | 2016-05-10 |
| First published | 2016-05-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Applicaster Ltd |
| Maintainers | f-roland-applicaster |

## Links

- npm: https://www.npmjs.com/package/applicaster-utils
- Repository: https://github.com/applicaster/applicaster-utils-js
- Homepage: https://github.com/applicaster/applicaster-utils-js#readme
- Issues: https://github.com/applicaster/applicaster-utils-js/issues
- npm.io page: https://npm.io/package/applicaster-utils

## Dependencies (7)

- [atob](https://npm.io/package/atob.md) ^2.0.3
- [btoa](https://npm.io/package/btoa.md) ^1.1.2
- [babel-cli](https://npm.io/package/babel-cli.md) ^6.8.0
- [babel-core](https://npm.io/package/babel-core.md) ^6.8.0
- [react-cookie](https://npm.io/package/react-cookie.md) ^0.4.5
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.6.0
- [babel-preset-stage-0](https://npm.io/package/babel-preset-stage-0.md) ^6.5.0

## Recent versions

- 1.0.1 (latest) — 2016-05-10

## README

# applicaster-utils-js

Set of utilities for Applicaster javascript project.

## How to use
* install with npm
```bash
$ npm i -S applicaster-utils
```
* import in your js code

```javascript
import utils from "applicaster-utils";

const UQUrlWithPayload = '' // ...
const UQJsonFile = utils.decodePayloadFromUrl(UQUrlWithPayload);

```

you can also import only the functions you need

```javascript
import {decodePayloadFromUrl} from "applicaster-utils";

const UQUrlWithPayload = '' // ...
const UQJsonFile = decodePayloadFromUrl(UQUrlWithPayload);

```

## list of available functions :

#### hasLocalStorage : true || false
Boolean operator which tests the availability of localStorage.

#### setPersist(key, data) : null
Uses `utils.hasLocalStorage` to store a string or an object in localStorage or cookies, depending on what's available.

#### getPersist(key) : Object
Returns a string or an object previously stored to localStorage or cookies with the `utils.setPersist` method.

#### getUrlParamByName(name, source) : String || null
Returns the string of a given url parameter. If the source parameter is omitted, the search will be done on location.search

#### decodePayload(payload) : Object
Stringifies and encodes an object with javascript's `atob()` method;

#### encodePayload(object) : String
Decodes a string encoded with javascript's `btoa()` method, and parses it to return an object

#### decodePayloadFromUrl(urlString) : String
Returns the json file URL (`questionUrl` property) in a UQ url with `appli-payload`

#### getQuestionIdFromUrlString(urlString) : String
Returns the UQ id from a UQ json file url.

#### getViewPort() : Object(w: width, h: height, device: device name)
Returns current viewPorts' width and height, plus a device name based on the following map :

```javascript
if (viewPort.w < 322) {
        if (viewPort.h < 490) {
            viewPort.device = "iphone4";
        } else {
            viewPort.device = "iphone5";
        }
    } else if (viewPort.w < 365) {
        if (viewPort.h < 525) {
            viewPort.device = "g3";
        } else {
            viewPort.device = "s6";
        }
    } else if (viewPort.w < 450) {
        viewPort.device = "iphone6";
    } else if (viewPort.w < 1030) {
        if (viewPort.h < 580) {
            viewPort.device = "stab3";
        } else {
            viewPort.device = "ipad";
        }
    } else  if (viewPort.w < 1300) {
        viewPort.device = "androidTab";
    } else {
        viewPort.device = "default";
    }
```

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