Socket
Socket
Sign inDemoInstall

monocle-ts

Package Overview
Dependencies
1
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 2.1.1

5

CHANGELOG.md

@@ -16,2 +16,7 @@ # Changelog

# 2.1.1
- **Bug Fix**
- fix `Optional.fromPath`, #122 (@mikearnaldi)
# 2.1.0

@@ -18,0 +23,0 @@

52

es6/index.d.ts

@@ -21,6 +21,21 @@ /**

readonly reverseGet: (a: A) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Iso';
/**
* @since 1.0.0
*/
readonly unwrap: (s: S) => A;
/**
* @since 1.0.0
*/
readonly to: (s: S) => A;
/**
* @since 1.0.0
*/
readonly wrap: (a: A) => S;
/**
* @since 1.0.0
*/
readonly from: (a: A) => S;

@@ -155,2 +170,5 @@ constructor(get: (s: S) => A, reverseGet: (a: A) => S);

readonly set: (a: A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Lens';

@@ -351,2 +369,5 @@ constructor(get: (s: S) => A, set: (a: A) => (s: S) => S);

readonly reverseGet: (a: A) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Prism';

@@ -464,7 +485,7 @@ constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S);

export interface OptionalFromPath<S> {
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>[K3]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<S[K1]>[K2]>;
<K1 extends keyof S>(path: [K1]): Optional<S, S[K1]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>>;
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>;
}

@@ -482,2 +503,5 @@ /**

readonly set: (a: A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Optional';

@@ -664,2 +688,5 @@ constructor(getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S);

readonly modifyF: ModifyF<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'Traversal';

@@ -772,2 +799,5 @@ constructor(modifyF: ModifyF<S, A>);

readonly at: (i: I) => Lens<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'At';

@@ -787,2 +817,5 @@ constructor(at: (i: I) => Lens<S, A>);

readonly index: (i: I) => Optional<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'Index';

@@ -806,2 +839,5 @@ constructor(index: (i: I) => Optional<S, A>);

readonly get: (s: S) => A;
/**
* @since 1.0.0
*/
readonly _tag: 'Getter';

@@ -869,2 +905,5 @@ constructor(get: (s: S) => A);

readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M;
/**
* @since 1.0.0
*/
readonly _tag: 'Fold';

@@ -958,2 +997,5 @@ /**

readonly modify: (f: (a: A) => A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Setter';

@@ -960,0 +1002,0 @@ constructor(modify: (f: (a: A) => A) => (s: S) => S);

72

es6/index.js

@@ -22,6 +22,21 @@ import { monoidAll, monoidAny } from 'fp-ts/es6/Monoid';

this.reverseGet = reverseGet;
/**
* @since 1.0.0
*/
this._tag = 'Iso';
/**
* @since 1.0.0
*/
this.unwrap = this.get;
/**
* @since 1.0.0
*/
this.to = this.get;
/**
* @since 1.0.0
*/
this.wrap = this.reverseGet;
/**
* @since 1.0.0
*/
this.from = this.reverseGet;

@@ -88,3 +103,3 @@ }

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -197,2 +212,5 @@ /**

this.set = set;
/**
* @since 1.0.0
*/
this._tag = 'Lens';

@@ -249,3 +267,5 @@ }

Lens.fromProp = function () {
return function (prop) { return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; }); };
return function (prop) {
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; });
};
};

@@ -389,3 +409,3 @@ /**

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -479,2 +499,5 @@ /**

this.reverseGet = reverseGet;
/**
* @since 1.0.0
*/
this._tag = 'Prism';

@@ -570,8 +593,3 @@ }

var oa = _this.getOption(s);
if (isNone(oa)) {
return M.empty;
}
else {
return f(oa.value);
}
return isNone(oa) ? M.empty : f(oa.value);
}; }; });

@@ -668,2 +686,5 @@ };

this.set = set;
/**
* @since 1.0.0
*/
this._tag = 'Optional';

@@ -740,3 +761,5 @@ }

Optional.fromNullableProp = function () {
return function (k) { return new Optional(function (s) { return fromNullable(s[k]); }, function (a) { return function (s) { return (s[k] == null ? s : update(s, k, a)); }; }); };
return function (k) {
return new Optional(function (s) { return fromNullable(s[k]); }, function (a) { return function (s) { return (s[k] == null ? s : update(s, k, a)); }; });
};
};

@@ -819,8 +842,3 @@ /**

var oa = _this.getOption(s);
if (isNone(oa)) {
return M.empty;
}
else {
return f(oa.value);
}
return isNone(oa) ? M.empty : f(oa.value);
}; }; });

@@ -921,2 +939,5 @@ };

this.modifyF = modifyF;
/**
* @since 1.0.0
*/
this._tag = 'Traversal';

@@ -946,3 +967,3 @@ }

