Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

total-serialism

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

total-serialism - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

4

index.js

@@ -1,2 +0,2 @@

const Gen = require('./lib/gen-basic.js');
const Generative = require('./lib/gen-basic.js');
const Transform = require('./lib/transform.js');

@@ -10,3 +10,3 @@ // const Algo = require('./lib/algorithmic.js');

exports.Gen = Gen;
exports.Generative = Generative;
exports.Transform = Transform;

@@ -13,0 +13,0 @@ // exports.Algo = Algo;

@@ -146,3 +146,3 @@ //==============================================================================

function fill(...args){
if (!args.length){ args = [0, 1]; }
if (!args.length){ return [0]; }
if (args.length % 2){ args.pop(); }

@@ -149,0 +149,0 @@

@@ -11,43 +11,47 @@ //==============================================================================

// 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)
// - Many functions are 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)
//==============================================================================
// require the Utility methods
const Util = require('./utility.js');
// rotate the position of items in an array
// 1 = rotate right, -1 = rotate left
// duplicate an array, but add an offset to every value
//
// @param {Array}
// @param {steps to rotate} default=0
// @return {Array}
// @param {Array} -> array to clone
// @param {Int, Int2, ... Int-n} -> amount of clones with integer offset
//
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)]
function clone(a=[0], ...c){
if (!c.length) { c = [0, 0]; }
var arr = [];
for (var i=0; i<c.length; i++){
arr = arr.concat(a.map(v => v + c[i]));
}
return arr;
}
exports.rotate = rotate;
exports.clone = clone;
// reverse the order of items in an Array
// combine arrays into one array
// multiple arrays as arguments possible
//
// @param {Array}
// @params {Array0, Array1, ..., Array-n} -> Arrays to join
// @return {Array}
//
function reverse(a=[0]){
return a.slice().reverse();
function combine(...args){
if (!args.length){ return [0]; }
var arr = [];
for (var i=0; i<args.length; i++){
arr = arr.concat(args[i]);
}
return arr;
}
exports.reverse = reverse;
exports.combine = combine;
// duplicate an array a certain amount of times
//
// @param {Array}
// @param {amount of dupicates} default=2
// @param {Array} -> array to duplicate
// @param {Int} -> amount of output duplicates (optional, default=2)
// @return {Array}

@@ -57,3 +61,3 @@ //

var arr = [];
for (var i=0; i<d; i++){
for (var i=0; i<Math.max(1,d); i++){
arr = arr.concat(a);

@@ -65,99 +69,150 @@ }

// filter duplicate items from an array
// interleave two or more arrays
//
// @param {Array}
// @param {Array0, Array1, ..., Array-n} -> arrays to interleave
// @return {Array}
//
function unique(a=[0]){
return [...new Set(a)];
//
function lace(...args){
if (!args.length){ return [0]; }
var l = 0;
for (i in args){
l = Math.max(args[i].length, l);
}
var arr = [];
for (var i=0; i<l; i++){
for (var k in args){
v = args[k][i];
if (v != undefined){ arr.push(v); }
}
}
return arr;
}
exports.unique = unique;
exports.lace = lace;
// 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)
// invert a list of values by mapping the lowest value
// to the highest value and vice versa, flipping everything
// in between.
// Second optional argument sets the center to flip values against.
// Third optional argument sets a range to flip values against.
//
// @param {Array}
// @param {Array} -> array to invert
// @param {Int} -> invert center / low range (optional)
// @param {Int} -> high range (optional)
// @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;
function invert(arr=[0], lo, hi){
if (lo === undefined){
hi = Math.max(...arr);
lo = Math.min(...arr);
} else if (hi === undefined){
hi = lo;
}
return arr;
return arr.slice().map(v => hi - v + lo);
}
exports.shuffle = shuffle;
exports.invert = invert;
/*
// add all values of two lists on the same index
// preserves length of longest list
function merge(arr1, arr2){
var listOut = [];
var len1 = arr1.length;
var len2 = arr2.length;
// merge all values of two arrays on the same index
// into a 2D array. preserves length of longest list
//
// @params {Array0, Array1, ..., Array-n} -> Arrays to merge
// @return {Array}
//
function merge(...args){
if (!args.length){ return [0]; }
if (len1 < len2){
var temp = arr2;
arr2 = arr1;
arr1 = temp;
var l = 0;
for (i in args){
l = Math.max(args[i].length, l);
}
for (var i = 0; i < arr1.length; i++){
if (i < arr2.length){
listOut[i] = arr1[i] + arr2[i];
} else {
listOut[i] = arr1[i];
var arr = new Array(l);
for (var i=0; i<l; i++){
var a = [];
for (var k in args){
v = args[k][i];
if (v != undefined){ a.push(v); }
}
arr[i] = a;
}
return listOut;
return arr;
}
exports.merge = merge;
// combine arrays to one array
// can have many arrays as arguments
// looks up the array from the dict
function join(arrays){
var outList = [];
for (var i=0; i<arrays.length; i++){
outList = outList.concat(arrays[i]);
}
return outList;
}
// reverse an array and concatenate to the input
// creating a palindrome of the array
//
// @param {Array} -> array to make palindrome of
// @param {Bool} -> no-double flag (optional, default=false)
// @return {Array}
//
function palindrome(a=[0], noDouble=false){
var arr = a.slice();
var rev = a.reverse();
// reverse an array, and concatenate to the input array
// creating a palindrome of the array
function palin(arr, no_double){
var outList = arr.slice();
if (no_double === void(0)){ no_double = 0; } //default
var rev = arr.slice().reverse();
if (no_double){
if (noDouble){
rev = rev.slice(1, rev.length-1);
}
return outList.concat(rev);
return arr.concat(rev);
}
exports.palindrome = palindrome;
// invert a list of values by mapping the lowest value
// to the highest value, vice versa, and flipping everything
// in between. If no range, values are flipped between
function invert(arr, range){
if (range === void(0)){ range = 0; } //default
var max = (range)? Math.max(...arr) : 12;
var min = (range)? Math.min(...arr) : 0;
return arr.slice().map(v => max - v + min);
// reverse the order of items in an Array
//
// @param {Array} -> array to reverse
// @return {Array}
//
function reverse(a=[0]){
return a.slice().reverse();
}
exports.reverse = reverse;
// duplicate an array, but with add an offset to every value
// based on the arguments given
function clone(arr, clones){
if (clones === void(0)){ clones = [0, 0]; }
var outList = [];
for (var i=0; i<clones.length; i++){
outList = outList.concat(arr.map(v => v + clones[i]));
// rotate the position of items in an array
// 1 = direction right, -1 = direction left
//
// @param {Array} -> array to rotate
// @param {Int} -> steps to rotate (optional, 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;
return arr;
}
exports.rotate = rotate;
*/
// 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} -> array to shuffle
// @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;
// filter duplicate items from an array
//
// @param {Array} -> array to filter
// @return {Array}
//
function unique(a=[0]){
return [...new Set(a)];
}
exports.unique = unique;
{
"name": "total-serialism",
"version": "1.0.2",
"description": "A set of methods for the generation and transformation of number sequences in algorithmic composition",
"version": "1.0.3",
"description": "A set of methods for the generation and transformation of number sequences useful in algorithmic composition",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -1,11 +0,82 @@

# serialism.js
# total-serialism
A set of methods for the generation and transformation of number sequences in algorithmic composition
`total-serialism` is a set of methods for the generation and transformation of number sequences mainly designed for algorithmic composition of music.
# About
!!! Work-In-Progress !!!
!!! Currently under development, not working properly yet !!!
# Install
```
$ npm install total-serialism
```
# Usage
The entire library
```js
const Serial = require('total-serialism');
```
Or an individual section
```js
const Gen = require('total-serialism').Generative;
const Trs = require('total-serialism').Transform;
```
# Examples
```js
const Gen = require('total-serialism').Generative;
const Trs = require('total-serialism').Transform;
// generate an array of 7 ints between range 0-7
Gen.spread(7); //=> [0, 1, 2, 3, 4, 5, 6]
// generate an array of 5 ints between range 7-19
Gen.spread(5, 7, 19); //=> [7, 9, 11, 14, 16]
// generate an array of 9 floats between -1 - 1 (inclusive)
Gen.spreadInclusiveFloat(9, -1, 1); //=> [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1]
// fill an array with duplicates of a value
Gen.fill(10, 2, 15, 3, 20, 4); //=> [10, 10, 15, 15, 15, 20, 20, 20, 20]
// duplicate an array with an offset added to every value
Trs.clone([0, 5, 7], 0, 12, -12); //=> [0, 5, 7, 12, 17, 19, -12, -7, -5]
// combine multiple numbers/arrays into one
Trs.combine([0, 5], 12, [7, 3]); //=> [0, 5, 12, 7, 3]
// duplicate an array certain amount of times
Trs.duplicate([0, 5, 7], 3); //=> [0, 5, 7, 0, 5, 7, 0, 5, 7]
// invert an array around a center point
Trs.invert([0, 2, 5, 10, 13], 5); //=> [10, 8, 5, 0, -3]
// interleave multiple arrays into one
Trs.lace([0, 5, 9], [3, 3], [7, 12, 11, -1]); //=> [0, 3, 7, 5, 3, 12, 9, 11, -1]
// merge arrays into a 2D-array
Trs.merge([0, 3, 7], [3, 12], [12, -1, 19, 5]); //=> [[0, 3, 12], [3, 12, -1], [7, 19], [5]]
// generate a palindrome of an array
Trs.palindrome([0, 3, 5, 7]); //=> [0, 3, 5, 7, 7, 5, 3, 0]
// rotate an array in positive or negative direction
Trs.rotate([0, 5, 7, 12], -1); //=> [5, 7, 12, 0]
// reverse an array
Trs.reverse([0, 5, 7, 12]); //=> [12, 7, 5, 0]
// shuffle the items in an array (Fisher-Yates shuffle algorithm)
Trs.shuffle([0, 5, 7, 12]); //=> [7, 5, 0, 12]
// remove duplicates from an array, leave order of appearance intact
Trs.unique([5, 7, 5, 0, 12, 7, 5]); //=> [5, 7, 0, 12]
```
# License
The MIT License
const Serialism = require("../index");
const Gen = require("../index").Gen;
const Serial = require("../index");
const Gen = require("../index").Generative;
const Trans = require("../index").Transform;

@@ -14,3 +14,3 @@

// testGen();
testGen();
testTransform();

@@ -20,7 +20,8 @@

test("Gen.spread()");
test("Gen.spread(-5)");
test("Gen.spread(5, 10)");
test("Gen.spreadFloat(5, 0, 11)");
test("Gen.spreadFloat(7)");
test("Gen.spread(5, 7, 19)");
test("Gen.spread(4, 10, 2)");
test("Gen.spreadFloat(5, 2, 11)");
test("Gen.spreadFloat(4, -1, 1)");
test("Gen.spreadInclusiveFloat(5, -1, 1)");
test("Gen.spreadInclusiveFloat(9, -1, 1)");
test("Gen.spreadInclusiveFloatExp(5, 0, 1, 2)");

@@ -33,22 +34,48 @@

function testTransform(){
test("Trans.clone()");
test("Trans.clone([0, 5, 7], 0, 12, -12)");
test("Trans.clone(['hello', 'world'], 0, 1, 2)");
test("Trans.combine()");
test("Trans.combine([0, 1], [[22, 33], 4])");
test("Trans.combine([0, 5], 12, [7, 3])");
test("Trans.combine(0, 12, 3)");
test("Trans.duplicate()");
test("Trans.duplicate([0, 1, 2])");
test("Trans.duplicate([0, 1, 2], 4)");
test("Trans.invert()");
test("Trans.invert([0, 2, 5, 10, 13])");
test("Trans.invert([0, 2, 5, 10, 13], 5)");
test("Trans.invert([0, 2, 5, 10, 13], 0, 12)");
test("Trans.lace([0, 2, 4], [1, 3, 5], ['hello'])");
test("Trans.lace([0, 5, 9], [3, 3], [7, 12, 11, -1])");
test("Trans.merge()");
test("Trans.merge([0, 3, 7], [3, 12], [12, -1, 19, 5])");
test("Trans.merge([0, 1, 2, 3], [10, 20, 30, 40])");
test("Trans.palindrome()");
test("Trans.palindrome([0, 1, 2, 3])");
test("Trans.palindrome([0, 1, 2, 3], true)");
test("Trans.palindrome([0, 1, 2, 3], 1)");
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, 5, 7, 12], -1)");
test("Trans.rotate([0, [11, 12], 2, 3], 1)");
test("Trans.reverse()");
test("Trans.reverse([0, 1, 2, 3])");
test("Trans.reverse([0, 5, 7, 12])");
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.shuffle()");
test("Trans.shuffle([0, 5, 7, 12])");
test("Trans.shuffle([0, 5, 7, 12])");
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])");
test("Trans.unique([5, 7, 5, 0, 12, 7, 5])");
}

@@ -55,0 +82,0 @@

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