machinepack-arrays
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -10,3 +10,3 @@ module.exports = { | ||
extendedDescription: 'Warning: Both arrays must be homogenous, and their items must have matching/compatible types.', | ||
extendedDescription: 'Warning: Both arrays must be homogeneous, and their items must have matching/compatible types. Also, both arrays must be JSON-compatible.', | ||
@@ -24,3 +24,3 @@ | ||
description: 'The first array', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -31,3 +31,3 @@ }, | ||
description: 'The second array', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -52,4 +52,27 @@ } | ||
variableName: 'newArray', | ||
getExample: function (inputs){ | ||
return [inputs.firstArray[0]]; | ||
getExample: function (inputs, env){ | ||
var _ = env._; | ||
// If neither array is avaiable yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of JSON-compatible | ||
// values, as per the machine description. | ||
if (_.isUndefined(inputs.firstArray) && _.isUndefined(inputs.secondArray)) { | ||
return ['*']; | ||
} | ||
// If at least one array is available, and has at least one item, we can use | ||
// it to determine the pattern type. This is possible because this machine makes | ||
// it clear in the description that both arrays must share a common pattern type. | ||
if (inputs.firstArray&&inputs.firstArray.length>0) { | ||
return [inputs.firstArray[0]]; | ||
} | ||
else if (inputs.secondArray&&inputs.secondArray.length>0) { | ||
return [inputs.secondArray[0]]; | ||
} | ||
// If neither array has this information available yet, the best we can | ||
// do is return `['*']`, since we know that, barring any weird complications | ||
// that would cause a different exit to be traversed, this will be the | ||
// result for our machine. | ||
return ['*']; | ||
} | ||
@@ -56,0 +79,0 @@ } |
@@ -10,3 +10,3 @@ module.exports = { | ||
extendedDescription: 'This machine is not designed for everyday use-- it is an identity operator for the Array type.', | ||
extendedDescription: 'This machine is not designed for everyday use-- it is an identity operator for the Array type-- but it can certainly be used in any way you see fit.', | ||
@@ -23,4 +23,4 @@ | ||
array: { | ||
description: 'The array to build.', | ||
typeclass: 'array', | ||
description: 'The homogeneous array to build.', | ||
example: ['*'], | ||
required: true | ||
@@ -32,5 +32,2 @@ } | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -44,5 +41,22 @@ | ||
description: 'Returns new array.', | ||
variableName: 'newArray', | ||
friendlyName: 'then', | ||
getExample: function(inputs, exits) { | ||
return inputs.array; | ||
getExample: function(inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of JSON-compatible | ||
// values, as per the machine description. | ||
if (_.isUndefined(inputs.array)) { | ||
return ['*']; | ||
} | ||
// If the array is available and has one item, we can just borrow that first item | ||
// to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
// Otherwise, the best we can do is send back ['*']. | ||
return ['*']; | ||
} | ||
@@ -49,0 +63,0 @@ } |
module.exports = { | ||
friendlyName: 'Find dictionary by...', | ||
friendlyName: 'Find one by...', | ||
@@ -21,4 +21,3 @@ | ||
description: 'The array to search in (i.e. "haystack")', | ||
// example: [{}], | ||
typeclass: 'array', | ||
example: [{}], | ||
required: true | ||
@@ -29,3 +28,3 @@ }, | ||
friendlyName: 'Criteria', | ||
typeclass: 'dictionary', | ||
example: {}, | ||
description: 'The Lodash/Waterline-style criteria to use (i.e. "metal detector")', | ||
@@ -50,3 +49,14 @@ required: true | ||
description: 'Returns the matching dictionary.', | ||
getExample: function (inputs){ | ||
getExample: function (inputs, env){ | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, then | ||
// the best we can do is guarantee that this result will be some sort | ||
// of dictionary. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return {}; | ||
} | ||
// If the array is available and has one item, we can just borrow the | ||
// first item to build our example. | ||
return inputs.array[0]; | ||
@@ -53,0 +63,0 @@ } |
module.exports = { | ||
friendlyName: 'Find dictionaries where...', | ||
friendlyName: 'Find all by...', | ||
@@ -21,4 +21,3 @@ | ||
description: 'The array to search in (i.e. "haystack")', | ||
// example: [{}], | ||
typeclass: 'array', | ||
example: [{}], | ||
required: true | ||
@@ -29,3 +28,3 @@ }, | ||
friendlyName: 'Criteria', | ||
typeclass: 'dictionary', | ||
example: {}, | ||
description: 'The Lodash/Waterline-style criteria to use (i.e. "metal detector")', | ||
@@ -45,4 +44,19 @@ required: true | ||
description: 'Returns the matching dictionaries.', | ||
getExample: function (inputs){ | ||
return [inputs.array[0]]; | ||
getExample: function (inputs, env){ | ||
var _ = env._; | ||
// If the array is not available yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of dictionaries. | ||
if (_.isUndefined(inputs.array)) { | ||
return [{}]; | ||
} | ||
// If the array is available and has one item, we can just borrow that first item | ||
// to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
// Otherwise, the best we can do is send back [{}]. | ||
return [{}]; | ||
} | ||
@@ -49,0 +63,0 @@ } |
@@ -24,3 +24,3 @@ module.exports = { | ||
description: 'The array to search in (i.e. "haystack")', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -30,3 +30,3 @@ }, | ||
item: { | ||
typeclass: '*', | ||
example: '*', | ||
friendlyName: 'Search for', | ||
@@ -40,5 +40,2 @@ description: 'The value to search for (i.e. "needle")', | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -45,0 +42,0 @@ error: { |
@@ -24,3 +24,3 @@ module.exports = { | ||
description: 'The array where the new item should be inserted.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -39,3 +39,3 @@ }, | ||
description: 'The new item to insert into the array.', | ||
typeclass: '*', | ||
example: '*', | ||
required: true | ||
@@ -62,10 +62,24 @@ } | ||
description: 'Returns the last item in the array.', | ||
getExample: function (inputs) { | ||
if (inputs.index < 0) { | ||
return; | ||
getExample: function (inputs, env) { | ||
var _ = env._; | ||
// If neither the array nor the value to add are not available yet, the best we | ||
// can do is guarantee that this result will be some sort of homogeneous array. | ||
if (_.isUndefined(inputs.array) && _.isUndefined(inputs.value)) { | ||
return ['*']; | ||
} | ||
if (inputs.array.length <= inputs.index) { | ||
return; | ||
// If the array is available and has at least one item, we can just borrow | ||
// that first item to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
return [inputs.value]; | ||
// If the new vlue is available, we can borrow that to build our example | ||
if (_.isUndefined(inputs.value)) { | ||
return [inputs.value]; | ||
} | ||
// Otherwise, the best we can do is send back ['*']. | ||
return ['*']; | ||
} | ||
@@ -72,0 +86,0 @@ }, |
@@ -10,5 +10,2 @@ module.exports = { | ||
extendedDescription: '', | ||
sync: true, | ||
@@ -25,3 +22,3 @@ | ||
description: 'The array containing the desired item.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -33,5 +30,2 @@ } | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -49,4 +43,14 @@ | ||
description: 'Returns the last item in the array.', | ||
getExample: function (inputs) { | ||
if (inputs.array.length===0) return; | ||
getExample: function (inputs,env) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, then | ||
// the best we can do is guarantee that this result will be some sort | ||
// of JSON-compatible value. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return '*'; | ||
} | ||
// If the array is available and has one item, we can just borrow the | ||
// last item to build our example. | ||
return inputs.array[inputs.array.length-1]; | ||
@@ -53,0 +57,0 @@ } |
@@ -23,3 +23,3 @@ module.exports = { | ||
friendlyName: 'Array to count', | ||
typeclass: 'array', | ||
example: ['*'], | ||
description: 'The array of items to count', | ||
@@ -32,5 +32,2 @@ required: true | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -37,0 +34,0 @@ |
@@ -76,4 +76,14 @@ module.exports = { | ||
description: 'Done.', | ||
getExample: function (inputs){ | ||
return [inputs.itemExample]; | ||
getExample: function (inputs, env){ | ||
var _ = env._; | ||
// If this exit is traversed, its output type will always be | ||
// equivalent to a homogeneous array with items like `inputs.itemExample` | ||
if (!_.isUndefined(inputs.itemExample)) { | ||
return [inputs.itemExample]; | ||
} | ||
// But if `itemExample` is not available yet, the best we can | ||
// do is fall back to an array of JSON-serializable values. | ||
return ['*']; | ||
} | ||
@@ -80,0 +90,0 @@ } |
@@ -24,3 +24,3 @@ module.exports = { | ||
description: 'The array containing the desired item.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -54,3 +54,14 @@ }, | ||
description: 'Returns the item at the specified index within the array.', | ||
getExample: function (inputs) { | ||
getExample: function (inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, then | ||
// the best we can do is guarantee that this result will be some sort | ||
// of JSON-compatible value. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return '*'; | ||
} | ||
// If the array is available and has one item, we can just borrow the | ||
// first item to build our example. | ||
return inputs.array[0]; | ||
@@ -57,0 +68,0 @@ } |
@@ -10,5 +10,2 @@ module.exports = { | ||
extendedDescription: '', | ||
sync: true, | ||
@@ -25,4 +22,3 @@ | ||
description: 'The array of dictionaries to iterate over.', | ||
typeclass: 'array', | ||
// example: [{}], | ||
example: [{}], | ||
required: true | ||
@@ -41,5 +37,2 @@ }, | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -54,6 +47,26 @@ | ||
getExample: function(inputs, env) { | ||
if (Array.isArray(inputs.array) && inputs.array.length) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, the best we | ||
// can do is guarantee that this result will be some sort of homogeneous array | ||
// of JSON-compatible values. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return ['*']; | ||
} | ||
// If the name of the key is not available yet, we can't use it to figure out which | ||
// item to grab, so the best we can do is send back ['*'] | ||
if (_.isUndefined(inputs.key)) { | ||
return ['*']; | ||
} | ||
// But if we have the key name, and the array is available with at least one item, | ||
// we can just borrow that first item, grab the value of the `key`, and if that exists, | ||
// use that to build our example. | ||
if (!_.isUndefined(inputs.array[0][inputs.key])) { | ||
return [inputs.array[0][inputs.key]]; | ||
} | ||
return; | ||
// Otherwise, if it doesn't exist, we'll fall back to the same generic guarantee we | ||
// used above. | ||
return ['*']; | ||
} | ||
@@ -67,3 +80,2 @@ } | ||
var _ = require('lodash'); | ||
return exits.success(_.pluck(inputs.array, inputs.key)); | ||
@@ -70,0 +82,0 @@ } |
@@ -10,5 +10,2 @@ module.exports = { | ||
extendedDescription: '', | ||
inputs: { | ||
@@ -100,4 +97,14 @@ | ||
description: 'Done.', | ||
getExample: function (inputs){ | ||
return inputs.resultExample; | ||
getExample: function (inputs, env){ | ||
var _ = env._; | ||
// If this exit is traversed, its output type will always be | ||
// equivalent to `inputs.resultExample` | ||
if (!_.isUndefined(inputs.resultExample)) { | ||
return inputs.resultExample; | ||
} | ||
// But if `resultExample` is not available yet, the best we can | ||
// do is fall back to some kind of JSON-serializable value. | ||
return '*'; | ||
} | ||
@@ -104,0 +111,0 @@ } |
@@ -24,3 +24,3 @@ module.exports = { | ||
description: 'The array to reverse.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -44,2 +44,13 @@ } | ||
getExample: function(inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, then | ||
// the best we can do is guarantee that this result will be some sort | ||
// of homogeneous array. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return '*'; | ||
} | ||
// If the array is available and has one item, we can just go ahead | ||
// and actually reverse the array. | ||
return inputs.array.reverse(); | ||
@@ -46,0 +57,0 @@ } |
@@ -16,3 +16,3 @@ module.exports = { | ||
array: { | ||
typeclass: 'array', | ||
example: ['*'], | ||
description: 'The array of items to pick from', | ||
@@ -25,5 +25,2 @@ required: true | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -40,2 +37,13 @@ | ||
getExample: function(inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, then | ||
// the best we can do is guarantee that this result will be some sort | ||
// of JSON-compatible value. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return '*'; | ||
} | ||
// If the array is available and has one item, we can just borrow the | ||
// first item to build our example. | ||
return inputs.array[0]; | ||
@@ -42,0 +50,0 @@ }, |
@@ -24,3 +24,3 @@ module.exports = { | ||
description: 'The array to slice.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -48,5 +48,2 @@ }, | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -60,3 +57,14 @@ | ||
description: 'Done.', | ||
getExample: function (inputs) { | ||
getExample: function (inputs,env) { | ||
var _ = env._; | ||
// If the array is not available yet, or none of its items are, the best we | ||
// can do is guarantee that this result will be some sort of homogeneous array | ||
// of JSON-compatible values. | ||
if (_.isUndefined(inputs.array) || inputs.array.length < 1) { | ||
return ['*']; | ||
} | ||
// If the array is available and has at least one item, we can just borrow that | ||
// first item to build our example. | ||
return [inputs.array[0]]; | ||
@@ -63,0 +71,0 @@ } |
@@ -10,5 +10,2 @@ module.exports = { | ||
extendedDescription: '', | ||
sync: true, | ||
@@ -25,4 +22,3 @@ | ||
description: 'The array to sort.', | ||
typeclass: 'array', | ||
// example: [{}], | ||
example: [{}], | ||
required: true | ||
@@ -41,5 +37,2 @@ }, | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -54,5 +47,18 @@ | ||
getExample: function(inputs, env) { | ||
if (Array.isArray(inputs.array) && inputs.array.length) { | ||
var _ = env._; | ||
// If the array is not available yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of dictionaries. | ||
if (_.isUndefined(inputs.array)) { | ||
return [{}]; | ||
} | ||
// If the array is available and has one item, we can just borrow that first item | ||
// to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
// Otherwise, the best we can do is send back [{}]. | ||
return [{}]; | ||
} | ||
@@ -59,0 +65,0 @@ } |
@@ -31,5 +31,2 @@ module.exports = { | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -36,0 +33,0 @@ |
@@ -31,5 +31,2 @@ module.exports = { | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -36,0 +33,0 @@ |
@@ -24,4 +24,3 @@ module.exports = { | ||
description: 'The array of dictionaries to remove duplicates from.', | ||
typeclass: 'array', | ||
// example: [{}], | ||
example: [{}], | ||
required: true | ||
@@ -40,5 +39,2 @@ }, | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -53,4 +49,19 @@ | ||
friendlyName: 'then', | ||
getExample: function(inputs, exits) { | ||
return inputs.array; | ||
getExample: function(inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of dictionaries. | ||
if (_.isUndefined(inputs.array)) { | ||
return [{}]; | ||
} | ||
// If the array is available and has one item, we can just borrow that first item | ||
// to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
// Otherwise, the best we can do is send back [{}]. | ||
return [{}]; | ||
} | ||
@@ -57,0 +68,0 @@ } |
@@ -10,5 +10,2 @@ module.exports = { | ||
extendedDescription: '', | ||
sync: true, | ||
@@ -24,3 +21,3 @@ | ||
description: 'The array to remove duplicates from.', | ||
typeclass: 'array', | ||
example: ['*'], | ||
required: true | ||
@@ -32,5 +29,2 @@ } | ||
defaultExit: 'success', | ||
exits: { | ||
@@ -45,4 +39,20 @@ | ||
friendlyName: 'then', | ||
getExample: function(inputs, exits) { | ||
return inputs.array; | ||
getExample: function(inputs, env) { | ||
var _ = env._; | ||
// If the array is not available yet, the best we can do is guarantee | ||
// that this result will be some sort of homogeneous array of JSON-compatible | ||
// values. | ||
if (_.isUndefined(inputs.array)) { | ||
return ['*']; | ||
} | ||
// If the array is available and has one item, we can just borrow that first item | ||
// to build our example. | ||
if (inputs.array.length > 0) { | ||
return [inputs.array[0]]; | ||
} | ||
// Otherwise, the best we can do is send back ['*']. | ||
return ['*']; | ||
} | ||
@@ -49,0 +59,0 @@ } |
{ | ||
"name": "machinepack-arrays", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Work with arrays.", | ||
@@ -27,6 +27,14 @@ "scripts": { | ||
"machines": [ | ||
"each", | ||
"map", | ||
"reduce", | ||
"find-one", | ||
"find-where", | ||
"reverse", | ||
"index-of", | ||
"insert", | ||
"slice", | ||
"length", | ||
"reverse", | ||
"sample", | ||
"concat", | ||
@@ -37,2 +45,5 @@ "last", | ||
"pluck", | ||
"sort-by", | ||
"uniq-by", | ||
"uniq", | ||
"sort-strings", | ||
@@ -39,0 +50,0 @@ "sort-numbers" |
@@ -12,6 +12,6 @@ { | ||
"returns": [ | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
2, | ||
3, | ||
4, | ||
5 | ||
] | ||
@@ -28,12 +28,12 @@ }, | ||
{ | ||
"id": "2" | ||
"id": 2 | ||
}, | ||
{ | ||
"id": "3" | ||
"id": 3 | ||
}, | ||
{ | ||
"id": "4" | ||
"id": 4 | ||
}, | ||
{ | ||
"id": "5" | ||
"id": 5 | ||
} | ||
@@ -50,5 +50,5 @@ ] | ||
"returns": [ | ||
"10", | ||
"21", | ||
"32" | ||
10, | ||
21, | ||
32 | ||
] | ||
@@ -64,5 +64,5 @@ }, | ||
"returns": [ | ||
"10", | ||
"21", | ||
"32" | ||
10, | ||
21, | ||
32 | ||
] | ||
@@ -69,0 +69,0 @@ } |
@@ -5,7 +5,2 @@ { | ||
{ | ||
"todo": true, | ||
"using": {}, | ||
"outcome": "success" | ||
}, | ||
{ | ||
"using": { | ||
@@ -24,2 +19,2 @@ "array": "[{\"name\":\"Lucy\"},{\"name\":\"Ricky\"},{\"name\":\"Louise\"},{\"name\":\"Estelle\"}]", | ||
] | ||
} | ||
} |
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
61187
2048