New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.6.12 to 1.7.0

src/statistic.js

6

index.js

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

//==============================================================================
//=======================================================================
// index.js

@@ -10,3 +10,3 @@ // main of 'total-serialism' Package

// composition for music in mind.
//==============================================================================
//=======================================================================

@@ -18,2 +18,3 @@ // require the various libraries

const Transform = require('./src/transform.js');
const Statistic = require('./src/statistic.js')
const Translate = require('./src/translate.js');

@@ -27,2 +28,3 @@ const Utility = require('./src/utility.js');

exports.Transform = Transform;
exports.Statistic = Statistic;
exports.Translate = Translate;

@@ -29,0 +31,0 @@ exports.Utility = Utility;

{
"name": "total-serialism",
"version": "1.6.12",
"version": "1.7.0",
"description": "A set of methods for the generation and transformation of number sequences useful in algorithmic composition",
"main": "index.js",
"scripts": {
"test": "node test/serialism.test.js",
"test": "nodemon test/serialism.test.js",
"build": "npm run database && npm run clean && npm run bundle && npm run build-es5 && npm run build-min",

@@ -63,4 +63,5 @@ "clean": "rm -rf build",

"fs-extra": "^9.0.0",
"nodemon": "^2.0.4",
"uglify-js": "^3.8.1"
}
}

@@ -9,3 +9,3 @@ # Total Serialism

Install in node_modules:
## Install in node_modules

@@ -23,3 +23,3 @@ ```

Import es5 version
## Import es5 version

@@ -33,8 +33,18 @@ ```js

Include bundled minified es5 through url in index.html:
## Include in html
Include bundled minified es5 through url in index.html
```html
<script src="https://unpkg.com/total-serialism@1.6.8/build/ts.es5.min.js"></script>
<script src="https://unpkg.com/total-serialism/build/ts.es5.min.js"></script>
```
or a specific version with eg. `@1.6.12`
```html
<script src="https://unpkg.com/total-serialism@1.6.12/build/ts.es5.min.js"></script>
```
Use in a html `<script>` like so:
```js

@@ -60,2 +70,3 @@ // entire package

- [Transformative Methods](#transformative-methods)
- [Statistic Methods](#statistic-methods)
- [Translate Methods](#translate-methods)

@@ -78,2 +89,18 @@ - [Examples](#examples)

A libary of statistical methods is now included, featuring methods for returning the mean, median and mode from an array
```js
// Get the average (artihmetic mean) value from an array
Stat.average([1, 2, 3, 4, 5, 6, 7, 8, 9]);
//=> 5
// Return the center value (median) from an array
Stat.center([1, 5, 6, 9, 13]);
//=> 6
// Returns the most common value (mode) from an array as an array
Stat.common([8, 4, 3, 11, 9, 0, 11, 2, 10, 5, 11, 0]);
//=> [ 11 ]
```
Set a global scale and map relative values to that scale to stay in tune

@@ -85,6 +112,2 @@

// Map relative numbers to a specified scale class (excluding root)
TL.toScale([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);;
//=> [ 0, 0, 2, 3, 3, 5, 7, 7, 8, 8, 11, 11 ]
// Map relative numbers to a specified scale class (including root)

@@ -104,19 +127,8 @@ // output as midi value. Specify an octave (default = 'C3' = 4 => 48)

Pick random values from an urn filled with a range of integers
```js
// with default range 0 to 12 (exclusive), influenced by the random seed
Rand.urn(5);
//=> [ 3, 6, 2, 8, 7 ]
```
Generate Pisano periods and Fibonacci sequences
Generate Pisano periods from Fibonacci sequences
```js
Algo.pisano(7);
//=> [ 0, 1, 1, 2, 3, 5, 1, 6, 0, 6, 6, 5, 4, 2, 6, 1 ]
```
Get fibonacci values as strings (to preserve the big numbers)
```js
Algo.fibonacci(2, 100);

@@ -156,6 +168,8 @@ //=> [ '354224848179261915075', '573147844013817084101' ]

