Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lopatnov/join

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lopatnov/join

Object join technics

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@lopatnov/join Twitter

npm NPM version GitHub issues GitHub forks GitHub stars License

build-and-test-package publish-npm-package Libraries.io dependency status for latest release

Patreon sobe.ru LinkedIn

Object join technics.

Install

https://nodei.co/npm/@lopatnov/join.png?downloads=true&downloadRank=true&stars=true

npm install @lopatnov/join

Browser

<script src="https://lopatnov.github.io/join/dist/join.min.js"></script>

Import package to the project

TypeScript

import { join, JoinTypes } from "@lopatnov/join";

JavaScript

var library = require("@lopatnov/join");
var join = library.join;
var JoinTypes = library.JoinTypes;

Join Types

Join Types

enum JoinTypes {
  none       = 0b0000,
  left       = 0b1000, // take unique left object properties
  right      = 0b0001, // take unique right object properties
  innerLeft  = 0b0100, // take non-unique (inner) properties from left object
  innerRight = 0b0010, // take non-unique (inner) properties from right object
  innerJoin  = none | innerLeft | innerRight | none, // innerLeft + innerRight = deep merge inner join of two objects
  leftJoin   = left | innerLeft | innerRight | none,
  rightJoin  = none | innerLeft | innerRight | right,
  fullJoin   = left | innerLeft | innerRight | right,
  expand     = left | none      | innerRight | right
}

JoinTypes.expand is default join type

How to use

// 1. Set join Type
function join(joinType?: JoinTypes) => (local function)<TContext>(context: TContext)
// 2. Set context (left object)
(local function)<TContext>(context: TContext) => (local function)<TJoinObject>(joinObject: TJoinObject)
// 3. Set join object (right object) and gets result
(local function)<TJoinObject>(joinObject: TJoinObject): TContext & TJoinObject

As three separate operations

Right join sample
const rightJoin = join(JoinTypes.right);

const contextJoinBy = rightJoin({
  sample1: "One",
  sample2: "Two",
  sample3: "Three",
});

const result = contextJoinBy({
  sample2: "Dos",
  sample3: "Tres",
  sample4: "Quatro",
});

console.log(result); // { sample4: "Quatro" }
Left join sample
const leftJoin = join(JoinTypes.left);

const contextJoinBy = leftJoin({
  sample1: "One",
  sample2: "Two",
  sample3: "Three",
});

const result = contextJoinBy({
  sample2: "Dos",
  sample3: "Tres",
  sample4: "Quatro",
});

console.log(result); // { sample1: "One" }
Complex join sample
const complexJoin = join(JoinTypes.left | JoinTypes.innerLeft | JoinTypes.right);

const contextJoinBy = complexJoin({
  sample1: "One",
  sample2: "Two",
  sample3: "Three",
});

const result = contextJoinBy({
  sample2: "Dos",
  sample3: "Tres",
  sample4: "Quatro",
});

console.log(result); // {sample1: "One", sample2: "Two", sample3: "Three", sample4: "Quatro"}
Inner join sample
const result = join(JoinTypes.innerJoin)({
  sample1: "One",
  sample2: "Two",
  sample3: {
    smile: "cheese",
  },
})({
  sample2: "Dos",
  sample3: {
    sorrir: "queijo",
  },
  sample4: "Quatro",
});

console.log(result); // {sample2: "Dos", sample3: {smile: "cheese", sorrir: "queijo"}}

Demo

See, how it's working: https://runkit.com/lopatnov/join

Test it with a runkit: https://npm.runkit.com/@lopatnov/join

Rights and Agreements

License Apache-2.0

Copyright 2020–2021 Oleksandr Lopatnov

Keywords

FAQs

Package last updated on 03 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc