@jspsych/plugin-survey-likert 1.1.2 → 2.0.0

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/src/index.spec.ts CHANGED
@@ -30,7 +30,7 @@ describe("survey-likert plugin", () => {
30
30
  selectInput("Q3", "3").checked = true;
31
31
  selectInput("Q4", "4").checked = true;
32
32
 
33
- clickTarget(document.querySelector("#jspsych-survey-likert-next"));
33
+ await clickTarget(document.querySelector("#jspsych-survey-likert-next"));
34
34
 
35
35
  await expectFinished();
36
36
 
@@ -62,7 +62,7 @@ describe("survey-likert plugin simulation", () => {
62
62
 
63
63
  await expectFinished();
64
64
 
65
- const surveyData = getData().values()[0].response;
65
+ const surveyData = getData().values()[0].response as Record<string, number>;
66
66
  const all_valid = Object.entries(surveyData).every((x) => {
67
67
  return x[1] <= 4 && x[1] >= 0;
68
68
  });
@@ -94,7 +94,7 @@ describe("survey-likert plugin simulation", () => {
94
94
 
95
95
  await expectFinished();
96
96
 
97
- const surveyData = getData().values()[0].response;
97
+ const surveyData = getData().values()[0].response as Record<string, number>;
98
98
  const all_valid = Object.entries(surveyData).every((x) => {
99
99
  return x[1] <= 4 && x[1] >= 0;
100
100
  });
package/src/index.ts CHANGED
@@ -1,37 +1,35 @@
1
1
  import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
2
 
3
+ import { version } from "../package.json";
4
+
3
5
  const info = <const>{
4
6
  name: "survey-likert",
7
+ version: version,
5
8
  parameters: {
6
9
  /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
7
10
  questions: {
8
11
  type: ParameterType.COMPLEX,
9
12
  array: true,
10
- pretty_name: "Questions",
11
13
  nested: {
12
14
  /** Question prompt. */
13
15
  prompt: {
14
16
  type: ParameterType.HTML_STRING,
15
- pretty_name: "Prompt",
16
17
  default: undefined,
17
18
  },
18
19
  /** Array of likert labels to display for this question. */
19
20
  labels: {
20
21
  type: ParameterType.STRING,
21
22
  array: true,
22
- pretty_name: "Labels",
23
23
  default: undefined,
24
24
  },
25
25
  /** Whether or not a response to this question must be given in order to continue. */
26
26
  required: {
27
27
  type: ParameterType.BOOL,
28
- pretty_name: "Required",
29
28
  default: false,
30
29
  },
31
30
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
32
31
  name: {
33
32
  type: ParameterType.STRING,
34
- pretty_name: "Question Name",
35
33
  default: "",
36
34
  },
37
35
  },
@@ -39,45 +37,67 @@ const info = <const>{
39
37
  /** If true, the order of the questions in the 'questions' array will be randomized. */
40
38
  randomize_question_order: {
41
39
  type: ParameterType.BOOL,
42
- pretty_name: "Randomize Question Order",
43
40
  default: false,
44
41
  },
45
42
  /** HTML-formatted string to display at top of the page above all of the questions. */
46
43
  preamble: {
47
44
  type: ParameterType.HTML_STRING,
48
- pretty_name: "Preamble",
49
45
  default: null,
50
46
  },
51
47
  /** Width of the likert scales in pixels. */
52
48
  scale_width: {
53
49
  type: ParameterType.INT,
54
- pretty_name: "Scale width",
55
50
  default: null,
56
51
  },
57
52
  /** Label of the button to submit responses. */
58
53
  button_label: {
59
54
  type: ParameterType.STRING,
60
- pretty_name: "Button label",
61
55
  default: "Continue",
62
56
  },
63
57
  /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
64
58
  autocomplete: {
65
59
  type: ParameterType.BOOL,
66
- pretty_name: "Allow autocomplete",
67
60
  default: false,
68
61
  },
69
62
  },
63
+ data: {
64
+ /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
65
+ response: {
66
+ type: ParameterType.COMPLEX,
67
+ nested: {
68
+ identifier: {
69
+ type: ParameterType.STRING,
70
+ },
71
+ response: {
72
+ type:
73
+ ParameterType.STRING |
74
+ ParameterType.INT |
75
+ ParameterType.FLOAT |
76
+ ParameterType.BOOL |
77
+ ParameterType.OBJECT,
78
+ },
79
+ },
80
+ },
81
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
82
+ rt: {
83
+ type: ParameterType.INT,
84
+ },
85
+ /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
86
+ question_order: {
87
+ type: ParameterType.INT,
88
+ array: true,
89
+ },
90
+ },
70
91
  };
71
92
 
72
93
  type Info = typeof info;
73
94
 
74
95
  /**
75
- * **survey-likert**
76
- *
77
- * jsPsych plugin for gathering responses to questions on a likert scale
96
+ * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds
97
+ * by selecting a radio button.
78
98
  *
79
99
  * @author Josh de Leeuw
80
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}
100
+ * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}
81
101
  */
82
102
  class SurveyLikertPlugin implements JsPsychPlugin<Info> {
83
103
  static info = info;
@@ -209,8 +229,6 @@ class SurveyLikertPlugin implements JsPsychPlugin<Info> {
209
229
  question_order: question_order,
210
230
  };
211
231
 
212
- display_element.innerHTML = "";
213
-
214
232
  // next trial
215
233
  this.jsPsych.finishTrial(trial_data);
216
234
  });