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 - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

1

dist/join.js

@@ -10,2 +10,3 @@ (function (global, factory) {

*/
exports.JoinTypes = void 0;
(function (JoinTypes) {

@@ -12,0 +13,0 @@ JoinTypes[JoinTypes["none"] = 0] = "none";

2

dist/join.min.js

@@ -7,3 +7,3 @@ (function (global, factory) {

function getPartNames(e,n){var t=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(n),i=t.filter((function(e){return r.indexOf(e)>-1}));return t=t.filter((function(e){return i.indexOf(e)<0})),r=r.filter((function(e){return i.indexOf(e)<0})),{left:t,middle:i,right:r}}function clearNames(e,n){for(var t=0;t<n.length;t++)delete e[n[t]];}function attach(e,n,t){if(e!==n)for(var r=0;r<t.length;r++){var i=Object.getOwnPropertyDescriptor(n,t[r]);Object.defineProperty(e,t[r],i);}}function isFunction(e){return "function"==typeof e&&"number"!=typeof e.nodeType}function isPlainObject(e){var n,t,r=Object.prototype.toString,i=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,c=o.toString,f=c.call(Object);return !(!e||"[object Object]"!==r.call(e))&&(!(n=i(e))||"function"==typeof(t=o.call(n,"constructor")&&n.constructor)&&c.call(t)===f)}function extend(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t,r,i,o,c,f,a=arguments[0]||{},s=1,l=arguments.length,p=!1;for("boolean"==typeof a&&(p=a,a=arguments[s]||{},s++),"object"==typeof a||isFunction(a)||(a={}),s===l&&(a={},s--);s<l;s++)if(null!=(t=arguments[s]))for(r in t)o=t[r],"__proto__"!==r&&a!==o&&(p&&o&&(isPlainObject(o)||(c=Array.isArray(o)))?(i=a[r],f=c&&!Array.isArray(i)?[]:c||isPlainObject(i)?i:{},c=!1,a[r]=extend(p,f,o)):void 0!==o&&(a[r]=o));return a}function mergeObjects(e,n,t){if(e!==n)for(var r=0;r<t.length;r++)if(null===n[t[r]]||["string","boolean","null","undefined","symbol","number","bigint","regexp"].indexOf((typeof n[t[r]]).toLowerCase())>-1){var i=Object.getOwnPropertyDescriptor(n,t[r]);Object.defineProperty(e,t[r],i);}else e[t[r]]=extend(!0,e[t[r]],n[t[r]]);}function joinSource(e,n){if(void 0===n&&(n=exports.JoinTypes.expand),(15|n)<=0)throw new Error("Invalid join type. Please select join type");if(n===(exports.JoinTypes.left|exports.JoinTypes.innerLeft))return this;var t=getPartNames(this,e);switch(n&exports.JoinTypes.innerJoin){case exports.JoinTypes.none:clearNames(this,t.middle);break;case exports.JoinTypes.innerLeft:break;case exports.JoinTypes.innerRight:attach(this,e,t.middle);break;case exports.JoinTypes.innerJoin:mergeObjects(this,e,t.middle);}return (n&exports.JoinTypes.left)!==exports.JoinTypes.left&&clearNames(this,t.left),(n&exports.JoinTypes.right)===exports.JoinTypes.right&&attach(this,e,t.right),this}!function(e){e[e.none=0]="none",e[e.left=8]="left",e[e.right=1]="right",e[e.innerLeft=4]="innerLeft",e[e.innerRight=2]="innerRight",e[e.innerJoin=6]="innerJoin",e[e.leftJoin=14]="leftJoin",e[e.rightJoin=7]="rightJoin",e[e.fullJoin=15]="fullJoin",e[e.expand=11]="expand";}(exports.JoinTypes||(exports.JoinTypes={}));function join(e){if(void 0===e&&(e=exports.JoinTypes.expand),!e)throw new Error("Unknown join type");return function(n){return function(t){return joinSource.call(n,t,e)}}}
exports.JoinTypes = void 0;function getPartNames(e,n){var t=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(n),i=t.filter((function(e){return r.indexOf(e)>-1}));return t=t.filter((function(e){return i.indexOf(e)<0})),r=r.filter((function(e){return i.indexOf(e)<0})),{left:t,middle:i,right:r}}function clearNames(e,n){for(var t=0;t<n.length;t++)delete e[n[t]];}function attach(e,n,t){if(e!==n)for(var r=0;r<t.length;r++){var i=Object.getOwnPropertyDescriptor(n,t[r]);Object.defineProperty(e,t[r],i);}}function isFunction(e){return "function"==typeof e&&"number"!=typeof e.nodeType}function isPlainObject(e){var n,t,r=Object.prototype.toString,i=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,c=o.toString,f=c.call(Object);return !(!e||"[object Object]"!==r.call(e))&&(!(n=i(e))||"function"==typeof(t=o.call(n,"constructor")&&n.constructor)&&c.call(t)===f)}function extend(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t,r,i,o,c,f,a=arguments[0]||{},s=1,l=arguments.length,p=!1;for("boolean"==typeof a&&(p=a,a=arguments[s]||{},s++),"object"==typeof a||isFunction(a)||(a={}),s===l&&(a={},s--);s<l;s++)if(null!=(t=arguments[s]))for(r in t)o=t[r],"__proto__"!==r&&a!==o&&(p&&o&&(isPlainObject(o)||(c=Array.isArray(o)))?(i=a[r],f=c&&!Array.isArray(i)?[]:c||isPlainObject(i)?i:{},c=!1,a[r]=extend(p,f,o)):void 0!==o&&(a[r]=o));return a}function mergeObjects(e,n,t){if(e!==n)for(var r=0;r<t.length;r++)if(null===n[t[r]]||["string","boolean","null","undefined","symbol","number","bigint","regexp"].indexOf((typeof n[t[r]]).toLowerCase())>-1){var i=Object.getOwnPropertyDescriptor(n,t[r]);Object.defineProperty(e,t[r],i);}else e[t[r]]=extend(!0,e[t[r]],n[t[r]]);}function joinSource(e,n){if(void 0===n&&(n=exports.JoinTypes.expand),(15|n)<=0)throw new Error("Invalid join type. Please select join type");if(n===(exports.JoinTypes.left|exports.JoinTypes.innerLeft))return this;var t=getPartNames(this,e);switch(n&exports.JoinTypes.innerJoin){case exports.JoinTypes.none:clearNames(this,t.middle);break;case exports.JoinTypes.innerLeft:break;case exports.JoinTypes.innerRight:attach(this,e,t.middle);break;case exports.JoinTypes.innerJoin:mergeObjects(this,e,t.middle);}return (n&exports.JoinTypes.left)!==exports.JoinTypes.left&&clearNames(this,t.left),(n&exports.JoinTypes.right)===exports.JoinTypes.right&&attach(this,e,t.right),this}!function(e){e[e.none=0]="none",e[e.left=8]="left",e[e.right=1]="right",e[e.innerLeft=4]="innerLeft",e[e.innerRight=2]="innerRight",e[e.innerJoin=6]="innerJoin",e[e.leftJoin=14]="leftJoin",e[e.rightJoin=7]="rightJoin",e[e.fullJoin=15]="fullJoin",e[e.expand=11]="expand";}(exports.JoinTypes||(exports.JoinTypes={}));function join(e){if(void 0===e&&(e=exports.JoinTypes.expand),!e)throw new Error("Unknown join type");return function(n){return function(t){return joinSource.call(n,t,e)}}}

@@ -10,0 +10,0 @@ exports.join = join;

{
"name": "@lopatnov/join",
"version": "1.0.1",
"license": "Apache-2.0",
"author": "lopatnov",
"description": "Object join technics",
"homepage": "https://lopatnov.github.io/join/",
"keywords": [
"TypeScript",
"Library",
"typescript-library",
"join"
],
"umdName": "join",
"libraryFile": "join",
"main": "dist/join.js",
"module": "dist/join.es.js",
"types": "dist/join.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/lopatnov/join.git"
},
"bugs": {
"url": "https://github.com/lopatnov/join/issues"
},
"scripts": {
"build": "rollup -c rollup.config.ts",
"watch": "rollup -cw rollup.config.ts",
"configure-npm": "node ./set-registry.js -s https://registry.npmjs.org",
"configure-gpr": "node ./set-registry.js -s https://npm.pkg.github.com",
"test": "jest"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"devDependencies": {
"@lopatnov/rollup-plugin-uglify": "^2.1.0",
"@types/jest": "^26.0.9",
"@types/typescript": "^2.0.0",
"jest": "^26.2.2",
"jest-config": "^26.2.2",
"rollup": "^2.23.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup-plugin-typescript2": "^0.27.2",
"terser": "^5.0.0",
"ts-jest": "^26.1.4",
"typescript": "^3.9.7"
}
}
"name": "@lopatnov/join",
"version": "1.1.0",
"license": "Apache-2.0",
"author": "lopatnov",
"description": "Object join technics",
"homepage": "https://lopatnov.github.io/join/",
"keywords": [
"TypeScript",
"Library",
"typescript-library",
"join"
],
"umdName": "join",
"libraryFile": "join",
"main": "dist/join.js",
"module": "dist/join.es.js",
"types": "dist/join.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/lopatnov/join.git"
},
"bugs": {
"url": "https://github.com/lopatnov/join/issues"
},
"scripts": {
"build": "rollup -c rollup.config.ts",
"watch": "rollup -cw rollup.config.ts",
"configure-npm": "node ./set-registry.js -s https://registry.npmjs.org",
"configure-gpr": "node ./set-registry.js -s https://npm.pkg.github.com",
"test": "jest"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@lopatnov/rollup-plugin-uglify": "^2.1.0",
"@types/jest": "^26.0.23",
"@types/typescript": "^2.0.0",
"jest": "^27.0.3",
"jest-config": "^27.0.3",
"rollup": "^2.50.5",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.30.0",
"terser": "^5.7.0",
"ts-jest": "^27.0.2",
"typescript": "^4.3.2"
}
}
# @lopatnov/join
[![npm](https://img.shields.io/npm/dt/@lopatnov/join)](https://www.npmjs.com/package/@lopatnov/join)
[![NPM version](https://badge.fury.io/js/%40lopatnov%2Fjoin.svg)](https://www.npmjs.com/package/@lopatnov/join)

@@ -14,4 +15,5 @@ [![GitHub issues](https://img.shields.io/github/issues/lopatnov/join)](https://github.com/lopatnov/join/issues)

[![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fjoin)](https://twitter.com/intent/tweet?text=I%20want%20to%20share%20TypeScript%20library:&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fjoin)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-lopatnov-informational?style=social&logo=linkedin)](https://www.linkedin.com/in/lopatnov/)
The TypeScript library template.
Object join technics.

@@ -48,4 +50,40 @@ ## Install

## Join Types
![Join Types](./img/join-types.png)
```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)<TContext>(context: TContext)
```
```ts
// 2. Set context (left object)
(local function)<TContext>(context: TContext) => (local function)<TJoinObject>(joinObject: TJoinObject)
```
```ts
// 3. Set join object (right object) and gets result
(local function)<TJoinObject>(joinObject: TJoinObject): TContext & TJoinObject
```
### As three separate operations

@@ -56,3 +94,3 @@

const joinObject = rightJoin({
const contextJoinBy = rightJoin({
sample1: "One",

@@ -63,3 +101,3 @@ sample2: "Two",

const m = joinObject({
const result = contextJoinBy({
sample2: "Dos",

@@ -69,10 +107,46 @@ sample3: "Tres",

});
console.log(result); // { sample4: "Quatro" }
```
### As a function
```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" }
```
```typescript
const c = join(JoinTypes.innerJoin)({
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"}
```
```typescript
const result = join(JoinTypes.innerJoin)({
sample1: "One",
sample2: "Two",
sample3: {

@@ -88,2 +162,4 @@ smile: "cheese",

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

@@ -101,2 +177,2 @@

Copyright 2020 Oleksandr Lopatnov
Copyright 2020–2021 Oleksandr Lopatnov

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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