https://github.com/lopatnov/join
Object join technics.
https://github.com/lopatnov/join
join object typescript-library
Last synced: 3 months ago
JSON representation
Object join technics.
- Host: GitHub
- URL: https://github.com/lopatnov/join
- Owner: lopatnov
- License: apache-2.0
- Created: 2020-08-08T23:23:32.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-05T10:07:56.000Z (over 2 years ago)
- Last Synced: 2024-04-24T20:14:53.452Z (about 1 year ago)
- Topics: join, object, typescript-library
- Language: TypeScript
- Homepage: https://lopatnov.github.io/join/
- Size: 596 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# @lopatnov/join [](https://twitter.com/intent/tweet?text=I%20want%20to%20share%20TypeScript%20library:&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fjoin)
[](https://www.npmjs.com/package/@lopatnov/join)
[](https://www.npmjs.com/package/@lopatnov/join)
[](https://github.com/lopatnov/join/issues)
[](https://github.com/lopatnov/join/network)
[](https://github.com/lopatnov/join/stargazers)
[](https://github.com/lopatnov/join/blob/master/LICENSE)[](https://github.com/lopatnov/join/tree/master/tests)
[](https://github.com/lopatnov/join/releases)
[](https://www.npmjs.com/package/@lopatnov/join?activeTab=dependencies)[](https://www.patreon.com/lopatnov)
[](https://sobe.ru/na/tech_knigi)
[](https://www.linkedin.com/in/lopatnov/)Object join technics.
## Install
[](https://www.npmjs.com/package/@lopatnov/join)
```shell
npm install @lopatnov/join
```[Browser](https://lopatnov.github.io/join/dist/join.js)
```html
```
## Import package to the project
### TypeScript
```typescript
import { join, JoinTypes } from "@lopatnov/join";
```### JavaScript
```javascript
var library = require("@lopatnov/join");
var join = library.join;
var JoinTypes = library.JoinTypes;
```## Join Types

```typescript
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
```ts
// 1. Set join Type
function join(joinType?: JoinTypes) => (local function)(context: TContext)
``````ts
// 2. Set context (left object)
(local function)(context: TContext) => (local function)(joinObject: TJoinObject)
``````ts
// 3. Set join object (right object) and gets result
(local function)(joinObject: TJoinObject): TContext & TJoinObject
```### As three separate operations
#### Right join sample
```typescript
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
```typescript
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
```typescript
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
```typescript
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](https://runkit.com/lopatnov/join)
Test it with a runkit: [https://npm.runkit.com/@lopatnov/join](https://npm.runkit.com/%40lopatnov%2Fjoin)
## Rights and Agreements
License [Apache-2.0](https://github.com/lopatnov/join/blob/master/LICENSE)
Copyright 2020–2021 Oleksandr Lopatnov