//=> [ 0, 0.2, 0.4, 0.6, 0.8 ]
// Alternative: Gen.spreadF()
// generate an array of 5 ints between range 7-19 (19 inclusive)
Gen.spreadInclusive(5, 7, 19);
//=> [ 7, 9, 11, 14, 16 ]
//=> [ 7, 10, 13, 16, 19 ]
// Alternative: Gen.spreadInc()

@@ -165,7 +179,12 @@ // generate an array of 9 floats between -1 - 1 (inclusive)

//=> [ -1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1 ]
// Alternative: Gen.spreadIncF()
```
```js
// 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 ]
```
```js
// generate 10 ints with 1 period of a sine function

@@ -185,4 +204,10 @@ // between a default range of 0-12

// generate 8 floats with 1 period of a cosine function
Gen.sineFloat(8);
//=> [ 0.000, -0.707, -1, -0.707, -0.000, 0.707, 1, 0.707 ]
// Alternative: Gen.sin();
// generate 8 floats with 1 period of a cosine function
Gen.cosineFloat(8);
//=> [ 1, 0.707, 0.000, -0.707, -1, -0.707, -0.000, 0.707 ]
// Alternative: Gen.cos();
```

@@ -325,2 +350,3 @@

//=> [ 0.6291111850577886, 0.15153786227276944, 0.32814801081039646 ]
// Alternative Rand.randomF();

@@ -396,8 +422,10 @@ // generate an array of random integers in range

// combine multiple numbers/arrays into one
Mod.combine([0, 5], 12, [7, 3]);
Mod.join([0, 5], 12, [7, 3]);
//=> [ 0, 5, 12, 7, 3 ]
// Alternative: Mod.combine()
// duplicate an array certain amount of times
Mod.duplicate([0, 5, 7], 3);
Mod.copy([0, 5, 7], 3);
//=> [ 0, 5, 7, 0, 5, 7, 0, 5, 7 ]
// Alternative: Mod.duplicate()

@@ -408,2 +436,10 @@ // add zeroes to a rhythm to make it play once over a certain amount of bars

// remove values from an array
Mod.filter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 8, 10]);
//=> [ 0, 1, 2, 4, 5, 6, 7, 9 ]
// return only a specific datatype (in this case you specify the type to return)
Mod.filterType([0, 1, [1, 2], 'foo', 2, null, true, {bar: 5}, 3.14, undefined], 'number');
//=> [ 0, 1, 2, 3.14 ]
// invert an array around a center point

@@ -422,4 +458,5 @@ Mod.invert([0, 2, 5, 10, 13], 5);

// generate a palindrome of an array
Mod.palindrome([0, 3, 5, 7]);
Mod.mirror([0, 3, 5, 7]);
//=> [ 0, 3, 5, 7, 7, 5, 3, 0 ]
// Alternative Mod.palindrome()

@@ -443,2 +480,66 @@ // rotate an array in positive or negative direction

## Statistic Methods
A set of methods from Statistics and Probability Theory that allow for analysis of number sequences for statistical purposes.
```js
const Stat = require('total-serialism').Statistic;
```
```js
// Sort an array of numbers ascending
Stat.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11]);
//=> [ -12, -10, -7, -6, 2, 3, 4, 6, 8, 11 ]
// Sort an array of numbers descending with negative second argument
Stat.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11], -1);
//=> [ 11, 8, 6, 4, 3, 2, -6, -7, -10, -12 ]
// Sort a mixed array of strings and numbers
Stat.sort([10, 3.14, 'snare', 'kick', 5, -6, 'hat']);
//=> [ -6, 10, 3.14, 5, 'hat', 'kick', 'snare' ]
```
Measures of central tendencies (Mean, Median, Mode)
```js
// Get the average (artihmetic mean) value from an array
Stat.average([1, 2, 3, 4, 5, 6, 7, 8, 9]);
//=> 5
// Alternative: Stat.mean()
Stat.average([2, -6, 2, 0, 10, 9, -2, 5, -8, -11, 1, -3]);
//=> -0.0833
// Return the center value (median) from an array
Stat.center([1, 5, 6, 9, 13]);
//=> 6
// Alternative: Stat.median()
// Returns average of 2 middle values for even listlengths
// works with "official" statistics terminology
Stat.center([1, 7, 4, 2, 9, 5]);
//=> 4.5
// Returns the most common value (mode) from an array as an array
Stat.common([8, 4, 3, 11, 9, 0, 11, 2, 10, 5, 11, 0]);
//=> [ 11 ]
// In the case of a multi-modal system the array contains all common values
Stat.common([8, 4, 3, 9, 9, 0, 2, 10, 5, 11, 0, 11]);
//=> [ 0, 9, 11 ]
```
```js
// Return the maximum value from an array
Stat.maximum([-38, -53, -6, 33, 88, 32, -8, 73]);
//=> 88
// Alternative: Stat.max()
// Return the minimum value from an array
Stat.minimum([-38, -53, -6, 33, 88, 32, -8, 73]);
//=> -53
// Alternative: Stat.min()
```
## Translate Methods

@@ -461,3 +562,3 @@

//=> [ 'C4', 'G4', 'Bb4' ]
// alternative: TL.mton()
// Alternative: TL.mton()

@@ -467,3 +568,3 @@ // Convert Array of String as midi-notenames to midi-pitch

//=> [ 36, 38, 42 ]
// alternative: TL.ntom()
// Alternative: TL.ntom()

@@ -473,8 +574,8 @@ // Convert midi-pitches to frequency (A4 = 440 Hz)

//=> [ 261.6255653005986, 391.99543598174927, 523.2511306011972 ]
// alternative: TL.mtof()
// Alternative: TL.mtof()
// Convert midi-notenames to frequency (A4 = 440 Hz)
TL.noteToFreq(['c2','d2','f#2']);
TL.noteToFrequency(['c2','d2','f#2']);
//=> [ 65.40639132514966, 73.41619197935188, 92.4986056779086 ]
// alternative: TL.ntof()
// Alternative: TL.ntof()

@@ -485,7 +586,7 @@ // Convert relative semitone values to midi-numbers

//=> [ 36, 48, 55, 60 ]
// alternative: TL.rtom()
// Alternative: TL.rtom()
// Convert relative semitone values to frequency (A4 = 440 Hz)
// specify the octave as second argument (default = 'C3' = 4 => 48)
TL.rtof([-12, 0, 7, 12], 4);
TL.relativeToFrequency([-12, 0, 7, 12], 4);
//=> [ 65.40639132514966,

@@ -507,5 +608,6 @@ // 130.8127826502993,

//=> [ 500, 250, 375, 500, 333.33, 4000 ]
// Alternative: TL.dtoms()
// optional second argument sets bpm
TL.dtoms(['1/4', '1/8', '3/16', '1/4', '1/6', '2'], 100);
TL.divisionToMs(['1/4', '1/8', '3/16', '1/4', '1/6', '2'], 100);
//=> [ 600, 300, 450, 600, 400, 4800 ]

@@ -520,2 +622,3 @@

//=> [ 0.25, 0.125, 0.1875, 0.25, 0.1667, 2 ]
// Alternative: TL.dtor()
```