var _this = this;
return new Fold(function (M) { return function (f) { return function (s) { return _this.modifyF(getApplicative(M))(function (a) { return make(f(a)); })(s); }; }; });
return new Fold(function (M) { return function (f) { return _this.modifyF(getApplicative(M))(function (a) { return make(f(a)); }); }; });
};

@@ -1040,2 +1061,5 @@ /**

this.at = at;
/**
* @since 1.0.0
*/
this._tag = 'At';

@@ -1061,2 +1085,5 @@ }

this.index = index;
/**
* @since 1.0.0
*/
this._tag = 'Index';

@@ -1088,2 +1115,5 @@ }

this.get = get;
/**
* @since 1.0.0
*/
this._tag = 'Getter';

@@ -1098,3 +1128,3 @@ }

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -1175,2 +1205,5 @@ /**

this.foldMap = foldMap;
/**
* @since 1.0.0
*/
this._tag = 'Fold';

@@ -1267,2 +1300,5 @@ this.getAll = foldMap(getMonoid())(function (a) { return [a]; });

this.modify = modify;
/**
* @since 1.0.0
*/
this._tag = 'Setter';

@@ -1269,0 +1305,0 @@ }

@@ -21,6 +21,21 @@ /**

readonly reverseGet: (a: A) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Iso';
/**
* @since 1.0.0
*/
readonly unwrap: (s: S) => A;
/**
* @since 1.0.0
*/
readonly to: (s: S) => A;
/**
* @since 1.0.0
*/
readonly wrap: (a: A) => S;
/**
* @since 1.0.0
*/
readonly from: (a: A) => S;

@@ -155,2 +170,5 @@ constructor(get: (s: S) => A, reverseGet: (a: A) => S);

readonly set: (a: A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Lens';

@@ -351,2 +369,5 @@ constructor(get: (s: S) => A, set: (a: A) => (s: S) => S);

readonly reverseGet: (a: A) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Prism';

@@ -464,7 +485,7 @@ constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S);

export interface OptionalFromPath<S> {
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>[K3]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<S[K1]>[K2]>;
<K1 extends keyof S>(path: [K1]): Optional<S, S[K1]>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>;
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>>;
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>;
}

@@ -482,2 +503,5 @@ /**

readonly set: (a: A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Optional';

@@ -664,2 +688,5 @@ constructor(getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S);

readonly modifyF: ModifyF<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'Traversal';

@@ -772,2 +799,5 @@ constructor(modifyF: ModifyF<S, A>);

readonly at: (i: I) => Lens<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'At';

@@ -787,2 +817,5 @@ constructor(at: (i: I) => Lens<S, A>);

readonly index: (i: I) => Optional<S, A>;
/**
* @since 1.0.0
*/
readonly _tag: 'Index';

@@ -806,2 +839,5 @@ constructor(index: (i: I) => Optional<S, A>);

readonly get: (s: S) => A;
/**
* @since 1.0.0
*/
readonly _tag: 'Getter';

@@ -869,2 +905,5 @@ constructor(get: (s: S) => A);

readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M;
/**
* @since 1.0.0
*/
readonly _tag: 'Fold';

@@ -958,2 +997,5 @@ /**

readonly modify: (f: (a: A) => A) => (s: S) => S;
/**
* @since 1.0.0
*/
readonly _tag: 'Setter';

@@ -960,0 +1002,0 @@ constructor(modify: (f: (a: A) => A) => (s: S) => S);

@@ -24,6 +24,21 @@ "use strict";

this.reverseGet = reverseGet;
/**
* @since 1.0.0
*/
this._tag = 'Iso';
/**
* @since 1.0.0
*/
this.unwrap = this.get;
/**
* @since 1.0.0
*/
this.to = this.get;
/**
* @since 1.0.0
*/
this.wrap = this.reverseGet;
/**
* @since 1.0.0
*/
this.from = this.reverseGet;

@@ -90,3 +105,3 @@ }

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -199,2 +214,5 @@ /**

this.set = set;
/**
* @since 1.0.0
*/
this._tag = 'Lens';

@@ -251,3 +269,5 @@ }

Lens.fromProp = function () {
return function (prop) { return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; }); };
return function (prop) {
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; });
};
};

@@ -391,3 +411,3 @@ /**

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -481,2 +501,5 @@ /**

this.reverseGet = reverseGet;
/**
* @since 1.0.0
*/
this._tag = 'Prism';

@@ -572,8 +595,3 @@ }

var oa = _this.getOption(s);
if (Option_1.isNone(oa)) {
return M.empty;
}
else {
return f(oa.value);
}
return Option_1.isNone(oa) ? M.empty : f(oa.value);
}; }; });

@@ -670,2 +688,5 @@ };

this.set = set;
/**
* @since 1.0.0
*/
this._tag = 'Optional';

