@khanacademy/perseus-score 1.0.0 → 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.
Files changed (40) hide show
  1. package/dist/error-codes.d.ts +4 -0
  2. package/dist/es/index.js +1332 -4
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.d.ts +29 -0
  5. package/dist/index.js +1348 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/util/tex-wrangler.d.ts +2 -0
  8. package/dist/validation.types.d.ts +279 -0
  9. package/dist/validation.typetest.d.ts +1 -0
  10. package/dist/widgets/categorizer/score-categorizer.d.ts +3 -0
  11. package/dist/widgets/categorizer/validate-categorizer.d.ts +11 -0
  12. package/dist/widgets/cs-program/score-cs-program.d.ts +3 -0
  13. package/dist/widgets/dropdown/score-dropdown.d.ts +3 -0
  14. package/dist/widgets/dropdown/validate-dropdown.d.ts +7 -0
  15. package/dist/widgets/expression/score-expression.d.ts +3 -0
  16. package/dist/widgets/expression/validate-expression.d.ts +11 -0
  17. package/dist/widgets/grapher/score-grapher.d.ts +3 -0
  18. package/dist/widgets/iframe/score-iframe.d.ts +3 -0
  19. package/dist/widgets/input-number/score-input-number.d.ts +37 -0
  20. package/dist/widgets/interactive-graph/score-interactive-graph.d.ts +3 -0
  21. package/dist/widgets/label-image/score-label-image.d.ts +8 -0
  22. package/dist/widgets/label-image/validate-label-image.d.ts +3 -0
  23. package/dist/widgets/matcher/score-matcher.d.ts +3 -0
  24. package/dist/widgets/matrix/score-matrix.d.ts +3 -0
  25. package/dist/widgets/matrix/validate-matrix.d.ts +11 -0
  26. package/dist/widgets/number-line/score-number-line.d.ts +3 -0
  27. package/dist/widgets/number-line/validate-number-line.d.ts +11 -0
  28. package/dist/widgets/numeric-input/score-numeric-input.d.ts +4 -0
  29. package/dist/widgets/orderer/score-orderer.d.ts +3 -0
  30. package/dist/widgets/orderer/validate-orderer.d.ts +9 -0
  31. package/dist/widgets/plotter/score-plotter.d.ts +3 -0
  32. package/dist/widgets/plotter/validate-plotter.d.ts +9 -0
  33. package/dist/widgets/radio/score-radio.d.ts +3 -0
  34. package/dist/widgets/radio/validate-radio.d.ts +11 -0
  35. package/dist/widgets/sorter/score-sorter.d.ts +3 -0
  36. package/dist/widgets/sorter/validate-sorter.d.ts +10 -0
  37. package/dist/widgets/table/score-table.d.ts +3 -0
  38. package/dist/widgets/table/utils.d.ts +7 -0
  39. package/dist/widgets/table/validate-table.d.ts +3 -0
  40. package/package.json +4 -4
