jspsych 7.1.2 → 7.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! *****************************************************************************
1
+ /******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -23,6 +23,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
23
23
  });
24
24
  }
25
25
 
26
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
27
+
26
28
  // Gets all non-builtin properties up the prototype chain
27
29
  const getAllProperties = object => {
28
30
  const properties = new Set();
@@ -65,7 +67,7 @@ var autoBind = (self, {include, exclude} = {}) => {
65
67
  return self;
66
68
  };
67
69
 
68
- var version = "7.1.2";
70
+ var version = "7.2.2";
69
71
 
70
72
  class MigrationError extends Error {
71
73
  constructor(message = "The global `jsPsych` variable is no longer available in jsPsych v7.") {
@@ -405,6 +407,9 @@ class DataCollection {
405
407
  filterCustom(fn) {
406
408
  return new DataCollection(this.trials.filter(fn));
407
409
  }
410
+ filterColumns(columns) {
411
+ return new DataCollection(this.trials.map((trial) => Object.fromEntries(columns.filter((key) => key in trial).map((key) => [key, trial[key]]))));
412
+ }
408
413
  select(column) {
409
414
  const values = [];
410
415
  for (const trial of this.trials) {
@@ -1619,6 +1624,135 @@ var randomWords$1 = words;
1619
1624
  // Export the word list as it is often useful
1620
1625
  words.wordList = wordList;
1621
1626
 
1627
+ var alea = {exports: {}};
1628
+
1629
+ (function (module) {
1630
+ // A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010
1631
+ // http://baagoe.com/en/RandomMusings/javascript/
1632
+ // https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
1633
+ // Original work is under MIT license -
1634
+
1635
+ // Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>
1636
+ //
1637
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
1638
+ // of this software and associated documentation files (the "Software"), to deal
1639
+ // in the Software without restriction, including without limitation the rights
1640
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1641
+ // copies of the Software, and to permit persons to whom the Software is
1642
+ // furnished to do so, subject to the following conditions:
1643
+ //
1644
+ // The above copyright notice and this permission notice shall be included in
1645
+ // all copies or substantial portions of the Software.
1646
+ //
1647
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1648
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1649
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1650
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1651
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1652
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1653
+ // THE SOFTWARE.
1654
+
1655
+
1656
+
1657
+ (function(global, module, define) {
1658
+
1659
+ function Alea(seed) {
1660
+ var me = this, mash = Mash();
1661
+
1662
+ me.next = function() {
1663
+ var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32
1664
+ me.s0 = me.s1;
1665
+ me.s1 = me.s2;
1666
+ return me.s2 = t - (me.c = t | 0);
1667
+ };
1668
+
1669
+ // Apply the seeding algorithm from Baagoe.
1670
+ me.c = 1;
1671
+ me.s0 = mash(' ');
1672
+ me.s1 = mash(' ');
1673
+ me.s2 = mash(' ');
1674
+ me.s0 -= mash(seed);
1675
+ if (me.s0 < 0) { me.s0 += 1; }
1676
+ me.s1 -= mash(seed);
1677
+ if (me.s1 < 0) { me.s1 += 1; }
1678
+ me.s2 -= mash(seed);
1679
+ if (me.s2 < 0) { me.s2 += 1; }
1680
+ mash = null;
1681
+ }
1682
+
1683
+ function copy(f, t) {
1684
+ t.c = f.c;
1685
+ t.s0 = f.s0;
1686
+ t.s1 = f.s1;
1687
+ t.s2 = f.s2;
1688
+ return t;
1689
+ }
1690
+
1691
+ function impl(seed, opts) {
1692
+ var xg = new Alea(seed),
1693
+ state = opts && opts.state,
1694
+ prng = xg.next;
1695
+ prng.int32 = function() { return (xg.next() * 0x100000000) | 0; };
1696
+ prng.double = function() {
1697
+ return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
1698
+ };
1699
+ prng.quick = prng;
1700
+ if (state) {
1701
+ if (typeof(state) == 'object') copy(state, xg);
1702
+ prng.state = function() { return copy(xg, {}); };
1703
+ }
1704
+ return prng;
1705
+ }
1706
+
1707
+ function Mash() {
1708
+ var n = 0xefc8249d;
1709
+
1710
+ var mash = function(data) {
1711
+ data = String(data);
1712
+ for (var i = 0; i < data.length; i++) {
1713
+ n += data.charCodeAt(i);
1714
+ var h = 0.02519603282416938 * n;
1715
+ n = h >>> 0;
1716
+ h -= n;
1717
+ h *= n;
1718
+ n = h >>> 0;
1719
+ h -= n;
1720
+ n += h * 0x100000000; // 2^32
1721
+ }
1722
+ return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
1723
+ };
1724
+
1725
+ return mash;
1726
+ }
1727
+
1728
+
1729
+ if (module && module.exports) {
1730
+ module.exports = impl;
1731
+ } else if (define && define.amd) {
1732
+ define(function() { return impl; });
1733
+ } else {
1734
+ this.alea = impl;
1735
+ }
1736
+
1737
+ })(
1738
+ commonjsGlobal,
1739
+ module, // present in node.js
1740
+ (typeof undefined) == 'function' // present with an AMD loader
1741
+ );
1742
+ } (alea));
1743
+
1744
+ var seedrandom = alea.exports;
1745
+
1746
+ /**
1747
+ * Uses the `seedrandom` package to replace Math.random() with a seedable PRNG.
1748
+ *
1749
+ * @param seed An optional seed. If none is given, a random seed will be generated.
1750
+ * @returns The seed value.
1751
+ */
1752
+ function setSeed(seed = Math.random().toString()) {
1753
+ Math.random = seedrandom(seed);
1754
+ return seed;
1755
+ }
1622
1756
  function repeat(array, repetitions, unpack = false) {
1623
1757
  const arr_isArray = Array.isArray(array);
1624
1758
  const rep_isArray = Array.isArray(repetitions);
@@ -1901,6 +2035,7 @@ function unpackArray(array) {
1901
2035
 
1902
2036
  var randomization = /*#__PURE__*/Object.freeze({
1903
2037
  __proto__: null,
2038
+ setSeed: setSeed,
1904
2039
  repeat: repeat,
1905
2040
  shuffle: shuffle,
1906
2041
  shuffleNoRepeats: shuffleNoRepeats,
@@ -2576,7 +2711,7 @@ class JsPsych {
2576
2711
  // write the data from the trial
2577
2712
  this.data.write(data);
2578
2713
  // get back the data with all of the defaults in
2579
- const trial_data = this.data.get().filter({ trial_index: this.global_trial_index });
2714
+ const trial_data = this.data.getLastTrialData();
2580
2715
  // for trial-level callbacks, we just want to pass in a reference to the values
2581
2716
  // of the DataCollection, for easy access and editing.
2582
2717
  const trial_data_values = trial_data.values()[0];
@@ -2625,7 +2760,10 @@ class JsPsych {
2625
2760
  // done with callbacks
2626
2761
  this.internal.call_immediate = false;
2627
2762
  // wait for iti
2628
- if (typeof current_trial.post_trial_gap === null ||
2763
+ if (this.simulation_mode === "data-only") {
2764
+ this.nextTrial();
2765
+ }
2766
+ else if (typeof current_trial.post_trial_gap === null ||
2629
2767
  typeof current_trial.post_trial_gap === "undefined") {
2630
2768
  if (this.opts.default_iti > 0) {
2631
2769
  setTimeout(this.nextTrial, this.opts.default_iti);