xod-func-tools
Advanced tools
Comparing version 0.19.2 to 0.21.0
@@ -7,2 +7,14 @@ 'use strict'; | ||
var _errors = require('./errors'); | ||
Object.keys(_errors).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _errors[key]; | ||
} | ||
}); | ||
}); | ||
var _fetch = require('./fetch'); | ||
@@ -103,2 +115,26 @@ | ||
}); | ||
var _strings = require('./strings'); | ||
Object.keys(_strings).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _strings[key]; | ||
} | ||
}); | ||
}); | ||
var _sets = require('./sets'); | ||
Object.keys(_sets).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _sets[key]; | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.leftIf = exports.reduceMaybe = exports.reduceEither = exports.reduceM = exports.maybeToPromise = exports.eitherToPromise = exports.explodeEither = exports.catMaybies = exports.explodeMaybe = exports.explode = exports.foldMaybe = exports.foldEither = undefined; | ||
exports.maybeFind = exports.maybePath = exports.maybeProp = exports.leftIf = exports.reduceMaybe = exports.reduceEither = exports.reduceM = exports.maybeToPromise = exports.eitherToPromise = exports.explodeEither = exports.catMaybies = exports.explodeMaybe = exports.explode = exports.foldMaybe = exports.foldEither = exports.eitherRight = exports.eitherLeft = undefined; | ||
@@ -19,2 +19,8 @@ var _ramda = require('ramda'); | ||
/* | ||
* Shortcuts for easier ReasonML interop | ||
*/ | ||
var eitherLeft = exports.eitherLeft = _ramdaFantasy.Either.Left; | ||
var eitherRight = exports.eitherRight = _ramdaFantasy.Either.Right; | ||
/** | ||
@@ -93,3 +99,4 @@ * Function to extract value from `Either` by providing a function | ||
var catMaybies = exports.catMaybies = (0, _types.def)('catMaybies :: [Maybe a] -> [a]', R.compose(R.map(explodeMaybe('Expected Just, but got Nothing.')), R.filter(_ramdaFantasy.Maybe.isJust))); | ||
// :: Iterable Maybe a -> Iterable a | ||
var catMaybies = exports.catMaybies = R.compose(R.map(explodeMaybe('Expected Just, but got Nothing.')), R.filter(_ramdaFantasy.Maybe.isJust)); | ||
@@ -163,2 +170,8 @@ /** | ||
}); | ||
var maybeProp = exports.maybeProp = (0, _types.def)('maybeProp :: String -> StrMap a -> Maybe a', R.compose(_ramdaFantasy.Maybe, R.prop)); | ||
var maybePath = exports.maybePath = (0, _types.def)('maybePath :: [String] -> Object -> Maybe a', R.compose(_ramdaFantasy.Maybe, R.path)); | ||
var maybeFind = exports.maybeFind = (0, _types.def)('maybeFind :: (a -> Boolean) -> [a] -> Maybe a', R.compose(_ramdaFantasy.Maybe, R.find)); | ||
//# sourceMappingURL=monads.js.map |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.invertMap = exports.reverseLookup = exports.renameKeys = exports.subtractObject = exports.optionalObjOf = exports.omitTypeHints = exports.omitRecursively = exports.omitEmptyValues = exports.omitNilValues = undefined; | ||
exports.sameKeysetBy = exports.invertMap = exports.reverseLookup = exports.renameKeys = exports.subtractObject = exports.optionalObjOf = exports.omitTypeHints = exports.omitRecursively = exports.omitEmptyValues = exports.omitNilValues = undefined; | ||
@@ -15,2 +15,4 @@ var _ramda = require('ramda'); | ||
var _sets = require('./sets'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -99,2 +101,24 @@ | ||
var invertMap = exports.invertMap = (0, _types.def)('invertMap :: Map a b -> Map b a', R.compose(R.fromPairs, R.map(R.reverse), R.toPairs)); | ||
/** | ||
* Function compares two arguments by keys, produced by | ||
* calling transformation function on each of arguments. | ||
* | ||
* E.G. | ||
* Compare array of some objects: | ||
* sameKeysetBy(R.indexBy(R.prop('id')), [{ id: 'a' }], [{ id: 'b' }]) -> false | ||
*/ | ||
var sameKeysetBy = exports.sameKeysetBy = (0, _types.def)('sameKeysetBy :: (b -> StrMap a) -> b -> b -> Boolean', function (mapGetter, prev, next) { | ||
if (prev === next) return true; | ||
var prevMap = mapGetter(prev); | ||
var nextMap = mapGetter(next); | ||
var prevMapKeys = (0, _sets.setOfKeys)(prevMap); | ||
var nextMapKeys = (0, _sets.setOfKeys)(nextMap); | ||
var diffMapKeys = (0, _sets.diffSet)(prevMapKeys, nextMapKeys); | ||
// If there is some keys added/deleted — something changed | ||
if (diffMapKeys.size > 0) return false; | ||
return true; | ||
}); | ||
//# sourceMappingURL=objects.js.map |
@@ -6,4 +6,6 @@ 'use strict'; | ||
}); | ||
exports.def = exports.env = exports.$Either = exports.$Maybe = exports.$Promise = exports.Pair = exports.Map = exports.AliasType = exports.OneOfType = exports.Model = exports.EnumType = exports.BinaryType = exports.UnaryType = exports.NullaryType = exports.hasOneOfType = exports.hasType = undefined; | ||
exports.def = exports.env = exports.$Either = exports.$Maybe = exports.Stanza = exports.$Promise = exports.Pair = exports.Map = exports.AliasType = exports.OneOfType = exports.Model = exports.EnumType = exports.BinaryType = exports.UnaryType = exports.NullaryType = exports.hasOneOfType = exports.hasType = undefined; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _ramda = require('ramda'); | ||
@@ -128,2 +130,14 @@ | ||
// In case that sanctuary-def Record type could have only required fields | ||
// we'll check Stanza only for being an object (not null and not array) | ||
// and enumerate possible keys here: | ||
// - title: String | ||
// - note: String | ||
// - path: [PatchPath] | ||
// - solution: String | ||
// - learnMore: Url | ||
var Stanza = exports.Stanza = NullaryType(pkgName, dUrl, 'Stanza', function (x) { | ||
return x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && Array.isArray(x) === false; | ||
}); | ||
//----------------------------------------------------------------------------- | ||
@@ -153,3 +167,3 @@ // | ||
var env = exports.env = _sanctuaryDef2.default.env.concat([Map(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), Pair(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), $Promise, $Either(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), $Maybe(_sanctuaryDef2.default.Unknown)]); | ||
var env = exports.env = _sanctuaryDef2.default.env.concat([Map(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), Pair(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), $Promise, $Either(_sanctuaryDef2.default.Unknown, _sanctuaryDef2.default.Unknown), $Maybe(_sanctuaryDef2.default.Unknown), Stanza]); | ||
@@ -156,0 +170,0 @@ var def = exports.def = _hmDef2.default.create({ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.notEquals = exports.hasNo = exports.notEmpty = exports.notNil = exports.noop = undefined; | ||
exports.memoizeOnlyLast = exports.enumerate = exports.notEquals = exports.hasNo = exports.notEmpty = exports.notNil = exports.noop = undefined; | ||
@@ -25,2 +25,24 @@ var _ramda = require('ramda'); | ||
var notEquals = exports.notEquals = R.complement(R.equals); | ||
// enumerate(', ', ' or ', [1,2,3,4]) => "1, 2, 3 or 4" | ||
var enumerate = exports.enumerate = R.curry(function (separator, lastSeparator, items) { | ||
var firstItems = R.dropLast(2, items); | ||
var lastItems = R.takeLast(2, items); | ||
return R.compose(R.join(separator), R.append(R.__, firstItems), R.join(lastSeparator))(lastItems); | ||
}); | ||
var memoizeOnlyLast = exports.memoizeOnlyLast = function memoizeOnlyLast(f) { | ||
var lastArg = void 0; | ||
var result = void 0; | ||
return function (arg) { | ||
if (arg !== lastArg) { | ||
result = f(arg); | ||
lastArg = arg; | ||
} | ||
return result; | ||
}; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "xod-func-tools", | ||
"version": "0.19.2", | ||
"version": "0.21.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -0,1 +1,2 @@ | ||
export * from './errors'; | ||
export * from './fetch'; | ||
@@ -9,1 +10,3 @@ export * from './lists'; | ||
export * from './utils'; | ||
export * from './strings'; | ||
export * from './sets'; |
@@ -5,2 +5,8 @@ import * as R from 'ramda'; | ||
/* | ||
* Shortcuts for easier ReasonML interop | ||
*/ | ||
export const eitherLeft = Either.Left; | ||
export const eitherRight = Either.Right; | ||
/** | ||
@@ -101,8 +107,6 @@ * Function to extract value from `Either` by providing a function | ||
export const catMaybies = def( | ||
'catMaybies :: [Maybe a] -> [a]', | ||
R.compose( | ||
R.map(explodeMaybe('Expected Just, but got Nothing.')), | ||
R.filter(Maybe.isJust) | ||
) | ||
// :: Iterable Maybe a -> Iterable a | ||
export const catMaybies = R.compose( | ||
R.map(explodeMaybe('Expected Just, but got Nothing.')), | ||
R.filter(Maybe.isJust) | ||
); | ||
@@ -189,1 +193,16 @@ | ||
); | ||
export const maybeProp = def( | ||
'maybeProp :: String -> StrMap a -> Maybe a', | ||
R.compose(Maybe, R.prop) | ||
); | ||
export const maybePath = def( | ||
'maybePath :: [String] -> Object -> Maybe a', | ||
R.compose(Maybe, R.path) | ||
); | ||
export const maybeFind = def( | ||
'maybeFind :: (a -> Boolean) -> [a] -> Maybe a', | ||
R.compose(Maybe, R.find) | ||
); |
import * as R from 'ramda'; | ||
import { def } from './types'; | ||
import { setOfKeys, diffSet } from './sets'; | ||
@@ -120,1 +121,26 @@ /** | ||
); | ||
/** | ||
* Function compares two arguments by keys, produced by | ||
* calling transformation function on each of arguments. | ||
* | ||
* E.G. | ||
* Compare array of some objects: | ||
* sameKeysetBy(R.indexBy(R.prop('id')), [{ id: 'a' }], [{ id: 'b' }]) -> false | ||
*/ | ||
export const sameKeysetBy = def( | ||
'sameKeysetBy :: (b -> StrMap a) -> b -> b -> Boolean', | ||
(mapGetter, prev, next) => { | ||
if (prev === next) return true; | ||
const prevMap = mapGetter(prev); | ||
const nextMap = mapGetter(next); | ||
const prevMapKeys = setOfKeys(prevMap); | ||
const nextMapKeys = setOfKeys(nextMap); | ||
const diffMapKeys = diffSet(prevMapKeys, nextMapKeys); | ||
// If there is some keys added/deleted — something changed | ||
if (diffMapKeys.size > 0) return false; | ||
return true; | ||
} | ||
); |
@@ -145,2 +145,17 @@ import * as R from 'ramda'; | ||
// In case that sanctuary-def Record type could have only required fields | ||
// we'll check Stanza only for being an object (not null and not array) | ||
// and enumerate possible keys here: | ||
// - title: String | ||
// - note: String | ||
// - path: [PatchPath] | ||
// - solution: String | ||
// - learnMore: Url | ||
export const Stanza = NullaryType( | ||
pkgName, | ||
dUrl, | ||
'Stanza', | ||
x => x !== null && typeof x === 'object' && Array.isArray(x) === false | ||
); | ||
//----------------------------------------------------------------------------- | ||
@@ -181,2 +196,3 @@ // | ||
$Maybe($.Unknown), | ||
Stanza, | ||
]); | ||
@@ -183,0 +199,0 @@ |
@@ -13,1 +13,27 @@ import * as R from 'ramda'; | ||
export const notEquals = R.complement(R.equals); | ||
// enumerate(', ', ' or ', [1,2,3,4]) => "1, 2, 3 or 4" | ||
export const enumerate = R.curry((separator, lastSeparator, items) => { | ||
const firstItems = R.dropLast(2, items); | ||
const lastItems = R.takeLast(2, items); | ||
return R.compose( | ||
R.join(separator), | ||
R.append(R.__, firstItems), | ||
R.join(lastSeparator) | ||
)(lastItems); | ||
}); | ||
export const memoizeOnlyLast = f => { | ||
let lastArg; | ||
let result; | ||
return arg => { | ||
if (arg !== lastArg) { | ||
result = f(arg); | ||
lastArg = arg; | ||
} | ||
return result; | ||
}; | ||
}; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158539
47
2036