total-serialism
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,5 +0,5 @@ | ||
const Gen = require('./lib/generate.js'); | ||
const Gen = require('./lib/gen-basic.js'); | ||
const Transform = require('./lib/transform.js'); | ||
// const Algo = require('./lib/algorithmic.js'); | ||
// const Util = require('./lib/utilities.js'); | ||
// const Trans = require('./lib/transformational.js'); | ||
// const Dict = require('./lib/dict.js'); | ||
@@ -11,3 +11,3 @@ | ||
exports.Gen = Gen; | ||
// exports.Trans = Trans; | ||
exports.Transform = Transform; | ||
// exports.Algo = Algo; | ||
@@ -14,0 +14,0 @@ // exports.Util = Util; |
@@ -1,14 +0,94 @@ | ||
const Util = require('./utilities.js'); | ||
//============================================================================== | ||
// transform.js | ||
// part of 'total-serialism' Package | ||
// by Timo Hoogland (@t.mo / @tmhglnd), www.timohoogland.com | ||
// MIT License | ||
// | ||
// Basic methods that can transform number sequences | ||
// | ||
// | ||
// credits: | ||
// - Based on Laurie Spiegel's suggestion to "extract a basic "library" | ||
// consisting of the most elemental transformations which have | ||
// consistently been successfully used on musical patterns, a basic | ||
// group of "tried-and-true" musical manipulations.", in Manipulation | ||
// of Musical Patterns (1981) | ||
//============================================================================== | ||
// rotate an array in a certain direction | ||
const Util = require('./utility.js'); | ||
// rotate the position of items in an array | ||
// 1 = rotate right, -1 = rotate left | ||
function rotate(arr, rot){ | ||
var outList = new Array(arr.length); | ||
if (rot === void(0)){ rot = 0; } //default | ||
for (var i = 0; i < arr.length; i++){ | ||
outList[i] = arr[Util.mod((i - rot), arr.length)] | ||
// | ||
// @param {Array} | ||
// @param {steps to rotate} default=0 | ||
// @return {Array} | ||
// | ||
function rotate(a=[0], r=0){ | ||
var l = a.length; | ||
var arr = new Array(l); | ||
for (var i=0; i<l; i++){ | ||
arr[i] = a[Util.mod((i - r), l)] | ||
} | ||
return outList; | ||
}//rotate() | ||
return arr; | ||
} | ||
exports.rotate = rotate; | ||
// reverse the order of items in an Array | ||
// | ||
// @param {Array} | ||
// @return {Array} | ||
// | ||
function reverse(a=[0]){ | ||
return a.slice().reverse(); | ||
} | ||
exports.reverse = reverse; | ||
// duplicate an array a certain amount of times | ||
// | ||
// @param {Array} | ||
// @param {amount of dupicates} default=2 | ||
// @return {Array} | ||
// | ||
function duplicate(a=[0], d=2){ | ||
var arr = []; | ||
for (var i=0; i<d; i++){ | ||
arr = arr.concat(a); | ||
} | ||
return arr; | ||
} | ||
exports.duplicate = duplicate; | ||
// filter duplicate items from an array | ||
// | ||
// @param {Array} | ||
// @return {Array} | ||
// | ||
function unique(a=[0]){ | ||
return [...new Set(a)]; | ||
} | ||
exports.unique = unique; | ||
// shuffle a list, based on the | ||
// Fisher-Yates shuffle algorithm | ||
// by Ronald Fisher and Frank Yates in 1938 | ||
// algorithm has run time complexity of O(n) | ||
// | ||
// @param {Array} | ||
// @return {Array} | ||
// | ||
function shuffle(a=[0]){ | ||
var arr = a.slice(); | ||
for (var i=arr.length-1; i>0; i-=1) { | ||
var j = Math.floor(Math.random() * (i + 1)); | ||
var t = arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j] = t; | ||
} | ||
return arr; | ||
} | ||
exports.shuffle = shuffle; | ||
/* | ||
// add all values of two lists on the same index | ||
@@ -34,3 +114,3 @@ // preserves length of longest list | ||
return listOut; | ||
}//merge() | ||
} | ||
@@ -46,9 +126,4 @@ // combine arrays to one array | ||
return outList; | ||
}//combine() | ||
} | ||
// reverse an input array putting last item in the front etc. | ||
function reverse(arr){ | ||
return arr.slice().reverse(); | ||
}//reverse() | ||
// reverse an array, and concatenate to the input array | ||
@@ -64,3 +139,3 @@ // creating a palindrome of the array | ||
return outList.concat(rev); | ||
}//palin() | ||
} | ||
@@ -75,14 +150,4 @@ // invert a list of values by mapping the lowest value | ||
return arr.slice().map(v => max - v + min); | ||
}//invert() | ||
} | ||
// duplicate an array a certain amount of times | ||
function duplicate(arr, dups){ | ||
if (dups === void(0)){ dups = 1; } | ||
var outList = []; | ||
for (var i=0; i<dups; i++){ | ||
outList = outList.concat(arr); | ||
} | ||
return outList; | ||
}//duplicate() | ||
// duplicate an array, but with add an offset to every value | ||
@@ -97,33 +162,4 @@ // based on the arguments given | ||
return outList; | ||
}//clone() | ||
} | ||
// filter duplicates from an array output only | ||
function unique(arr){ | ||
return [...new Set(arr)]; | ||
}//unique() | ||
// shuffle a list with seedable randomness | ||
// Fisher-Yates shuffle algorithm | ||
// by Ronald Fisher and Frank Yates in 1938 | ||
// algorithm has run time complexity of O(n) | ||
function shuffle(arr){ | ||
var outList = arr.slice(); | ||
for (var i=outList.length-1; i>0; i-=1) { | ||
var j = Math.floor(Math.random() * (i + 1)); | ||
var t = outList[i]; | ||
outList[i] = outList[j]; | ||
outList[j] = t; | ||
} | ||
return outList; | ||
}//shuffle() | ||
exports.rotate = rotate; | ||
exports.merge = merge; | ||
exports.join = join; | ||
exports.reverse = reverse; | ||
exports.palin = palin; | ||
exports.invert = invert; | ||
exports.duplicate = duplicate; | ||
exports.clone = clone; | ||
exports.unique = unique; | ||
exports.shuffle = shuffle; | ||
*/ |
{ | ||
"name": "total-serialism", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A set of methods for the generation and transformation of number sequences in algorithmic composition", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const Serialism = require("../index"); | ||
const Gen = require("../index").Gen; | ||
const Trans = require("../index").Transform; | ||
test("Gen.spread(-5)"); | ||
test("Gen.spread(5, 10)"); | ||
/* | ||
Test criteria: | ||
- test for no argument | ||
- test for single argument | ||
- test for multiple arguments | ||
- test for negative values | ||
*/ | ||
test("Gen.spreadFloat(5, 0, 11)"); | ||
test("Gen.spreadFloat(5, -4, 6)"); | ||
test("Gen.spreadInclusiveFloat(5, -4, 4)"); | ||
// testGen(); | ||
testTransform(); | ||
// test("Gen.spreadFloat(48, 0, 12)"); | ||
// test("Gen.spreadExp(10, 10, 1000, 4)"); | ||
// test("Gen.spreadinclusive(5, 0, 12)"); | ||
// test("Gen.spread_f(5, 0, 1)"); | ||
// test("Gen.spreadinclusive_f(6, 0, 1)"); | ||
function testGen(){ | ||
test("Gen.spread()"); | ||
test("Gen.spread(-5)"); | ||
test("Gen.spread(5, 10)"); | ||
test("Gen.spreadFloat(5, 0, 11)"); | ||
test("Gen.spreadFloat(4, -1, 1)"); | ||
test("Gen.spreadInclusiveFloat(5, -1, 1)"); | ||
test("Gen.spreadInclusiveFloatExp(5, 0, 1, 2)"); | ||
test("Gen.fill()"); | ||
test("Gen.fill(10, 2, 15, 3, 20, 4)"); | ||
} | ||
// test("Gen.spread(6, -100, 100)"); | ||
// test("Gen.spreadinclusive(4, -50, -10)"); | ||
// test("Gen.spread_f(5, 2)"); | ||
// test("Gen.spreadinclusive_f(5, -2, 2)"); | ||
function testTransform(){ | ||
test("Trans.rotate()"); | ||
test("Trans.rotate([0, 1, 2, 3])"); | ||
test("Trans.rotate([0, 1, 2, 3], 1)"); | ||
test("Trans.rotate([0, 1, 2, 3], -1)"); | ||
test("Trans.rotate([0, [11, 12], 2, 3], 1)"); | ||
test("Trans.reverse()"); | ||
test("Trans.reverse([0, 1, 2, 3])"); | ||
test("Trans.reverse([0, [11, 12], 2, 3])"); | ||
test("Trans.duplicate()"); | ||
test("Trans.duplicate([0, 1, 2])"); | ||
test("Trans.duplicate([0, 1, 2], 4)"); | ||
test("Trans.unique()"); | ||
test("Trans.unique([0, 1, 2, 2, 1])"); | ||
test("Trans.shuffle()"); | ||
test("Trans.shuffle([0, 1, 2, 3])"); | ||
test("Trans.shuffle([0, 1, 2, 3])"); | ||
} | ||
function test(f){ | ||
// print the written function to console | ||
console.log(f); | ||
// evaluate the function and print results | ||
console.log("=> ", eval(f), "\n"); | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20020
13
645