# appcd-util

> Various utility functions to support the Appc Daemon.

Latest version **3.1.6** (published 2021-04-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install appcd-util
pnpm add appcd-util
yarn add appcd-util
bun add appcd-util
```

## 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 | 3.1.6 |
| Published | 2021-04-26 |
| First published | 2017-09-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.13.0 |
| Dependencies | 5 |
| Unpacked size | 99.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Axway, Inc. |
| Maintainers | cb1kenobi, appcelerator, awam |

## Links

- npm: https://www.npmjs.com/package/appcd-util
- Repository: https://github.com/appcelerator/appc-daemon.git#master
- Homepage: https://github.com/appcelerator/appc-daemon
- Issues: https://github.com/appcelerator/appc-daemon/issues
- npm.io page: https://npm.io/package/appcd-util

## Dependencies (5)

- [semver](https://npm.io/package/semver.md) ^7.3.5
- [appcd-fs](https://npm.io/package/appcd-fs.md) ^2.0.7
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.19

## Recent versions

- 3.1.6 (latest) — 2021-04-26
- 3.1.5 — 2021-04-15
- 3.1.4 — 2021-03-03
- 3.1.3 — 2021-01-26
- 3.1.2 — 2021-01-22
- 3.1.1 — 2021-01-05
- 3.1.0 — 2020-12-01
- 3.0.0 — 2020-06-12
- 2.0.2 — 2020-01-08
- 2.0.1 — 2019-11-06
- 2.0.0 — 2019-08-13
- 1.1.7 — 2019-06-04
- 1.1.6 — 2019-03-29
- 1.1.5 — 2019-01-16
- 1.1.4 — 2018-11-27
- … 41 more at https://npm.io/package/appcd-util/versions

## README

# appcd-util

Common utility functions.

Visit https://github.com/appcelerator/appc-daemon for more information.

Report issues to [GitHub issues][2]. Official issue tracker in [JIRA][3].

## Installation

	npm i appcd-util

## Usage

```js
import { arch } from 'appcd-util';

console.log(arch()); // 'x86' or 'x64'
```

```js
import { arrayify } from 'appcd-util';

console.log(arrayify('foo')); // [ 'foo' ]

console.log(arrayify([ 'a', '', null, 'b' ], true)); // [ 'a', 'b' ]
```

```js
import { assertNodeEngineVersion } from 'appcd-util';

// throw an exception if current node version doesn't satisfy the `engines.node` version
assertNodeEngineVersion(require('package.json'));
```

```js
import { cache } from 'appcd-util';

const now = () => Date.now();

const first = await cache('my namespace', now);
const second = await cache('my namespace', now);
assert(first === second);

const third = await cache('my namespace', true, now);
assert(first !== third && second !== third);
```

```js
import { cacheSync } from 'appcd-util';

const now = () => Date.now();

const first = cacheSync('my namespace', now);
const second = cacheSync('my namespace', now);
assert(first === second);

const third = cacheSync('my namespace', true, now);
assert(first !== third && second !== third);
```

Debouncer that returns a promise and that can be cancelled.

```js
import { debounce } from 'appcd-util';

const fn = debounce(() => {
	console.log(new Date());
});

// schedule the callback to be called in 200ms
fn().then(() => {
	console.log('Function called');
});

// cancel the debounce
fn.cancel();
```

```js
import { formatNumber } from 'appcd-util';

console.log(formatNumber(12)); // 12
console.log(formatNumber(123)); // 123
console.log(formatNumber(1234)); // 1,234
console.log(formatNumber(12345)); // 12,345
console.log(formatNumber(123456)); // 123,456
console.log(formatNumber(1234567)); // 1,234,567
```

```js
import { get } from 'appcd-util';

const obj = {
	foo: 'bar'
};

console.log(get(obj, 'foo')); // 'bar'
console.log(get(obj, 'baz', 'pow')); // 'pow'
```

Get all open sockets, [net] servers, timers, child processes, filesystem watchers, and other
handles.

```js
import { getActiveHandles } from 'appcd-util';

console.log(getActiveHandles());
```

```js
import { inherits } from 'appcd-util';

class A {}
class B extends A {}
class C {}

console.log(inherits(B, A)); // true
console.log(inherits(B, C)); // false
```

```js
import { mergeDeep } from 'appcd-util';

const obj1 = {
	a: {
		b: 'c'
	}
};

const obj2 = {
	a: {
		d: 'e'
	}
};

console.log(mergeDeep(obj1, obj2)); // { a: { b: 'c', d: 'e' } }
```

```js
import { mutex } from 'appcd-util';

const fn = () => {
	return mutex('my mutex', () => {
		console.log('foo!');
	});
};

await Promise.all([ fn(), fn(), fn() ]);
```

```js
import { randomBytes } from 'appcd-util';

console.log(randomBytes(20));
```

```js
import { sha1 } from 'appcd-util';

console.log(sha1('foo'));
```

```js
import { sleep } from 'appcd-util';

await sleep(1000); // sleep for 1 second
```

Block multiple simultaneous callers until the first caller finishes, then all queued up 'tailgaters'
are resolved with the result.

```js
import { tailgate } from 'appcd-util';

const fn = () => {
	return tailgate('my tailgate', async () => {
		console.log('I will only be called once');
	});
};

await Promise.all([ fn(), fn(), fn() ]);
```

```js
import { unique } from 'appcd-util';

console.log(unique([ 'a', 'b', 'a', 'b' ])); // [ 'a', 'b' ]
```

## Legal

This project is open source under the [Apache Public License v2][1] and is developed by
[Axway, Inc](http://www.axway.com/) and the community. Please read the [`LICENSE`][1] file included
in this distribution for more information.

[1]: https://github.com/appcelerator/appc-daemon/blob/master/packages/appcd-util/LICENSE
[2]: https://github.com/appcelerator/appc-daemon/issues
[3]: https://jira.appcelerator.org/projects/DAEMON/issues

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