@@ -0,0 +1,2 @@
1
+ export declare function modifyTex(tex: string): string;
2
+ export declare function parseTex(tex: string): string;
@@ -0,0 +1,279 @@
1
+ /**
2
+ * This file contains types used for validation and scoring. The types abide by
3
+ * a naming convention so that they're easy to follow and that we remain
4
+ * consistent across all of the widgets.
5
+ *
6
+ * These types are:
7
+ *
8
+ * * `Perseus<Widget>UserInput`: the data from the widget that represents the
9
+ * data the user entered. This is referred to as the 'guess' in some older
10
+ * parts of Perseus.
11
+ *
12
+ * * `Perseus<Widget>ValidationData`: the data needed to do validation of the
13
+ * user input. Validation refers to the different checks that we can do
14
+ * both on the client-side (before submitting user input for scoring) and
15
+ * on the server-side (when we score it). As such, it cannot contain any of
16
+ * the sensitive scoring data that would reveal the answer.
17
+ *
18
+ * * `Perseus<Widget>Rubric` (nee `Perseus<Widget>Rubric`): the data
19
+ * needed to score the user input. By convention, this type is defined as
20
+ * the set of sensitive answer data and then intersected with
21
+ * `Perseus<Widget>ValidationData`.
22
+ *
23
+ * For example:
24
+ * ```
25
+ * type Perseus<Widget>Rubric = {
26
+ * correct: string; // Used _only_ for scoring
27
+ * size: number; // Used _only_ for scoring
28
+ * } & Perseus<Widget>ValidationData;
29
+ * ```
30
+ */
31
+ import type { GrapherAnswerTypes, PerseusDropdownChoice, PerseusExpressionAnswerForm, PerseusGradedGroupSetWidgetOptions, PerseusGradedGroupWidgetOptions, PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatrixWidgetAnswers, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, PerseusRadioChoice, PerseusGraphCorrectType, MakeWidgetMap, Relationship } from "@khanacademy/perseus-core";
32
+ export type PerseusScore = {
33
+ type: "invalid";
34
+ message?: string | null | undefined;
35
+ suppressAlmostThere?: boolean | null | undefined;
36
+ } | {
37
+ type: "points";
38
+ earned: number;
39
+ total: number;
40
+ message?: string | null | undefined;
41
+ };
42
+ export type ValidationResult = Extract<PerseusScore, {
43
+ type: "invalid";
44
+ }> | null;
45
+ export type UserInputStatus = "correct" | "incorrect" | "incomplete";
46
+ export type PerseusCategorizerRubric = {
47
+ values: ReadonlyArray<number>;
48
+ } & PerseusCategorizerValidationData;
49
+ export type PerseusCategorizerUserInput = {
50
+ values: PerseusCategorizerRubric["values"];
51
+ };
52
+ export type PerseusCategorizerValidationData = {
53
+ items: ReadonlyArray<string>;
54
+ };
55
+ export type PerseusCSProgramUserInput = {
56
+ status: UserInputStatus;
57
+ message: string | null;
58
+ };
59
+ export type PerseusDropdownRubric = {
60
+ choices: ReadonlyArray<PerseusDropdownChoice>;
61
+ };
62
+ export type PerseusDropdownUserInput = {
63
+ value: number;
64
+ };
65
+ export type PerseusExpressionRubric = {
66
+ answerForms: ReadonlyArray<PerseusExpressionAnswerForm>;
67
+ functions: ReadonlyArray<string>;
68
+ };
69
+ export type PerseusExpressionUserInput = string;
70
+ export type PerseusGroupRubric = PerseusGroupWidgetOptions;
71
+ export type PerseusGroupValidationData = {
72
+ widgets: ValidationDataMap;
73
+ };
74
+ export type PerseusGroupUserInput = UserInputMap;
75
+ export type PerseusGradedGroupRubric = PerseusGradedGroupWidgetOptions;
76
+ export type PerseusGradedGroupSetRubric = PerseusGradedGroupSetWidgetOptions;
77
+ export type PerseusGrapherRubric = {
78
+ correct: GrapherAnswerTypes;
79
+ };
80
+ export type PerseusGrapherUserInput = PerseusGrapherRubric["correct"];
81
+ export type PerseusIFrameUserInput = {
82
+ status: UserInputStatus;
83
+ message: string | null;
84
+ };
85
+ export type PerseusInputNumberRubric = {
86
+ answerType?: "number" | "decimal" | "integer" | "rational" | "improper" | "mixed" | "percent" | "pi";
87
+ inexact?: boolean;
88
+ maxError?: number | string;
89
+ simplify: "required" | "optional" | "enforced";
90
+ value: string | number;
91
+ };
92
+ export type PerseusInputNumberUserInput = {
93
+ currentValue: string;
94
+ };
95
+ export type PerseusInteractiveGraphRubric = {
96
+ correct: PerseusGraphCorrectType;
97
+ graph: PerseusGraphType;
98
+ };
99
+ export type PerseusInteractiveGraphUserInput = PerseusGraphType;
100
+ export type PerseusLabelImageRubric = {
101
+ markers: ReadonlyArray<{
102
+ answers: ReadonlyArray<string>;
103
+ label: string;
104
+ }>;
105
+ };
106
+ export type PerseusLabelImageUserInput = {
107
+ markers: ReadonlyArray<{
108
+ selected?: ReadonlyArray<string>;
109
+ label: string;
110
+ }>;
111
+ };
112
+ export type PerseusMatcherRubric = {
113
+ left: ReadonlyArray<string>;
114
+ right: ReadonlyArray<string>;
115
+ };
116
+ export type PerseusMatcherUserInput = {
117
+ left: ReadonlyArray<string>;
118
+ right: ReadonlyArray<string>;
119
+ };
120
+ export type PerseusMatrixRubric = {
121
+ answers: PerseusMatrixWidgetAnswers;
122
+ } & PerseusMatrixValidationData;
123
+ export type PerseusMatrixValidationData = Empty;
124
+ export type PerseusMatrixUserInput = {
125
+ answers: PerseusMatrixRubric["answers"];
126
+ };
127
+ export type PerseusNumberLineRubric = {
128
+ correctRel: string | null | undefined;
129
+ correctX: number;
130
+ range: ReadonlyArray<number>;
131
+ initialX: number | null | undefined;
132
+ isInequality: boolean;
133
+ };
134
+ export type PerseusNumberLineUserInput = {
135
+ isTickCrtl?: boolean;
136
+ numLinePosition: number;
137
+ rel: Relationship | "eq";
138
+ numDivisions: number;
139
+ divisionRange: ReadonlyArray<number>;
140
+ };
141
+ export type PerseusNumericInputRubric = {
142
+ answers: ReadonlyArray<PerseusNumericInputAnswer>;
143
+ coefficient: boolean;
144
+ };
145
+ export type PerseusNumericInputUserInput = {
146
+ currentValue: string;
147
+ };
148
+ export type PerseusOrdererRubric = PerseusOrdererWidgetOptions;
149
+ export type PerseusOrdererUserInput = {
150
+ current: ReadonlyArray<string>;
151
+ };
152
+ export type PerseusPlotterRubric = {
153
+ correct: ReadonlyArray<number>;
154
+ } & PerseusPlotterValidationData;
155
+ export type PerseusPlotterValidationData = {
156
+ starting: ReadonlyArray<number>;
157
+ };
158
+ export type PerseusPlotterUserInput = ReadonlyArray<number>;
159
+ export type PerseusRadioRubric = {
160
+ choices: ReadonlyArray<PerseusRadioChoice>;
161
+ };
162
+ export type PerseusRadioUserInput = {
163
+ choicesSelected: ReadonlyArray<boolean>;
164
+ };
165
+ export type PerseusSorterRubric = {
166
+ correct: ReadonlyArray<string>;
167
+ };
168
+ export type PerseusSorterUserInput = {
169
+ options: ReadonlyArray<string>;
170
+ changed: boolean;
171
+ };
172
+ export type PerseusTableRubric = {
173
+ answers: ReadonlyArray<ReadonlyArray<string>>;
174
+ };
175
+ export type PerseusTableUserInput = ReadonlyArray<ReadonlyArray<string>>;
176
+ export interface RubricRegistry {
177
+ categorizer: PerseusCategorizerRubric;
178
+ dropdown: PerseusDropdownRubric;
179
+ expression: PerseusExpressionRubric;
180
+ "graded-group-set": PerseusGradedGroupSetRubric;
181
+ "graded-group": PerseusGradedGroupRubric;
182
+ grapher: PerseusGrapherRubric;
183
+ group: PerseusGroupRubric;
184
+ image: PerseusLabelImageRubric;
185
+ "input-number": PerseusInputNumberRubric;
186
+ "interactive-graph": PerseusInteractiveGraphRubric;
187
+ "label-image": PerseusLabelImageRubric;
188
+ matcher: PerseusMatcherRubric;
189
+ matrix: PerseusMatrixRubric;
190
+ "number-line": PerseusNumberLineRubric;
191
+ "numeric-input": PerseusNumericInputRubric;
192
+ orderer: PerseusOrdererRubric;
193
+ plotter: PerseusPlotterRubric;
194
+ radio: PerseusRadioRubric;
195
+ sorter: PerseusSorterRubric;
196
+ table: PerseusTableRubric;
197
+ }
198
+ /**
199
+ * A map of scoring data (previously referred to as "rubric"), keyed by
200
+ * `widgetId`. This data is used to score a learner's guess for a PerseusItem.
201
+ *
202
+ * NOTE: The value in this map is intentionally a subset of WidgetOptions<T>.
203
+ * By using the same shape (minus any unneeded render data), we are able to
204
+ * share functionality that understands how to traverse maps of `widget id` to
205
+ * `options`.
206
+ */
207
+ export type RubricMap = {
208
+ [Property in keyof RubricRegistry as `${Property} ${number}`]: {
209
+ type: Property;
210
+ static?: boolean;
211
+ options: RubricRegistry[Property];
212
+ };
213
+ };
214
+ export type Rubric = RubricRegistry[keyof RubricRegistry];
215
+ /**
216
+ * This is an interface so that it can be extended if a widget is created
217
+ * outside of this Perseus package. See `PerseusWidgetTypes` for a full
218
+ * explanation.
219
+ */
220
+ interface UserInputRegistry {
221
+ categorizer: PerseusCategorizerUserInput;
222
+ "cs-program": PerseusCSProgramUserInput;
223
+ dropdown: PerseusDropdownUserInput;
224
+ expression: PerseusExpressionUserInput;
225
+ grapher: PerseusGrapherUserInput;
226
+ group: PerseusGroupUserInput;
227
+ iframe: PerseusIFrameUserInput;
228
+ "input-number": PerseusInputNumberUserInput;
229
+ "interactive-graph": PerseusInteractiveGraphUserInput;
230
+ "label-image": PerseusLabelImageUserInput;
231
+ matcher: PerseusMatcherUserInput;
232
+ matrix: PerseusMatrixUserInput;
233
+ "number-line": PerseusNumberLineUserInput;
234
+ "numeric-input": PerseusNumericInputUserInput;
235
+ orderer: PerseusOrdererUserInput;
236
+ plotter: PerseusPlotterUserInput;
237
+ radio: PerseusRadioUserInput;
238
+ sorter: PerseusSorterUserInput;
239
+ table: PerseusTableUserInput;
240
+ }
241
+ /** A union type of all the widget user input types */
242
+ export type UserInput = UserInputRegistry[keyof UserInputRegistry];
243
+ /**
244
+ * A map of widget IDs to user input types (strongly typed based on the format
245
+ * of the widget ID).
246
+ */
247
+ export type UserInputMap = MakeWidgetMap<UserInputRegistry>;
248
+ /**
249
+ * deprecated prefer using UserInputMap
250
+ */
251
+ export type UserInputArray = ReadonlyArray<UserInputArray | UserInput | null | undefined>;
252
+ export interface ValidationDataTypes {
253
+ categorizer: PerseusCategorizerValidationData;
254
+ group: PerseusGroupValidationData;
255
+ plotter: PerseusPlotterValidationData;
256
+ }
257
+ /**
258
+ * A map of validation data, keyed by `widgetId`. This data is used to check if
259
+ * a question is answerable. This data represents the minimal intersection of
260
+ * data that's available in the client (widget options) and server (scoring
261
+ * data) and is represented by a group of types known as "validation data".
262
+ *
263
+ * NOTE: The value in this map is intentionally a subset of WidgetOptions<T>.
264
+ * By using the same shape (minus any unneeded data), we are able to pass a
265
+ * `PerseusWidgetsMap` or ` into any function that accepts a
266
+ * `ValidationDataMap` without any mutation of data.
267
+ */
268
+ export type ValidationDataMap = {
269
+ [Property in keyof ValidationDataTypes as `${Property} ${number}`]: {
270
+ type: Property;
271
+ static?: boolean;
272
+ options: ValidationDataTypes[Property];
273
+ };
274
+ };
275
+ /**
276
+ * A union type of all the different widget validation data types that exist.
277
+ */
278
+ export type ValidationData = ValidationDataTypes[keyof ValidationDataTypes];
279
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { PerseusCategorizerRubric, PerseusCategorizerUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreCategorizer(userInput: PerseusCategorizerUserInput, rubric: PerseusCategorizerRubric): PerseusScore;
3
+ export default scoreCategorizer;
@@ -0,0 +1,11 @@
1
+ import type { ValidationResult, PerseusCategorizerUserInput, PerseusCategorizerValidationData } from "@khanacademy/perseus-score";
2
+ /**
3
+ * Checks userInput from the categorizer widget to see if the user has selected
4
+ * a category for each item.
5
+ * @param userInput - The user's input corresponding to an array of indices that
6
+ * represent the selected category for each row/item.
7
+ * @param validationData - An array of strings corresponding to each row/item
8
+ * @param strings - Used to provide a validation message
9
+ */
10
+ declare function validateCategorizer(userInput: PerseusCategorizerUserInput, validationData: PerseusCategorizerValidationData): ValidationResult;
11
+ export default validateCategorizer;
@@ -0,0 +1,3 @@
1
+ import type { PerseusCSProgramUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreCSProgram(userInput: PerseusCSProgramUserInput): PerseusScore;
3
+ export default scoreCSProgram;
@@ -0,0 +1,3 @@
1
+ import type { PerseusDropdownRubric, PerseusDropdownUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreDropdown(userInput: PerseusDropdownUserInput, rubric: PerseusDropdownRubric): PerseusScore;
3
+ export default scoreDropdown;
@@ -0,0 +1,7 @@
1
+ import type { PerseusDropdownUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks if the user has selected an item from the dropdown before scoring.
4
+ * This is shown with a userInput value / index other than 0.
5
+ */
6
+ declare function validateDropdown(userInput: PerseusDropdownUserInput): ValidationResult;
7
+ export default validateDropdown;
@@ -0,0 +1,3 @@
1
+ import type { PerseusExpressionRubric, PerseusExpressionUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreExpression(userInput: PerseusExpressionUserInput, rubric: PerseusExpressionRubric, locale: string): PerseusScore;
3
+ export default scoreExpression;
@@ -0,0 +1,11 @@
1
+ import type { PerseusExpressionUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks user input from the expression widget to see if it is scorable.
4
+ *
5
+ * Note: Most of the expression widget's validation requires the Rubric because
6
+ * of its use of KhanAnswerTypes as a core part of scoring.
7
+ *
8
+ * @see `scoreExpression()` for more details.
9
+ */
10
+ declare function validateExpression(userInput: PerseusExpressionUserInput): ValidationResult;
11
+ export default validateExpression;
@@ -0,0 +1,3 @@
1
+ import type { PerseusGrapherRubric, PerseusGrapherUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreGrapher(userInput: PerseusGrapherUserInput, rubric: PerseusGrapherRubric): PerseusScore;
3
+ export default scoreGrapher;
@@ -0,0 +1,3 @@
1
+ import type { PerseusIFrameUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreIframe(userInput: PerseusIFrameUserInput): PerseusScore;
3
+ export default scoreIframe;
@@ -0,0 +1,37 @@
1
+ import type { PerseusInputNumberRubric, PerseusInputNumberUserInput, PerseusScore } from "../../validation.types";
2
+ export declare const inputNumberAnswerTypes: {
3
+ readonly number: {
4
+ readonly name: "Numbers";
5
+ readonly forms: "integer, decimal, proper, improper, mixed";
6
+ };
7
+ readonly decimal: {
8
+ readonly name: "Decimals";
9
+ readonly forms: "decimal";
10
+ };
11
+ readonly integer: {
12
+ readonly name: "Integers";
13
+ readonly forms: "integer";
14
+ };
15
+ readonly rational: {
16
+ readonly name: "Fractions and mixed numbers";
17
+ readonly forms: "integer, proper, improper, mixed";
18
+ };
19
+ readonly improper: {
20
+ readonly name: "Improper numbers (no mixed)";
21
+ readonly forms: "integer, proper, improper";
22
+ };
23
+ readonly mixed: {
24
+ readonly name: "Mixed numbers (no improper)";
25
+ readonly forms: "integer, proper, mixed";
26
+ };
27
+ readonly percent: {
28
+ readonly name: "Numbers or percents";
29
+ readonly forms: "integer, decimal, proper, improper, mixed, percent";
30
+ };
31
+ readonly pi: {
32
+ readonly name: "Numbers with pi";
33
+ readonly forms: "pi";
34
+ };
35
+ };
36
+ declare function scoreInputNumber(userInput: PerseusInputNumberUserInput, rubric: PerseusInputNumberRubric): PerseusScore;
37
+ export default scoreInputNumber;
@@ -0,0 +1,3 @@
1
+ import type { PerseusInteractiveGraphRubric, PerseusScore, PerseusInteractiveGraphUserInput } from "@khanacademy/perseus-score";
2
+ declare function scoreInteractiveGraph(userInput: PerseusInteractiveGraphUserInput, rubric: PerseusInteractiveGraphRubric): PerseusScore;
3
+ export default scoreInteractiveGraph;
@@ -0,0 +1,8 @@
1
+ import type { PerseusLabelImageUserInput, PerseusLabelImageRubric, PerseusScore } from "../../validation.types";
2
+ type InteractiveMarkerScore = {
3
+ hasAnswers: boolean;
4
+ isCorrect: boolean;
5
+ };
6
+ export declare function scoreLabelImageMarker(userInput: PerseusLabelImageUserInput["markers"][number]["selected"], rubric: PerseusLabelImageRubric["markers"][number]["answers"]): InteractiveMarkerScore;
7
+ declare function scoreLabelImage(userInput: PerseusLabelImageUserInput, rubric: PerseusLabelImageRubric): PerseusScore;
8
+ export default scoreLabelImage;
@@ -0,0 +1,3 @@
1
+ import type { PerseusLabelImageUserInput, ValidationResult } from "../../validation.types";
2
+ declare function validateLabelImage(userInput: PerseusLabelImageUserInput): ValidationResult;
3
+ export default validateLabelImage;
@@ -0,0 +1,3 @@
1
+ import type { PerseusMatcherRubric, PerseusMatcherUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreMatcher(userInput: PerseusMatcherUserInput, rubric: PerseusMatcherRubric): PerseusScore;
3
+ export default scoreMatcher;
@@ -0,0 +1,3 @@
1
+ import type { PerseusMatrixRubric, PerseusMatrixUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreMatrix(userInput: PerseusMatrixUserInput, rubric: PerseusMatrixRubric): PerseusScore;
3
+ export default scoreMatrix;
@@ -0,0 +1,11 @@
1
+ import type { PerseusMatrixUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks user input from the matrix widget to see if it is scorable.
4
+ *
5
+ * Note: The matrix widget cannot do much validation without the Scoring
6
+ * Data because of its use of KhanAnswerTypes as a core part of scoring.
7
+ *
8
+ * @see `scoreMatrix()` for more details.
9
+ */
10
+ declare function validateMatrix(userInput: PerseusMatrixUserInput): ValidationResult;
11
+ export default validateMatrix;
@@ -0,0 +1,3 @@
1
+ import type { PerseusNumberLineRubric, PerseusNumberLineUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreNumberLine(userInput: PerseusNumberLineUserInput, rubric: PerseusNumberLineRubric): PerseusScore;
3
+ export default scoreNumberLine;
@@ -0,0 +1,11 @@
1
+ import type { PerseusNumberLineUserInput, PerseusScore } from "../../validation.types";
2
+ /**
3
+ * Checks user input is within the allowed range and not the same as the initial
4
+ * state.
5
+ * @param userInput
6
+ * @see 'scoreNumberLine' for the scoring logic.
7
+ */
8
+ declare function validateNumberLine(userInput: PerseusNumberLineUserInput): Extract<PerseusScore, {
9
+ type: "invalid";
10
+ }> | null;
11
+ export default validateNumberLine;
@@ -0,0 +1,4 @@
1
+ import type { PerseusNumericInputRubric, PerseusNumericInputUserInput, PerseusScore } from "../../validation.types";
2
+ export declare function maybeParsePercentInput(inputValue: string | number, normalizedAnswerExpected: boolean): string | number;
3
+ declare function scoreNumericInput(userInput: PerseusNumericInputUserInput, rubric: PerseusNumericInputRubric): PerseusScore;
4
+ export default scoreNumericInput;
@@ -0,0 +1,3 @@
1
+ import type { PerseusOrdererRubric, PerseusOrdererUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreOrderer(userInput: PerseusOrdererUserInput, rubric: PerseusOrdererRubric): PerseusScore;
3
+ export default scoreOrderer;
@@ -0,0 +1,9 @@
1
+ import type { PerseusOrdererUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks user input from the orderer widget to see if the user has started
4
+ * ordering the options, making the widget scorable.
5
+ * @param userInput
6
+ * @see `scoreOrderer` for more details.
7
+ */
8
+ declare function validateOrderer(userInput: PerseusOrdererUserInput): ValidationResult;
9
+ export default validateOrderer;
@@ -0,0 +1,3 @@
1
+ import type { PerseusPlotterUserInput, PerseusPlotterRubric, PerseusScore } from "../../validation.types";
2
+ declare function scorePlotter(userInput: PerseusPlotterUserInput, rubric: PerseusPlotterRubric): PerseusScore;
3
+ export default scorePlotter;
@@ -0,0 +1,9 @@
1
+ import type { PerseusPlotterUserInput, PerseusPlotterValidationData, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks user input to confirm it is not the same as the starting values for the graph.
4
+ * This means the user has modified the graph, and the question can be scored.
5
+ *
6
+ * @see 'scorePlotter' for more details on scoring.
7
+ */
8
+ declare function validatePlotter(userInput: PerseusPlotterUserInput, validationData: PerseusPlotterValidationData): ValidationResult;
9
+ export default validatePlotter;
@@ -0,0 +1,3 @@
1
+ import type { PerseusRadioRubric, PerseusRadioUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreRadio(userInput: PerseusRadioUserInput, rubric: PerseusRadioRubric): PerseusScore;
3
+ export default scoreRadio;
@@ -0,0 +1,11 @@
1
+ import type { PerseusRadioUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks if the user has selected at least one option. Additional validation
4
+ * is done in scoreRadio to check if the number of selected options is correct
5
+ * and if the user has selected both a correct option and the "none of the above"
6
+ * option.
7
+ * @param userInput
8
+ * @see `scoreRadio` for the additional validation logic and the scoring logic.
9
+ */
10
+ declare function validateRadio(userInput: PerseusRadioUserInput): ValidationResult;
11
+ export default validateRadio;
@@ -0,0 +1,3 @@
1
+ import type { PerseusSorterRubric, PerseusSorterUserInput, PerseusScore } from "../../validation.types";
2
+ declare function scoreSorter(userInput: PerseusSorterUserInput, rubric: PerseusSorterRubric): PerseusScore;
3
+ export default scoreSorter;
@@ -0,0 +1,10 @@
1
+ import type { PerseusSorterUserInput, ValidationResult } from "../../validation.types";
2
+ /**
3
+ * Checks user input for the sorter widget to ensure that the user has made
4
+ * changes before attempting to score the widget.
5
+ * @param userInput
6
+ * @see 'scoreSorter' in 'packages/perseus/src/widgets/sorter/score-sorter.ts'
7
+ * for more details on how the sorter widget is scored.
8
+ */
9
+ declare function validateSorter(userInput: PerseusSorterUserInput): ValidationResult;
10
+ export default validateSorter;
@@ -0,0 +1,3 @@
1
+ import type { PerseusTableRubric, PerseusScore, PerseusTableUserInput } from "../../validation.types";
2
+ declare function scoreTable(userInput: PerseusTableUserInput, rubric: PerseusTableRubric): PerseusScore;
3
+ export default scoreTable;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Filters the given table (modelled as a 2D array) to remove any rows that are
3
+ * completely empty.
4
+ *
5
+ * @returns A new table with only non-empty rows.
6
+ */
7
+ export declare const filterNonEmpty: (table: ReadonlyArray<ReadonlyArray<string>>) => (readonly string[])[];
@@ -0,0 +1,3 @@
1
+ import type { PerseusTableUserInput, ValidationResult } from "../../validation.types";
2
+ declare function validateTable(userInput: PerseusTableUserInput): ValidationResult;
3
+ export default validateTable;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus score",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "1.0.0",
6
+ "version": "2.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -26,9 +26,9 @@
26
26
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
27
27
  },
28
28
  "dependencies": {
29
- "@khanacademy/kas": "^0.4.10",
30
- "@khanacademy/kmath": "^0.2.0",
31
- "@khanacademy/perseus-core": "3.1.0"
29
+ "@khanacademy/kas": "^0.4.12",
30
+ "@khanacademy/kmath": "^0.3.1",
31
+ "@khanacademy/perseus-core": "3.3.0"
32
32
  },
33
33
  "devDependencies": {},
34
34
  "peerDependencies": {},