Coder Social home page Coder Social logo

o's Introduction

o Logo

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 install o
$ 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/[email protected]/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.

o's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

o's Issues

Dependabot couldn't find the branch develop

Dependabot was set up to create pull requests against the branch develop, but couldn't find it.

If the branch has been permanently deleted you can update Dependabot's target branch from your dashboard.

You can mention @dependabot in the comments below to contact the Dependabot team.

diff function

Add diff function

Diff 2 objects

const a = {
  a: 1,
  b: 2,
  c: 3
};

const b = {
  a: 2,
  c: 3,
  d: 4
};

diff(a, b);
// {
//   "removal": {
//     "total": 1,
//     "keys": [
//       "b"
//     ]
//   },
//   "addition": {
//     "total": 1,
//     "keys": [
//       "d"
//     ]
//   },
//   "changes": {
//     "total": 1,
//     "keys": [
//       "a"
//     ]
//   },
//   "original": {
//     "a": 1,
//     "b": 2,
//     "c": 3
//   },
//   "changed": {
//     "a": 2,
//     "c": 3,
//     "d": 4
//   }
// }

Dependabot couldn't find the branch develop

Dependabot was set up to create pull requests against the branch develop, but couldn't find it.

If the branch has been permanently deleted you can update Dependabot's target branch from your dashboard.

You can mention @dependabot in the comments below to contact the Dependabot team.

convert function

Add convert function

Converts specified keys into something else

const a = {
  testa: 1,
  b: 2,
  c: 3,
};

convert(a, 'testa', 'a'); // => { a: 1, b: 2, c: 3 }
const a = {
  testa: 1,
  testb: 2,
  c: 3,
};

convert(a, [
  'testa',
  'testb',
], [
  'a',
  'b',
]); // => { a: 1, b: 2, c: 3 }

equal & deepEqual functions

Two functions to check if two or more objects are exactly the same.

  1. equal(object, ...compare)
  2. deepEqual(object, ...compare) (will check inner objects)

has undefined error

.has() throws an error when checking an object which doesn't have a property
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.