@@ -742,3 +763,5 @@ }

Optional.fromNullableProp = function () {
return function (k) { return new Optional(function (s) { return Option_1.fromNullable(s[k]); }, function (a) { return function (s) { return (s[k] == null ? s : update(s, k, a)); }; }); };
return function (k) {
return new Optional(function (s) { return Option_1.fromNullable(s[k]); }, function (a) { return function (s) { return (s[k] == null ? s : update(s, k, a)); }; });
};
};

@@ -821,8 +844,3 @@ /**

var oa = _this.getOption(s);
if (Option_1.isNone(oa)) {
return M.empty;
}
else {
return f(oa.value);
}
return Option_1.isNone(oa) ? M.empty : f(oa.value);
}; }; });

@@ -923,2 +941,5 @@ };

this.modifyF = modifyF;
/**
* @since 1.0.0
*/
this._tag = 'Traversal';

@@ -948,3 +969,3 @@ }

var _this = this;
return new Fold(function (M) { return function (f) { return function (s) { return _this.modifyF(Const_1.getApplicative(M))(function (a) { return Const_1.make(f(a)); })(s); }; }; });
return new Fold(function (M) { return function (f) { return _this.modifyF(Const_1.getApplicative(M))(function (a) { return Const_1.make(f(a)); }); }; });
};

@@ -1042,2 +1063,5 @@ /**

this.at = at;
/**
* @since 1.0.0
*/
this._tag = 'At';

@@ -1063,2 +1087,5 @@ }

this.index = index;
/**
* @since 1.0.0
*/
this._tag = 'Index';

@@ -1090,2 +1117,5 @@ }

this.get = get;
/**
* @since 1.0.0
*/
this._tag = 'Getter';

@@ -1100,3 +1130,3 @@ }

var _this = this;
return new Fold(function (_) { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
return new Fold(function () { return function (f) { return function (s) { return f(_this.get(s)); }; }; });
};

@@ -1177,2 +1207,5 @@ /**

this.foldMap = foldMap;
/**
* @since 1.0.0
*/
this._tag = 'Fold';

@@ -1269,2 +1302,5 @@ this.getAll = foldMap(Array_1.getMonoid())(function (a) { return [a]; });

this.modify = modify;
/**
* @since 1.0.0
*/
this._tag = 'Setter';

@@ -1271,0 +1307,0 @@ }

{
"name": "monocle-ts",
"version": "2.1.0",
"version": "2.1.1",
"description": "A porting of scala monocle library to TypeScript",

@@ -45,3 +45,3 @@ "files": [

"@types/node": "7.0.4",
"docs-ts": "^0.3.1",
"docs-ts": "^0.4.0",
"dtslint": "github:gcanti/dtslint",

@@ -52,3 +52,3 @@ "fp-ts": "^2.0.0",

"mocha": "^5.2.0",
"prettier": "^1.15.3",
"prettier": "^2.0.2",
"rimraf": "^2.6.3",

@@ -59,3 +59,3 @@ "ts-jest": "^24.0.0",

"tslint-config-standard": "^8.0.1",
"typescript": "^3.7.2"
"typescript": "^3.8.3"
},

@@ -62,0 +62,0 @@ "tags": [

@@ -52,3 +52,3 @@ [![build status](https://img.shields.io/travis/gcanti/monocle-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/monocle-ts)

const employee2 = {
const employeeCapitalized = {
...employee,

@@ -78,7 +78,2 @@ company: {

const name = Lens.fromProp<Street>()('name')
company
.compose(address)
.compose(street)
.compose(name)
```

@@ -92,7 +87,9 @@

```ts
company
const capitalizeName = company
.compose(address)
.compose(street)
.compose(name)
.modify(capitalize)(employee)
.modify(capitalize)
assert.deepStrictEqual(capitalizeName(employee), employeeCapitalized) // true
```

@@ -107,3 +104,5 @@

name.modify(capitalize)(employee)
const capitalizeName = name.modify(capitalize)
assert.deepStrictEqual(capitalizeName(employee), employeeCapitalized) // true
```

@@ -121,5 +120,8 @@

const firstLetter = new Optional<string, string>(s => (s.length > 0 ? some(s[0]) : none), a => s => a + s.substring(1))
const firstLetterOptional = new Optional<string, string>(
s => (s.length > 0 ? some(s[0]) : none),
a => s => (s.length > 0 ? a + s.substring(1) : s)
)
company
const firstLetter = company
.compose(address)

@@ -129,4 +131,5 @@ .compose(street)

.asOptional()
.compose(firstLetter)
.modify(s => s.toUpperCase())(employee)
.compose(firstLetterOptional)
assert.deepStrictEqual(firstLetter.modify(s => s.toUpperCase())(employee), employeeCapitalized) // true
```

@@ -133,0 +136,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc