o

common object helper functions

Usage no npm install needed!

<script type="module">
  import o from 'https://cdn.skypack.dev/o';
</script>

README

o Logo

o

common object helper functions written in TypeScript which can be used in NodeJS and the browser (supports ES6).

GitHub Actions Status Coverage Status npm version license JavaScript Style Guide

Installation

NPM

$ npm install o

Yarn

$ yarn add o

Usage

TypeScript

import o from 'o';
// or require specific functions
import { is, empty } from 'o';

NodeJS

const o = require('o');
// or require specific functions
const { is, empty } = require('o');

Browser

ES6
<!-- Script tag -->
<script
  type="module"
  src="./o.min.js"
/>

<!-- Import syntax -->
<script type="text/javascript">
  import './o.min.js';
</script>
CDN/Script
<script
  type="application/javascript"
  src="https://cdn.jsdelivr.net/npm/o@2.0.0/dist/o.min.js"
/>

Example usage

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.

Documentation

You can view the documentation here, docs are generated by TypeDoc.

Contributing

All functions are documented with TypeDoc 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.