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

liftjs

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

liftjs - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

2

npm/lift-min.js

@@ -1,1 +0,1 @@

/* jshint -W097, esversion: 6, strict: true, node: true *//* global module */'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var isFunction=function isFunction(func){return!!(func&&func.constructor&&func.call&&func.apply)};var idFunction=function idFunction(value){return value};var isNone=function isNone(value){return value===null||value===undefined};var Curry=exports.Curry=function Curry(func){for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return args.length>=func.length?func.apply(undefined,args):Curry.bind.apply(Curry,[undefined,func].concat(args))};var Monad=exports.Monad=function Monad(modifier){var prototype=Object.create({is_monad:true});var unit=function unit(value){var run=function run(value,func,args){return isFunction(func)?func.apply(undefined,[value].concat(_toConsumableArray(args||[]))):monad};prototype.bind=function(func,args){return run(value,func,args)};var monad=Object.create(prototype);monad.of=monad.pure=function(value){var m=run(value,idFunction);return m&&m.is_monad?m:unit(m)};monad.get=function(){return value};monad.chain=monad.flatMap=monad.bind;monad.map=function(func){return unit(func(value))};monad.join=function(){return monad.bind(idFunction)};monad.toMaybe=function(){return Maybe(value)};monad.run=function(func){run(value,func);return monad};if(isFunction(modifier)){modifier(monad,value)}return monad};var apply=function apply(prototype,name,func,unit){prototype[name]=func;return unit};unit.lift=function(name,func){return apply(prototype,name,function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}var m=prototype.bind(func,args);return m&&m.is_monad?m:unit(m)},unit)};unit.lift_value=function(name,func){return apply(prototype,name,function(){for(var _len3=arguments.length,args=Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3]}return prototype.bind(func,args)},unit)};unit.method=function(name,func){return apply(prototype,name,func,unit)};return unit};var Just=exports.Just=Monad();var Maybe=exports.Maybe=Monad(function(monad,value){var valueIsNone=isNone(value);monad.none=monad.nothing=function(){return Maybe()};monad.isNone=monad.isNothing=function(){return valueIsNone};monad.isSome=monad.isJust=function(){return!valueIsNone};monad.orSome=monad.orJust=function(orValue){return valueIsNone?orValue:value};monad.orElse=function(orMonad){return valueIsNone?orMonad:monad};monad.bind=valueIsNone?function(){return monad}:monad.bind;monad.map=valueIsNone?function(){return monad}:monad.map;var run=monad.run;monad.run=function(func){(valueIsNone?function(){}:run)(value,func);return monad}});var successFactory=function successFactory(value){return Success(value)};var failFactory=function failFactory(value){return Fail(value)};var validFunctions=function validFunctions(monad,value){monad.success=monad.s=successFactory;monad.fail=monad.f=failFactory;monad.isSuccess=function(){return monad.isSuccessValue};monad.isFail=function(){return!monad.isSuccessValue};monad.ap=function(validationWithFn){return monad.isSuccess()?validationWithFn.map(function(fn){return fn(value)}):validationWithFn.isFail()?monad.fail([].concat(value,validationWithFn.fail())):monad}};var Success=Monad(function(monad,value){monad.isSuccessValue=true;validFunctions(monad,value)});var Fail=Monad(function(monad,value){monad.isSuccessValue=false;validFunctions(monad,value)});var Valid=exports.Valid=Monad(function(monad,value){validFunctions(monad,value)});Valid.success=Valid.s=successFactory;Valid.fail=Valid.f=failFactory;
/* jshint -W097, esversion: 6, strict: true, node: true *//* global module */'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var isFunction=function isFunction(func){return!!(func&&func.constructor&&func.call&&func.apply)};var idFunction=function idFunction(value){return value};var isNone=function isNone(value){return value===null||value===undefined};var Curry=exports.Curry=function Curry(func){for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return args.length>=func.length?func.apply(undefined,args):Curry.bind.apply(Curry,[undefined,func].concat(args))};var Monad=exports.Monad=function Monad(modifier){var prototype=Object.create({is_monad:true});var unit=function unit(value){var run=function run(value,func,args){return isFunction(func)?func.apply(undefined,[value].concat(_toConsumableArray(args||[]))):monad};prototype.bind=function(func,args){return run(value,func,args)};var monad=Object.create(prototype);monad.of=function(value){var m=run(value,idFunction);return m&&m.is_monad?m:unit(m)};monad.get=monad.g=function(){return value};monad.chain=monad.c=monad.bind;monad.map=monad.m=function(func){return unit(func(value))};monad.join=monad.j=function(){return monad.bind(idFunction)};monad.toMaybe=function(){return Maybe(value)};monad.run=monad.r=function(func){run(value,func);return monad};if(isFunction(modifier)){modifier(monad,value)}return monad};var apply=function apply(prototype,name,func,unit){prototype[name]=func;return unit};unit.lift=unit.l=function(name,func){return apply(prototype,name,function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2]}var m=prototype.bind(func,args);return m&&m.is_monad?m:unit(m)},unit)};unit.liftValue=unit.lv=function(name,func){return apply(prototype,name,function(){for(var _len3=arguments.length,args=Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3]}return prototype.bind(func,args)},unit)};unit.method=unit.m=function(name,func){return apply(prototype,name,func,unit)};return unit};var Just=exports.Just=Monad();var Maybe=exports.Maybe=Monad(function(monad,value){var valueIsNone=isNone(value);monad.isNothing=monad.n=function(){return valueIsNone};monad.is=monad.i=function(){return!valueIsNone};monad.or=monad.o=function(orValue){return valueIsNone?orValue:value};monad.else=monad.e=function(orMonad){return valueIsNone?orMonad:monad};monad.bind=valueIsNone?function(){return monad}:monad.bind;monad.map=valueIsNone?function(){return monad}:monad.map;var run=monad.run;monad.run=function(func){(valueIsNone?function(){}:run)(value,func);return monad}});var successFactory=function successFactory(value){return Success(value)};var failFactory=function failFactory(value){return Fail(value)};var validFunctions=function validFunctions(monad,value){monad.success=monad.s=successFactory;monad.fail=monad.f=failFactory;monad.isSuccess=function(){return monad.isSuccessValue};monad.isFail=function(){return!monad.isSuccessValue};monad.ap=function(validationWithFn){return monad.isSuccess()?validationWithFn.map(function(fn){return fn(value)}):validationWithFn.isFail()?monad.fail([].concat(value,validationWithFn.fail())):monad}};var Success=Monad(function(monad,value){monad.isSuccessValue=true;validFunctions(monad,value)});var Fail=Monad(function(monad,value){monad.isSuccessValue=false;validFunctions(monad,value)});var Valid=exports.Valid=Monad(function(monad,value){validFunctions(monad,value)});Valid.success=Valid.s=successFactory;Valid.fail=Valid.f=failFactory;