@@ -522,0 +625,0 @@

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

//==============================================================================
//==========================================================================
// gen-basic.js

@@ -12,3 +12,3 @@ // part of 'total-serialism' Package

// - spread-methods inspired by Max8's MC functions spread and spreadinclusive
//==============================================================================
//==========================================================================

@@ -37,2 +37,3 @@ const Util = require('./utility.js');

exports.spreadFloat = spreadFloat;
exports.spreadF = spreadFloat;

@@ -100,2 +101,3 @@ // Generate a list of n-length starting at one value

exports.spreadInclusiveFloat = spreadInclusiveFloat;
exports.spreadIncF = spreadInclusiveFloat;

@@ -131,2 +133,3 @@ // Generate a list of n-length starting at one value

exports.spreadInclusive = spreadInclusive;
exports.spreadInc = spreadInclusive;

@@ -193,2 +196,3 @@ // spreadinclusiveFloatExp function floored to integers

exports.sineFloat = sineFloat;
exports.sin = sineFloat;

@@ -217,2 +221,3 @@ // Generate an integer array with n-periods of a sine function

exports.cosineFloat = cosineFloat;
exports.cos = cosineFloat;

@@ -219,0 +224,0 @@ // Generate an integer array with n-periods of a cosine function

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

//==============================================================================
//=======================================================================
// gen-stochastic.js

