o
Version:
common object helper functions
99 lines (75 loc) • 2.4 kB
Markdown

# [o](https://github.com/hammy2899/o)
common object helper functions written in TypeScript which can be used in [NodeJS](https://nodejs.org/en/) and the browser (supports ES6).
[](https://github.com/hammy2899/o/actions)
[](https://coveralls.io/github/hammy2899/o?branch=master)
[](https://www.npmjs.com/package/o)
[](https://github.com/hammy2899/o/blob/master/LICENSE.md)
[](https://standardjs.com)
### Installation
#### [NPM](https://npmjs.com)
```bash
$ npm install o
```
#### [Yarn](https://yarnpkg.com)
```bash
$ yarn add o
```
### Usage
#### TypeScript
```typescript
import o from 'o';
// or require specific functions
import { is, empty } from 'o';
```
#### NodeJS
```javascript
const o = require('o');
// or require specific functions
const { is, empty } = require('o');
```
#### Browser
##### ES6
```html
<!-- Script tag -->
<script
type="module"
src="./o.min.js"
/>
<!-- Import syntax -->
<script type="text/javascript">
import './o.min.js';
</script>
```
##### CDN/Script
```html
<script
type="application/javascript"
src="https://cdn.jsdelivr.net/npm/o@2.0.0/dist/o.min.js"
/>
```
### Example usage
```javascript
const a = {
a: 1,
b: 2,
c: {
d: 3,
e: 4,
},
};
is(a); // => true
empty(a); // => false
has(a, 'a'); // => true
has(a, 'd'); // => false
has(a, 'c.d'); // => true
const b = set(a, 'f', 5);
get(b, 'f'); // => 5
```
For more examples and a list of all functions view the [documentation page](https://o.hammy2899.dev).
### Documentation
You can view the [documentation here](https://o.hammy2899.dev), docs are generated by [TypeDoc](https://typedoc.org).
### Contributing
All functions are documented with [TypeDoc](https://typedoc.org) and are fully commented explaining how they works. If you want to
contribute feel free to open a PR. When you open a PR please make sure `yarn test` and `yarn lint` both pass
with no errors and if any tests fail or any linting issues are raised please fix them accordingly.