New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

purify-ts

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purify-ts - npm Package Compare versions

Comparing version 0.15.0 to 0.15.1

3

Codec.d.ts

@@ -29,4 +29,3 @@ import { Either } from './Either';

export declare const nullType: Codec<null>;
/** A codec for undefined only */
export declare const undefinedType: Codec<undefined>;
export declare const optional: <T>(codec: Codec<T>) => Codec<T | undefined>;
/** A codec for a boolean value */

@@ -33,0 +32,0 @@ export declare const boolean: Codec<boolean>;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {

@@ -56,3 +67,4 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

var key = keys_1_1.value;
if (!input.hasOwnProperty(key)) {
if (!input.hasOwnProperty(key) &&
!properties[key]._isOptional) {
return Either_1.Left("Problem with property \"" + key + "\": it does not exist in received object " + JSON.stringify(input));

@@ -136,4 +148,3 @@ }

});
/** A codec for undefined only */
exports.undefinedType = exports.Codec.custom({
var undefinedType = exports.Codec.custom({
decode: function (input) {

@@ -146,2 +157,5 @@ return input === undefined

});
exports.optional = function (codec) {
return (__assign(__assign({}, exports.oneOf([codec, undefinedType])), { _isOptional: true }));
};
/** A codec for a boolean value */

@@ -148,0 +162,0 @@ exports.boolean = exports.Codec.custom({

@@ -68,2 +68,4 @@ import { Maybe } from './Maybe';

extract(): L | R;
/** Returns `Right` if `this` is `Left` and vice versa */
swap(): Either<R, L>;
'fantasy-land/bimap'<L2, R2>(f: (value: L) => L2, g: (value: R) => R2): Either<L2, R2>;

@@ -70,0 +72,0 @@ 'fantasy-land/map'<R2>(f: (value: R) => R2): Either<L, R2>;

@@ -159,2 +159,5 @@ "use strict";

};
Right.prototype.swap = function () {
return left(this.__value);
};
Right.prototype['fantasy-land/bimap'] = function (f, g) {

@@ -275,2 +278,5 @@ return this.bimap(f, g);

};
Left.prototype.swap = function () {
return right(this.__value);
};
Left.prototype['fantasy-land/bimap'] = function (f, g) {

@@ -277,0 +283,0 @@ return this.bimap(f, g);

@@ -41,3 +41,9 @@ import { Either } from './Either';

}
/** Constructs a EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
export declare const EitherAsync: <L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
export declare const fromPromise: <L, R>(f: () => Promise<Either<L, R>>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
export declare const liftPromise: <R, L = Error>(f: () => Promise<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
export declare const liftEither: <L, R>(either: Either<L, R>) => EitherAsync<L, R>;

@@ -156,3 +156,17 @@ "use strict";

}());
/** Constructs a EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
exports.EitherAsync = function (runPromise) { return new EitherAsyncImpl(runPromise); };
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
exports.fromPromise = function (f) { return exports.EitherAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
}); };
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
exports.liftPromise = function (f) { return exports.EitherAsync(f); };
/** Constructs an EitherAsync object from an Either */
exports.liftEither = function (either) {
return exports.EitherAsync(function (_a) {
var liftEither = _a.liftEither;
return liftEither(either);
});
};

@@ -29,4 +29,3 @@ import { Either } from './Either';

export declare const nullType: Codec<null>;
/** A codec for undefined only */
export declare const undefinedType: Codec<undefined>;
export declare const optional: <T>(codec: Codec<T>) => Codec<T | undefined>;
/** A codec for a boolean value */

@@ -33,0 +32,0 @@ export declare const boolean: Codec<boolean>;

@@ -40,3 +40,4 @@ "use strict";

for (const key of keys) {
if (!input.hasOwnProperty(key)) {
if (!input.hasOwnProperty(key) &&
!properties[key]._isOptional) {
return Either_1.Left(`Problem with property "${key}": it does not exist in received object ${JSON.stringify(input)}`);

@@ -63,3 +64,3 @@ }

encode,
unsafeDecode: input => decode(input).unsafeCoerce()
unsafeDecode: (input) => decode(input).unsafeCoerce()
};

@@ -72,3 +73,3 @@ },

encode,
unsafeDecode: input => decode(input).unsafeCoerce()
unsafeDecode: (input) => decode(input).unsafeCoerce()
};

@@ -79,3 +80,3 @@ }

exports.string = exports.Codec.custom({
decode: input => typeof input === 'string'
decode: (input) => typeof input === 'string'
? Either_1.Right(input)

@@ -87,3 +88,3 @@ : Either_1.Left(reportError('a string', input)),

exports.number = exports.Codec.custom({
decode: input => typeof input === 'number'
decode: (input) => typeof input === 'number'
? Either_1.Right(input)

@@ -95,8 +96,7 @@ : Either_1.Left(reportError('a number', input)),

exports.nullType = exports.Codec.custom({
decode: input => input === null ? Either_1.Right(input) : Either_1.Left(reportError('a null', input)),
decode: (input) => input === null ? Either_1.Right(input) : Either_1.Left(reportError('a null', input)),
encode: Function_1.identity
});
/** A codec for undefined only */
exports.undefinedType = exports.Codec.custom({
decode: input => input === undefined
const undefinedType = exports.Codec.custom({
decode: (input) => input === undefined
? Either_1.Right(input)

@@ -106,5 +106,9 @@ : Either_1.Left(reportError('an undefined', input)),

});
exports.optional = (codec) => ({
...exports.oneOf([codec, undefinedType]),
_isOptional: true
});
/** A codec for a boolean value */
exports.boolean = exports.Codec.custom({
decode: input => typeof input === 'boolean'
decode: (input) => typeof input === 'boolean'
? Either_1.Right(input)

@@ -121,3 +125,3 @@ : Either_1.Left(reportError('a boolean', input)),

exports.oneOf = (codecs) => exports.Codec.custom({
decode: input => {
decode: (input) => {
let errors = [];

@@ -137,3 +141,3 @@ for (const codec of codecs) {

},
encode: input => {
encode: (input) => {
for (const codec of codecs) {

@@ -150,3 +154,3 @@ const res = codec.decode(input);

exports.array = (codec) => exports.Codec.custom({
decode: input => {
decode: (input) => {
if (!Array.isArray(input)) {

@@ -169,8 +173,8 @@ return Either_1.Left(reportError('an array', input));

},
encode: input => input.map(codec.encode)
encode: (input) => input.map(codec.encode)
});
const numberString = exports.Codec.custom({
decode: input => exports.string
decode: (input) => exports.string
.decode(input)
.chain(x => isFinite(+x) ? Either_1.Right(x) : Either_1.Left(reportError('a number key', input))),
.chain((x) => isFinite(+x) ? Either_1.Right(x) : Either_1.Left(reportError('a number key', input))),
encode: Function_1.identity

@@ -180,3 +184,3 @@ });

exports.record = (keyCodec, valueCodec) => exports.Codec.custom({
decode: input => {
decode: (input) => {
const result = {};

@@ -204,3 +208,3 @@ const keyCodecOverride = keyCodec === exports.number ? numberString : keyCodec;

},
encode: input => {
encode: (input) => {
const result = {};

@@ -217,3 +221,3 @@ for (const key in input) {

exports.exactly = (expectedValue) => exports.Codec.custom({
decode: input => input === expectedValue
decode: (input) => input === expectedValue
? Either_1.Right(expectedValue)

@@ -227,12 +231,12 @@ : Either_1.Left(typeof input === typeof expectedValue

exports.lazy = (getCodec) => exports.Codec.custom({
decode: input => getCodec().decode(input),
encode: input => getCodec().encode(input)
decode: (input) => getCodec().decode(input),
encode: (input) => getCodec().encode(input)
});
/** A codec for purify's Maybe type. Encode runs Maybe#toJSON, which effectively returns the value inside if it's a Just or undefined if it's Nothing */
exports.maybe = (codec) => exports.Codec.custom({
decode: input => Maybe_1.Maybe.fromNullable(input).caseOf({
Just: x => codec.decode(x).map(Maybe_1.Just),
decode: (input) => Maybe_1.Maybe.fromNullable(input).caseOf({
Just: (x) => codec.decode(x).map(Maybe_1.Just),
Nothing: () => Either_1.Right(Maybe_1.Nothing)
}),
encode: input => input.toJSON()
encode: (input) => input.toJSON()
});

@@ -243,5 +247,5 @@ /** A codec for purify's NEL type */

return exports.Codec.custom({
decode: input => arrayCodec
decode: (input) => arrayCodec
.decode(input)
.chain(x => NonEmptyList_1.NonEmptyList.fromArray(x).toEither(`Expected an array with one or more elements, but received an empty array`)),
.chain((x) => NonEmptyList_1.NonEmptyList.fromArray(x).toEither(`Expected an array with one or more elements, but received an empty array`)),
encode: arrayCodec.encode

@@ -252,3 +256,3 @@ });

exports.tuple = (codecs) => exports.Codec.custom({
decode: input => {
decode: (input) => {
if (!Array.isArray(input)) {

@@ -274,13 +278,13 @@ return Either_1.Left(reportError('an array', input));

},
encode: input => input.map((x, i) => codecs[i].encode(x))
encode: (input) => input.map((x, i) => codecs[i].encode(x))
});
/** A codec for a parsable date string, on successful decoding it resolves to a Date object. The validity of the date string during decoding is decided by the browser implementation of Date.parse. Encode runs toISOString on the passed in date object */
exports.date = exports.Codec.custom({
decode: input => exports.string
decode: (input) => exports.string
.decode(input)
.mapLeft(err => `Problem with date string: ${err}`)
.chain(x => Number.isNaN(Date.parse(x))
.mapLeft((err) => `Problem with date string: ${err}`)
.chain((x) => Number.isNaN(Date.parse(x))
? Either_1.Left('Expected a valid date string, but received a string that cannot be parsed')
: Either_1.Right(new Date(x))),
encode: input => input.toISOString()
encode: (input) => input.toISOString()
});

@@ -68,2 +68,4 @@ import { Maybe } from './Maybe';

extract(): L | R;
/** Returns `Right` if `this` is `Left` and vice versa */
swap(): Either<R, L>;
'fantasy-land/bimap'<L2, R2>(f: (value: L) => L2, g: (value: R) => R2): Either<L2, R2>;

@@ -70,0 +72,0 @@ 'fantasy-land/map'<R2>(f: (value: R) => R2): Either<L, R2>;

@@ -126,2 +126,5 @@ "use strict";

}
swap() {
return left(this.__value);
}
'fantasy-land/bimap'(f, g) {

@@ -241,2 +244,5 @@ return this.bimap(f, g);

}
swap() {
return right(this.__value);
}
'fantasy-land/bimap'(f, g) {

@@ -243,0 +249,0 @@ return this.bimap(f, g);

@@ -41,3 +41,9 @@ import { Either } from './Either';

}
/** Constructs a EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
export declare const EitherAsync: <L, R>(runPromise: (helpers: EitherAsyncHelpers<L>) => PromiseLike<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
export declare const fromPromise: <L, R>(f: () => Promise<Either<L, R>>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
export declare const liftPromise: <R, L = Error>(f: () => Promise<R>) => EitherAsync<L, R>;
/** Constructs an EitherAsync object from an Either */
export declare const liftEither: <L, R>(either: Either<L, R>) => EitherAsync<L, R>;

@@ -32,3 +32,3 @@ "use strict";

map(f) {
return exports.EitherAsync(helpers => this.runPromise(helpers).then(f));
return exports.EitherAsync((helpers) => this.runPromise(helpers).then(f));
}

@@ -74,3 +74,9 @@ mapLeft(f) {

}
/** Constructs a EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
/** Constructs an EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */
exports.EitherAsync = (runPromise) => new EitherAsyncImpl(runPromise);
/** Constructs an EitherAsync object from a function that returns an Either wrapped in a Promise */
exports.fromPromise = (f) => exports.EitherAsync(({ fromPromise: fP }) => fP(f()));
/** Constructs an EitherAsync object from a function that returns a Promise. The left type is defaulted to the built-in Error type */
exports.liftPromise = (f) => exports.EitherAsync(f);
/** Constructs an EitherAsync object from an Either */
exports.liftEither = (either) => exports.EitherAsync(({ liftEither }) => liftEither(either));

@@ -7,12 +7,18 @@ "use strict";

exports.always = (x) => () => x;
var Order;
(function (Order) {
Order["LT"] = "LT";
Order["EQ"] = "EQ";
Order["GT"] = "GT";
})(Order = exports.Order || (exports.Order = {}));
/** Compares two values using the default "<" and ">" operators */
exports.compare = (x, y) => {
if (x > y) {
return "GT" /* GT */;
return Order.GT;
}
else if (x < y) {
return "LT" /* LT */;
return Order.LT;
}
else {
return "EQ" /* EQ */;
return Order.EQ;
}

@@ -23,9 +29,9 @@ };

switch (order) {
case "LT" /* LT */:
case Order.LT:
return -1;
case "EQ" /* EQ */:
case Order.EQ:
return 0;
case "GT" /* GT */:
case Order.GT:
return 1;
}
};
export * from './Codec';
export * from './Either';
export * from './EitherAsync';
export * from './Function';
export * from './List';
export * from './Maybe';
export * from './MaybeAsync';
export { MaybeAsync } from './MaybeAsync';
export { EitherAsync } from './EitherAsync';
export * from './NonEmptyList';
export * from './Tuple';

@@ -8,8 +8,10 @@ "use strict";

__export(require("./Either"));
__export(require("./EitherAsync"));
__export(require("./Function"));
__export(require("./List"));
__export(require("./Maybe"));
__export(require("./MaybeAsync"));
var MaybeAsync_1 = require("./MaybeAsync");
exports.MaybeAsync = MaybeAsync_1.MaybeAsync;
var EitherAsync_1 = require("./EitherAsync");
exports.EitherAsync = EitherAsync_1.EitherAsync;
__export(require("./NonEmptyList"));
__export(require("./Tuple"));

@@ -31,3 +31,3 @@ "use strict";

default:
return Maybe_1.Maybe.fromPredicate(x => x !== -1, list.findIndex(f));
return Maybe_1.Maybe.fromPredicate((x) => x !== -1, list.findIndex(f));
}

@@ -34,0 +34,0 @@ }

@@ -37,3 +37,3 @@ "use strict";

catMaybes(list) {
return list.filter(x => x.isJust()).map(x => x.__value);
return list.filter((x) => x.isJust()).map((x) => x.__value);
},

@@ -40,0 +40,0 @@ encase(thunk) {

@@ -37,1 +37,7 @@ import { Maybe } from './Maybe';

export declare const MaybeAsync: <T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
export declare const fromPromise: <T>(f: () => Promise<Maybe<T>>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
export declare const liftPromise: <T>(f: () => Promise<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
export declare const liftMaybe: <T>(maybe: Maybe<T>) => MaybeAsync<T>;

@@ -29,3 +29,3 @@ "use strict";

map(f) {
return exports.MaybeAsync(helpers => this.runPromise(helpers).then(f));
return exports.MaybeAsync((helpers) => this.runPromise(helpers).then(f));
}

@@ -53,1 +53,7 @@ chain(f) {

exports.MaybeAsync = (runPromise) => new MaybeAsyncImpl(runPromise);
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
exports.fromPromise = (f) => exports.MaybeAsync(({ fromPromise: fP }) => fP(f()));
/** Constructs an MaybeAsync object from a function that returns a Promise */
exports.liftPromise = (f) => exports.MaybeAsync(f);
/** Constructs an MaybeAsync object from a Maybe */
exports.liftMaybe = (maybe) => exports.MaybeAsync(({ liftMaybe }) => liftMaybe(maybe));

@@ -7,12 +7,18 @@ "use strict";

exports.always = function (x) { return function () { return x; }; };
var Order;
(function (Order) {
Order["LT"] = "LT";
Order["EQ"] = "EQ";
Order["GT"] = "GT";
})(Order = exports.Order || (exports.Order = {}));
/** Compares two values using the default "<" and ">" operators */
exports.compare = function (x, y) {
if (x > y) {
return "GT" /* GT */;
return Order.GT;
}
else if (x < y) {
return "LT" /* LT */;
return Order.LT;
}
else {
return "EQ" /* EQ */;
return Order.EQ;
}

@@ -23,9 +29,9 @@ };

switch (order) {
case "LT" /* LT */:
case Order.LT:
return -1;
case "EQ" /* EQ */:
case Order.EQ:
return 0;
case "GT" /* GT */:
case Order.GT:
return 1;
}
};
export * from './Codec';
export * from './Either';
export * from './EitherAsync';
export * from './Function';
export * from './List';
export * from './Maybe';
export * from './MaybeAsync';
export { MaybeAsync } from './MaybeAsync';
export { EitherAsync } from './EitherAsync';
export * from './NonEmptyList';
export * from './Tuple';

@@ -8,8 +8,10 @@ "use strict";

__export(require("./Either"));
__export(require("./EitherAsync"));
__export(require("./Function"));
__export(require("./List"));
__export(require("./Maybe"));
__export(require("./MaybeAsync"));
var MaybeAsync_1 = require("./MaybeAsync");
exports.MaybeAsync = MaybeAsync_1.MaybeAsync;
var EitherAsync_1 = require("./EitherAsync");
exports.EitherAsync = EitherAsync_1.EitherAsync;
__export(require("./NonEmptyList"));
__export(require("./Tuple"));

@@ -37,1 +37,7 @@ import { Maybe } from './Maybe';

export declare const MaybeAsync: <T>(runPromise: (helpers: MaybeAsyncHelpers) => PromiseLike<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
export declare const fromPromise: <T>(f: () => Promise<Maybe<T>>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a function that returns a Promise */
export declare const liftPromise: <T>(f: () => Promise<T>) => MaybeAsync<T>;
/** Constructs an MaybeAsync object from a Maybe */
export declare const liftMaybe: <T>(maybe: Maybe<T>) => MaybeAsync<T>;

@@ -120,1 +120,19 @@ "use strict";

exports.MaybeAsync = function (runPromise) { return new MaybeAsyncImpl(runPromise); };
/** Constructs an MaybeAsync object from a function that returns a Maybe wrapped in a Promise */
exports.fromPromise = function (f) {
return exports.MaybeAsync(function (_a) {
var fP = _a.fromPromise;
return fP(f());
});
};
/** Constructs an MaybeAsync object from a function that returns a Promise */
exports.liftPromise = function (f) {
return exports.MaybeAsync(f);
};
/** Constructs an MaybeAsync object from a Maybe */
exports.liftMaybe = function (maybe) {
return exports.MaybeAsync(function (_a) {
var liftMaybe = _a.liftMaybe;
return liftMaybe(maybe);
});
};
{
"name": "purify-ts",
"version": "0.15.0",
"version": "0.15.1",
"description": "Functional programming standard library for TypeScript ",

@@ -32,7 +32,7 @@ "main": "lib/index.js",

"jest": "^25.1.0",
"prettier": "^1.19.1",
"prettier": "^2.0.1",
"ts-jest": "^25.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"dependencies": {}
}
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