@@ -28,12 +28,12 @@ /* jshint -W097, esversion: 6, strict: true, node: true */

const monad = Object.create(prototype);
monad.of = monad.pure = (value) => {
monad.of = (value) => {
const m = run(value, idFunction);
return m && m.is_monad ? m : unit(m);
};
monad.get = () => value;
monad.chain = monad.flatMap = monad.bind;
monad.map = (func) => unit(func(value));
monad.join = () => monad.bind(idFunction);
monad.get = monad.g = () => value;
monad.chain = monad.c = monad.bind;
monad.map = monad.m = (func) => unit(func(value));
monad.join = monad.j = () => monad.bind(idFunction);
monad.toMaybe = () => Maybe(value);
monad.run = (func) => { run(value, func); return monad; };
monad.run = monad.r = (func) => { run(value, func); return monad; };

@@ -51,3 +51,3 @@ if (isFunction(modifier)) {

unit.lift = (name, func) => apply(prototype, name, (...args) => {
unit.lift = unit.l = (name, func) => apply(prototype, name, (...args) => {
const m = prototype.bind(func, args);

@@ -57,5 +57,5 @@ return (m && m.is_monad) ? m : unit(m);

unit.lift_value = (name, func) => apply(prototype, name, (...args) => prototype.bind(func, args), unit);
unit.liftValue = unit.lv = (name, func) => apply(prototype, name, (...args) => prototype.bind(func, args), unit);
unit.method = (name, func) => apply(prototype, name, func, unit);
unit.method = unit.m = (name, func) => apply(prototype, name, func, unit);

@@ -69,7 +69,6 @@ return unit;

const valueIsNone = isNone(value);
monad.none = monad.nothing = () => Maybe();
monad.isNone = monad.isNothing = () => valueIsNone;
monad.isSome = monad.isJust = () => !valueIsNone;
monad.orSome = monad.orJust = (orValue) => valueIsNone ? orValue : value;
monad.orElse = (orMonad) => valueIsNone ? orMonad : monad;
monad.isNothing = monad.n = () => valueIsNone;
monad.is = monad.i = () => !valueIsNone;
monad.or = monad.o = (orValue) => valueIsNone ? orValue : value;
monad.else = monad.e = (orMonad) => valueIsNone ? orMonad : monad;
monad.bind = valueIsNone ? () => monad : monad.bind;

@@ -76,0 +75,0 @@ monad.map = valueIsNone ? () => monad : monad.map;

{
"name": "liftjs",
"version": "1.1.5",
"version": "1.2.0",
"homepage": "https://github.com/atomable/lift.js/",

@@ -5,0 +5,0 @@ "description": "lift.js is a compact monad opinionated javascript library",

@@ -10,4 +10,9 @@ # lift.js — Write less code.

npm install liftjs
yarn add liftjs
```
## Source code | fork | pull request | issues
https://github.com/atomable/lift.js
#### importing

@@ -28,5 +33,19 @@

## Monad
## Monad factory
```
Monad(modifier[monad, value]: null) : unit
```
```javascript
Monad(modifier) : unit
const Person = Monad();
const person = Person({ firstname: 'Bill', lastname: 'Murray' });
// with a modifier
const doubleIt = Monad((monad, value) => {
monad.double = value * 2;
});
const two = doubleIt(2);
two.double();
// 4
```

@@ -67,6 +86,6 @@

### bind, alias: chain flatMap
```javascript
bind(func, args)
### bind, alias: chain
```
Monad[A].bind[func[A] : Monad[B], args] : Monad[B]
```
```javascript

@@ -77,6 +96,7 @@ const justWithValue = Just(5).bind((value)=> Just(value));

```
### of, alias: pure
```javascript
of(value)
### of
```
Monad[A].of[B] : Monad[B]
```
```javascript

@@ -89,15 +109,16 @@ const justWithValue = Just(5).of(6);

```
### get
```javascript
get()
```
Monad[A].get[] : A
```
```javascript
const value = Just(5).get();
//5
// 5
```
### map
```javascript
map(func)
```
Monad[A].map(func[A] : B ) : Monad[B]
```
```javascript

@@ -109,5 +130,5 @@ const justWithValue = Just(7).map(value => value * 2);

### join
```javascript
join()
```
Monad[Monad[A]].join() : Monad[A]
```
```javascript

@@ -118,5 +139,5 @@ const justWithValue = Just(Just(5)).join()

### toMaybe
```javascript
toMaybe()
```
Monad[A].toMaybe() : Maybe[A]
```
```javascript

@@ -128,5 +149,5 @@ const maybeWithValue = Just(5).toMaybe();

### run
```javascript
run(func)
```
Monad[A].run(func[A] : null): Monad[A]
```
```javascript

@@ -139,59 +160,62 @@ Just(5).run(value => console.log(value));

### none, alias: nothing
```javascript
none()
###
```
Maybe(A) : Maybe[A]
```
```javascript
const maybeWithValue = Maybe().none()
const maybeWithoutValue = Maybe()
// Maybe[]
const maybeWithValue = Maybe().nothing()
// Maybe[]
const maybeWithValue = Maybe(2)
// Maybe[2]
const maybeWithValue = Maybe()
const maybeWithoutValue = Maybe(undefined)
// Maybe[]
const maybeWithValue = Maybe(undefined)
const maybeWithoutValue = Maybe(null)
// Maybe[]
const maybeWithValue = Maybe(null)
// Maybe[]
```
### isNone, alias: isNothing
```javascript
isNone()
### isNothing, alias: n
```
Maybe[A].isNothing() : boolean
```
```javascript
const value = Maybe(5).isNone();
const value = Maybe(5).isNothing();
// false
const value = Maybe(5).n();
// false
```
### isJust, alias: orSome
### is, alias: i
```javascript
isJust()
Maybe[A].is() : boolean
```
```javascript
const value = Maybe(5).isJust();
const value = Maybe(5).is();
// true
const value = Maybe(5).i();
// true
```
### orJust, alias: orSome
```javascript
orJust()
### or, alias: o
```
Maybe[A].or(B) : A or B
```
```javascript
const maybeWithValue = Maybe().orJust(15);
// Maybe[15]
const maybeWithValue = Maybe().or(15);
// 15
```
### orElse
```javascript
orElse(monad)
### else, alias; e
```
Maybe[A].else(Monad[B]) : Maybe[A] or Monad[B]
```
```javascript
const maybeWithValue = Maybe(5).orElse(Maybe(15));
const maybeWithValue = Maybe(5).else(Maybe(15));
// Maybe[5]
const maybeWithValue = Maybe().orElse(Just(15));
const maybeWithValue = Maybe().e(Just(15));
// Just[15]

@@ -209,11 +233,14 @@ ```

- document `method` function
- add List monad
- `ap` function just `Just` and `Maybe` & tests
- 1 character alias for all methods that are more than 3 characters. Per example: `Just(5).b(v=> Just(v)).m(v => v * 2)`
- tests for lift functions
## Change Log
- 1.2.0 : I've changed the Maybe api qute a bit, orSome, orElse, none, are replaced.
## Links
- [npm](https://www.npmjs.com/package/liftjs)
- [atomable](https://twitter.com/atomable)
- [atomable](http://www.atomable.io)
- [@pre63](http://twitter.com/pre63)

@@ -220,0 +247,0 @@

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