@@ -7,3 +7,4 @@ // part of 'total-serialism' Package

//
// Stochastic algorithms to generate various forms of random
// Stochastic and Probablity Theory algorithms to generate
// various forms of random
// number sequences

@@ -13,3 +14,3 @@ //

// - Gratefully using the seedrandom package by David Bau
//==============================================================================
//=======================================================================

@@ -60,2 +61,3 @@ // require Generative methods

exports.randomFloat = randomFloat;
exports.randomF = randomFloat;

@@ -62,0 +64,0 @@ // generate a list of random integer values

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

//==============================================================================
//=======================================================================
// transform.js

@@ -16,7 +16,8 @@ // part of 'total-serialism' Package

// manipulations.", in Manipulation of Musical Patterns (1981)
//==============================================================================
//=======================================================================
// require the Utility methods
const Rand = require('./gen-stochastic.js');
const Util = require('./utility.js');
// const Rand = require('./gen-stochastic');
const Stat = require('./statistic');
const Util = require('./utility');

@@ -53,2 +54,3 @@ // duplicate an array, but add an offset to every value

exports.combine = combine;
exports.join = combine;

@@ -69,2 +71,3 @@ // duplicate an array a certain amount of times

exports.duplicate = duplicate;
exports.copy = duplicate;

@@ -91,2 +94,49 @@ // add zeroes to an array with a rhythmic sequence

// filter one or multiple values from an array
//
// @param {Array} -> array to filter
// @param {Number/String/Array} -> values to filter
// @return (Array} -> filtered array
//
function filter(a=[0], f){
let arr = (Array.isArray(a))? a.slice() : [a];
f = (Array.isArray(f))? f : [f];
for (let i in f){
let index = arr.indexOf(f[i]);
while (index >= 0){
arr.splice(index, 1);
index = arr.indexOf(f[i]);
}
}
return arr;
}
exports.filter = filter;
// filter one or multiple datatypes from an array
// In this case the input type is the type that is output
//
// @param {Array} -> array to filter
// @param {String/Array} -> types to filter
// @return (Array} -> filtered array
//
function filterType(a=[0], t){
a = (Array.isArray(a))? a.slice() : [a];
t = (Array.isArray(t))? t : [t];
let types = a.map(x => typeof x);
let arr = [];
for (let i in t){
let index = types.indexOf(t[i]);
while (index >= 0){
arr.push(a[index]);
a.splice(index, 1);
types.splice(index, 1);
index = types.indexOf(t[i]);
}
}
return arr;
}
exports.filterType = filterType;
// invert a list of values by mapping the lowest value

@@ -177,2 +227,3 @@ // to the highest value and vice versa, flipping everything

exports.palindrome = palindrome;
exports.mirror = palindrome;

@@ -206,2 +257,7 @@ // reverse the order of items in an Array

// placeholder for the sort() method found in
// statistic.js
//
exports.sort = Stat.sort;
// spray the values of one array on the

@@ -208,0 +264,0 @@ // places of values of another array if

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

//==============================================================================
//=======================================================================
// utility.js

@@ -8,3 +8,3 @@ // part of 'total-serialism' Package

// Utility functions
//==============================================================================
//=======================================================================

@@ -11,0 +11,0 @@ // Return the remainder after division

// const entryPoint = "../index";
// const entryPoint = "../build/ts.bundle.js";
// const entryPoint = "../build/ts.es5.js";
const entryPoint = "../build/ts.es5.min.js";
let entryPoint = "../index";
// entryPoint = "../build/ts.bundle.js";
// entryPoint = "../build/ts.es5.js";
// entryPoint = "../build/ts.es5.min.js";
const Srl = require(entryPoint);
const Gen = Srl.Generative;

@@ -12,5 +13,10 @@ const Algo = Srl.Algorithmic;

