@lopatnov/join
Object join technics.
Install
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
enum JoinTypes {
none = 0b0000,
left = 0b1000,
right = 0b0001,
innerLeft = 0b0100,
innerRight = 0b0010,
innerJoin = none | innerLeft | innerRight | none,
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
function join(joinType?: JoinTypes) => (local function)<TContext>(context: TContext)
(local function)<TContext>(context: TContext) => (local function)<TJoinObject>(joinObject: TJoinObject)
(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);
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);
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);
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);
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