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

immutable-recursive

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-recursive - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

docs/deepGet.js.html

184

lib/index.js

@@ -6,149 +6,55 @@ 'use strict';

});
exports.deepMapParents = exports.deepMapLeaves = exports.deepMap = exports.deepSetChildren = exports.deepSet = exports.deepGetChildren = exports.deepGet = exports.isLeaf = exports.keysToPathChildren = exports.keysToPath = exports.asList = undefined;
exports.deepMapParents = exports.deepMapLeaves = exports.deepMap = exports.deepSetChildren = exports.deepSet = exports.deepGetChildren = exports.deepGet = undefined;
var _immutable = require('immutable');
var _get = require('./get');
//
// utils
//
Object.defineProperty(exports, 'deepGet', {
enumerable: true,
get: function get() {
return _get.deepGet;
}
});
Object.defineProperty(exports, 'deepGetChildren', {
enumerable: true,
get: function get() {
return _get.deepGetChildren;
}
});
var asList = exports.asList = function asList(input) {
return _immutable.List.isList(input) ? input : (0, _immutable.List)(input);
};
var _set = require('./set');
var keysToPath = exports.keysToPath = function keysToPath(keys, childPath) {
childPath = asList(childPath).toJS();
return keys.reduce(function (fullPath, key) {
return fullPath.concat(childPath).push(key);
}, (0, _immutable.List)());
};
var keysToPathChildren = exports.keysToPathChildren = function keysToPathChildren(keys, childPath) {
return keysToPath(keys, childPath).concat(childPath);
};
var isLeaf = exports.isLeaf = function isLeaf(item) {
var childPath = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
if (!_immutable.Iterable.isIterable(item)) {
return true;
Object.defineProperty(exports, 'deepSet', {
enumerable: true,
get: function get() {
return _set.deepSet;
}
var children = item.getIn(childPath);
return !children || children.isEmpty();
};
});
Object.defineProperty(exports, 'deepSetChildren', {
enumerable: true,
get: function get() {
return _set.deepSetChildren;
}
});
//
// get
//
var _map = require('./map');
var deepGet = exports.deepGet = function deepGet(keys, childPath) {
var notSetValue = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return function (input) {
return input.getIn(keysToPath(keys, childPath), notSetValue);
};
};
var deepGetChildren = exports.deepGetChildren = function deepGetChildren(keys, childPath) {
var notSetValue = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return function (input) {
return input.getIn(keysToPathChildren(keys, childPath), notSetValue);
};
};
//
// set
//
var deepSet = exports.deepSet = function deepSet(keys, value, childPath) {
return function (input) {
return input.setIn(keysToPath(keys, childPath), value);
};
};
var deepSetChildren = exports.deepSetChildren = function deepSetChildren(keys, value, childPath) {
return function (input) {
return input.setIn(keysToPathChildren(keys, childPath), value);
};
};
//
// map
//
var mapRecursive = function mapRecursive(self, childPath, mapper, options) {
var keys = arguments.length <= 4 || arguments[4] === undefined ? (0, _immutable.List)() : arguments[4];
var mapSelf = function mapSelf(self) {
var children = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
return mapper(self, keys, children);
};
if (isLeaf(self, childPath)) {
return options.onlyParents ? self : mapSelf(self);
Object.defineProperty(exports, 'deepMap', {
enumerable: true,
get: function get() {
return _map.deepMap;
}
});
Object.defineProperty(exports, 'deepMapLeaves', {
enumerable: true,
get: function get() {
return _map.deepMapLeaves;
}
});
Object.defineProperty(exports, 'deepMapParents', {
enumerable: true,
get: function get() {
return _map.deepMapParents;
}
});
var mappedChildren = self.getIn(childPath).map(function (kid, key) {
return mapRecursive(kid, childPath, mapper, options, keys.push(key));
});
var selfWithMappedChildren = childPath.isEmpty() ? self.merge(mappedChildren) : self.setIn(childPath, mappedChildren);
return options.onlyLeaves ? selfWithMappedChildren : mapSelf(selfWithMappedChildren, mappedChildren);
};
var deepMap = exports.deepMap = function deepMap(mapper) {
var childPath = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
return function (input) {
return mapRecursive(input, asList(childPath), mapper, {});
};
};
var deepMapLeaves = exports.deepMapLeaves = function deepMapLeaves(mapper) {
var childPath = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
return function (input) {
return mapRecursive(input, asList(childPath), mapper, { onlyLeaves: true });
};
};
var deepMapParents = exports.deepMapParents = function deepMapParents(mapper) {
var childPath = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
return function (input) {
return mapRecursive(input, asList(childPath), mapper, { onlyParents: true });
};
};
//
// delete
//
// ...
//
// filter
//
// ...
//
// reduce
//
// ...
//
// sort
//
// ...
//
// deconstruct
//
// ...
//
// reconstruct
//
// ...
var _utils = require('./utils');
{
"name": "immutable-recursive",
"version": "0.0.0",
"version": "0.0.1",
"description": "Extra functions for use with Immutable.js to better handle tree structures / nested data and recursive iteration",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src --out-dir lib && jsdoc2md -l js -t jsdoc2md/README.hbs lib/*.js lib/**/*.js > README.md",
"prepublish": "npm run build",
"dev": "babel src -d lib --watch",
"docs": "jsdoc2md -l js -t jsdoc2md/README.hbs lib/*.js lib/**/*.js > README.md"
"build": "babel src --out-dir lib && npm run docs",
"tape": "tape -r ./tests/tests.js src/**/*-test.js",
"test": "nyc --report-dir=./coverage npm run tape && npm run check-coverage",
"check-coverage": "nyc check-coverage --branches 0.0 --functions 0.0 --lines 0",
"docs": "jsdoc -c jsdoc/conf.json",
"prepublish": "npm run build && npm run docs"
},

@@ -24,16 +26,14 @@ "keywords": [

"repository": "github:dxinteractive/immutable-recursive",
"license": "ISC",
"license": "MIT",
"devDependencies": {
"app-module-path": "^1.1.0",
"babel-cli": "^6.5.1",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-preset-es2015": "^6.5.0",
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-esdoc": "0.0.2",
"grunt-jsdoc": "^1.1.0",
"babel-register": "^6.14.0",
"docdash": "^0.4.0",
"glob": "^7.0.6",
"immutable": "^3.8.1",
"ink-docstrap": "^1.1.1",
"jsdoc-babel": "^0.1.0",
"jsdoc-export-default-interop": "^0.3.1",
"jsdoc-to-markdown": "^1.3.6",
"minami": "^1.1.1",
"jsdoc": "^3.4.1",
"nyc": "^8.1.0",
"repeating": "^2.0.0",

@@ -44,3 +44,22 @@ "tape": "^4.6.0"

"immutable": "^3.8.1"
},
"nyc": {
"all": true,
"include": [
"src/**"
],
"exclude": [
"src/**/*-test.js"
],
"reporter": [
"lcov",
"text-summary"
],
"extension": [
".js"
],
"require": [
"./tests/tests.js"
]
}
}

@@ -8,1 +8,56 @@ # immutable-recursive

Completely pre-alpha at this point, won't be long until this is ready for public. Hold on to your hats, anything could change in the near future.
[Preliminary documentation](https://dxinteractive.github.io/immutable-recursive/)
## Development tasks
| Function | Plan | Write | Tests | Document | Examples |
| -------- | ---- | ----- | ----- | -------- | -------- |
| deepGet | Done | Done | | | |
| deepGetChildren | Done | Done | | | |
| deepSet | Done | Done | | | |
| deepSetChildren | Done | Done | | | |
| deepUpdate | | | | | |
| deepUpdateChildren | | | | | |
| deepDelete | Done | | | | |
| deepDeleteChildren | Done | | | | |
| deepDeleteCollapse | In progress | | | | |
| deepMap | Done | Done | | In progress | |
| deepMapLeaves | Done | Done | | In progress | |
| deepMapParents | Done | Done | | In progress | |
| deepMapOutward | In progress | | | | |
| deepMapParentsOutward | In progress | | | | |
| deepReduce | In progress | | | | |
| deepFilter | In progress | | | | |
| deepFilterCollapse | In progress | | | | |
| deepFilterCollapse | In progress | | | | |
| deepSortBy | Done | In progress | | | |
| deconstruct | Done | In progress | | | |
| reconstruct | In progress | | | | |
| flatCollapse | | | | | |
| flatPrune | | | | | |
| asList | Done | Done | Done | Done | |
| isLeaf | Done | Done | Done | Done | |
| keysToPath | Done | Done | Done | Done | |
| keysToPathChildren | Done | Done | Done | Done | |
| isSiblingOf | Done | | | | |
| isParentOf | Done | | | | |
| isAncestorOf | Done | | | | |
| commonAncestorOf | | | | | |
| inputFunction (typedef) | Done | N/A | N/A | Done | |
| keys (typedef) | Done | N/A | N/A | In progress | |
| childPath (typedef) | Done | N/A | N/A | In progress | |
| mapper (typedef) | Done | N/A | N/A | In progress | |
| updater (typedef) | Done | N/A | N/A | In progress | |
| reducer (typedef) | Done | N/A | N/A | In progress | |
| filter (typedef) | Done | N/A | N/A | In progress | |
- Reconsider paramaters passed to mappers / updaters etc. and which children, parents or ancestors should be accessible
- Add a 'thinking in trees and nodes' style intro
- Add documentation about partially applied function benefits
- Add documentation about deep data manipulation pitfalls, avoiding killing children
- Add build process with Travis
- Add coverage reporting and build failing
- Add shields for tests, version numbers, coverage
- Change to minami, fix table styles on index page

@@ -1,129 +0,22 @@

import {
fromJS,
Iterable,
List,
Map,
OrderedMap
} from 'immutable';
export {
deepGet,
deepGetChildren
} from './get';
//
// utils
//
export {
deepSet,
deepSetChildren
} from './set';
export const asList = (input) => List.isList(input) ? input : List(input);
export {
deepMap,
deepMapLeaves,
deepMapParents
} from './map';
export const keysToPath = (keys, childPath) => {
childPath = asList(childPath).toJS();
return keys.reduce((fullPath, key) => {
return fullPath.concat(childPath).push(key);
}, List());
};
export const keysToPathChildren = (keys, childPath) => {
return keysToPath(keys, childPath).concat(childPath);
};
export const isLeaf = (item, childPath = []) => {
if(!Iterable.isIterable(item)) {
return true;
}
const children = item.getIn(childPath);
return !children || children.isEmpty();
};
//
// get
//
export const deepGet = (keys, childPath, notSetValue = null) => (input) => {
return input.getIn(keysToPath(keys, childPath), notSetValue);
};
export const deepGetChildren = (keys, childPath, notSetValue = null) => (input) => {
return input.getIn(keysToPathChildren(keys, childPath), notSetValue);
};
//
// set
//
export const deepSet = (keys, value, childPath) => (input) => {
return input.setIn(keysToPath(keys, childPath), value);
};
export const deepSetChildren = (keys, value, childPath) => (input) => {
return input.setIn(keysToPathChildren(keys, childPath), value);
};
//
// map
//
const mapRecursive = (self, childPath, mapper, options, keys = List()) => {
const mapSelf = (self, children = null) => mapper(self, keys, children);
if(isLeaf(self, childPath)) {
return options.onlyParents ? self : mapSelf(self);
}
const mappedChildren = self
.getIn(childPath)
.map((kid, key) => mapRecursive(kid, childPath, mapper, options, keys.push(key)));
const selfWithMappedChildren = childPath.isEmpty()
? self.merge(mappedChildren)
: self.setIn(childPath, mappedChildren);
return options.onlyLeaves
? selfWithMappedChildren
: mapSelf(selfWithMappedChildren, mappedChildren);
};
export const deepMap = (mapper, childPath = []) => (input) => {
return mapRecursive(input, asList(childPath), mapper, {});
};
export const deepMapLeaves = (mapper, childPath = []) => (input) => {
return mapRecursive(input, asList(childPath), mapper, {onlyLeaves: true});
};
export const deepMapParents = (mapper, childPath = []) => (input) => {
return mapRecursive(input, asList(childPath), mapper, {onlyParents: true});
};
//
// delete
//
// ...
//
// filter
//
// ...
//
// reduce
//
// ...
//
// sort
//
// ...
//
// deconstruct
//
// ...
//
// reconstruct
//
// ...
import {
asList,
isLeaf,
keysToPath,
keysToPathChildren
} from './utils';

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