const Rand = Srl.Stochastic;
const Stat = Srl.Statistic;
const TL = Srl.Translate;
const Util = Srl.Utility;
console.time('requires load');
console.timeEnd('requires load');
console.log();
/*

@@ -25,10 +31,6 @@ Test criteria:

// console.log(TL.scaleName());
// TL.searchScales(['1P', '2M', '3m', '4P', '6m', '7M']);
// console.log(Algo.pisano(0));
fullTest();
function fullTest(){
console.time('Total Time');
testSerial();

@@ -39,5 +41,8 @@ testGen();

testMod();
testStat();
testTranslate();
testUtil();
pagebreak("Test Passed");
console.timeEnd('Total Time');
}

@@ -68,7 +73,15 @@

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

@@ -81,3 +94,5 @@

test("Gen.sineFloat(10, 1, -1, 1, 0.5)");
test("Gen.sin(8)");
test("Gen.cosineFloat(8)");
test("Gen.cos(8)");

@@ -152,3 +167,3 @@ test("Gen.sine(10)");

test("Rand.randomFloat(3, -1, 1)");
test("Rand.randomFloat(3, 0.2, 0.5)");
test("Rand.randomF(3, 0.2, 0.5)");

@@ -233,2 +248,8 @@ test("Rand.seed(4827)");

test("Mod.every([1,0,0,1,1], 1.5, 8, 0.5)");
test("Mod.filter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 8, 10])");
test("Mod.filter([0, 1.618, 2, 3.14, 4], 3.14)");
test("Mod.filter([0, 1, 'foo', 'bar', 2, 3], ['1', 'foo'])");
test("Mod.filterType([0, 1, [1, 2], 'foo', 2, null, true, {bar: 5}, 3.14, undefined], 'number')");

@@ -284,2 +305,6 @@ // var invArr = [0, 2, 5, 10, 13];

test("Mod.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11], -1)");
test("Mod.sort([10, 3.14, 'snare', 'kick', 5, -6, 'hat'])");
test("Mod.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11])");
// var sprArr1 = [12, 19, 24];

@@ -299,2 +324,30 @@ // var sprArr2 = [1, 0, 0, 1, 1, 0, 1, 0, 0.2];

function testStat(){
pagebreak("Statistic");
test("Stat.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11], -1)");
test("Stat.sort([10, 3.14, 'foo', 'bar', 5, -6, 'foobar'])");
test("Stat.sort([-10, 8, 6, -12, -6, -7, 2, 4, 3, 11])");
test("Stat.mean([2, -6, 2, 0, 10, 9, -2, 5, -8, -11, 1, -3])");
test("Stat.average([1, 2, 3, 4, 5, 6, 7, 8, 9])");
test("Stat.average([2, -6, 2, 0, 10, 9, -2, 5, -8, -11, 1, -3])");
test("Stat.median()");
test("Stat.median([1, 5, 6, 9, 13])");
test("Stat.median([1, 5, 6, 'foo', 'bar', 13,])");
test("Stat.center([1, 5, 11])");
test("Stat.center([1, 7, 4, 2, 9, 5])");
test("Stat.center([1, 7, 4, 2, 9, 5, 'foo', 'bar', true, true])");
test("Stat.common([8, 4, 3, 11, 9, 0, 11, 2, 10, 5, 11, 0])");
test("Stat.common([8, 4, 3, 9, 9, 0, 2, 10, 5, 11, 0, 11])");
test("Stat.common([8, 4, 3, 'foo', 'foo', 0, 2, 10, 5, 11, 0, 11])");
test("Stat.maximum([-38, -53, -6, 33, 88, 32, -8, 73])");
test("Stat.minimum([-38, -53, -6, 33, 88, 32, -8, 73])");
test("Stat.minimum([-38, -53, -6, 'foo', 33, 'bar'])");
}
function testTranslate(){

@@ -397,2 +450,12 @@ pagebreak("Translate");

function benchMark(f, iterations=10000){
console.time('benchmark time');
console.log(f+";");
for (var i in iterations){
eval(f);
}
console.timeEnd('benchmark time');
}
function pagebreak(n){

@@ -399,0 +462,0 @@ console.log("====================================");

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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