@pie-lib/feedback 0.20.1-next.0 → 0.21.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/esm/index.js +123 -0
- package/esm/index.js.map +1 -0
- package/package.json +9 -2
- package/LICENSE.md +0 -5
package/esm/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function (target) {
|
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var key in source) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
|
+
target[key] = source[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const defaults = {
|
|
20
|
+
correct: {
|
|
21
|
+
type: 'default',
|
|
22
|
+
default: 'Correct',
|
|
23
|
+
custom: 'Correct'
|
|
24
|
+
},
|
|
25
|
+
incorrect: {
|
|
26
|
+
type: 'default',
|
|
27
|
+
default: 'Incorrect',
|
|
28
|
+
custom: 'Incorrect'
|
|
29
|
+
},
|
|
30
|
+
partial: {
|
|
31
|
+
type: 'default',
|
|
32
|
+
default: 'Nearly',
|
|
33
|
+
custom: 'Nearly'
|
|
34
|
+
},
|
|
35
|
+
unanswered: {
|
|
36
|
+
type: 'default',
|
|
37
|
+
default: 'You have not entered a response',
|
|
38
|
+
custom: 'You have not entered a response'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {Object} FeedbackConfig
|
|
43
|
+
* @property {'default'|'none'|'custom'} type
|
|
44
|
+
* @property {string} default
|
|
45
|
+
* @property {string} custom
|
|
46
|
+
*
|
|
47
|
+
* @typedef {Object} Feedback
|
|
48
|
+
* @property {FeedbackConfig} correct
|
|
49
|
+
* @property {FeedbackConfig} incorrect
|
|
50
|
+
* @property {FeedbackConfig} partial
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const normalizeCorrectness = c => {
|
|
54
|
+
if (c === 'partially-correct') {
|
|
55
|
+
return 'partial';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return c;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Get the feedback for the correctness
|
|
62
|
+
*
|
|
63
|
+
* @param {'correct'|'incorrect'|'partial'} correctness
|
|
64
|
+
* @param {Feedback} feedback
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const getFeedbackForCorrectness = (correctness, feedback) => new Promise(resolve => {
|
|
69
|
+
feedback = _extends({}, defaults, feedback);
|
|
70
|
+
correctness = normalizeCorrectness(correctness);
|
|
71
|
+
const fb = feedback[correctness] || defaults[correctness] || {};
|
|
72
|
+
const d = defaults[correctness] || {};
|
|
73
|
+
getFeedback(fb, d[fb.type || 'default']).then(result => resolve(result));
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Get the feedback from a {FeedbackConfig}
|
|
77
|
+
*
|
|
78
|
+
* @param {FeedbackConfig} feedback
|
|
79
|
+
* @param {string} fallback
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
const getFeedback = (feedback, fallback) => new Promise(resolve => {
|
|
83
|
+
if (!feedback || feedback.type === 'none') {
|
|
84
|
+
resolve(undefined);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
feedback = feedback || {};
|
|
89
|
+
const out = feedback[feedback.type] || fallback;
|
|
90
|
+
resolve(out);
|
|
91
|
+
}); // TODO: should replace getFeedbackForCorrectness
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get feedback for correctness
|
|
95
|
+
* @param {'correct'|'incorrect'|'partial'} correctness
|
|
96
|
+
* @param {Feedback} feedback
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
const getActualFeedbackForCorrectness = (correctness, feedback) => {
|
|
100
|
+
feedback = _extends({}, defaults, feedback); // normalize correctness
|
|
101
|
+
|
|
102
|
+
correctness = correctness === 'partially-correct' ? 'partial' : correctness;
|
|
103
|
+
const defaultFeedback = defaults[correctness] || {};
|
|
104
|
+
const fb = feedback[correctness] || defaultFeedback;
|
|
105
|
+
return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);
|
|
106
|
+
}; // TODO: should replace getFeedback
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the feedback from a {FeedbackConfig}
|
|
110
|
+
* @param {FeedbackConfig} feedback
|
|
111
|
+
* @param {string} fallback
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
const getActualFeedback = (feedback, fallback) => {
|
|
115
|
+
if (!feedback || feedback.type === 'none') {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return feedback[feedback.type] || fallback;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export { defaults, getActualFeedback, getActualFeedbackForCorrectness, getFeedback, getFeedbackForCorrectness };
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["export const defaults = {\n correct: { type: 'default', default: 'Correct', custom: 'Correct' },\n incorrect: { type: 'default', default: 'Incorrect', custom: 'Incorrect' },\n partial: { type: 'default', default: 'Nearly', custom: 'Nearly' },\n unanswered: {\n type: 'default',\n default: 'You have not entered a response',\n custom: 'You have not entered a response',\n },\n};\n\n/**\n * @typedef {Object} FeedbackConfig\n * @property {'default'|'none'|'custom'} type\n * @property {string} default\n * @property {string} custom\n *\n * @typedef {Object} Feedback\n * @property {FeedbackConfig} correct\n * @property {FeedbackConfig} incorrect\n * @property {FeedbackConfig} partial\n */\n\nconst normalizeCorrectness = (c) => {\n if (c === 'partially-correct') {\n return 'partial';\n }\n return c;\n};\n\n/**\n * Get the feedback for the correctness\n *\n * @param {'correct'|'incorrect'|'partial'} correctness\n * @param {Feedback} feedback\n */\nexport const getFeedbackForCorrectness = (correctness, feedback) =>\n new Promise((resolve) => {\n feedback = { ...defaults, ...feedback };\n correctness = normalizeCorrectness(correctness);\n const fb = feedback[correctness] || defaults[correctness] || {};\n const d = defaults[correctness] || {};\n getFeedback(fb, d[fb.type || 'default']).then((result) => resolve(result));\n });\n\n/**\n * Get the feedback from a {FeedbackConfig}\n *\n * @param {FeedbackConfig} feedback\n * @param {string} fallback\n */\nexport const getFeedback = (feedback, fallback) =>\n new Promise((resolve) => {\n if (!feedback || feedback.type === 'none') {\n resolve(undefined);\n return;\n }\n feedback = feedback || {};\n const out = feedback[feedback.type] || fallback;\n resolve(out);\n });\n\n// TODO: should replace getFeedbackForCorrectness\n/**\n * Get feedback for correctness\n * @param {'correct'|'incorrect'|'partial'} correctness\n * @param {Feedback} feedback\n */\nexport const getActualFeedbackForCorrectness = (correctness, feedback) => {\n feedback = { ...defaults, ...feedback };\n\n // normalize correctness\n correctness = correctness === 'partially-correct' ? 'partial' : correctness;\n\n const defaultFeedback = defaults[correctness] || {};\n const fb = feedback[correctness] || defaultFeedback;\n\n return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);\n};\n\n// TODO: should replace getFeedback\n/**\n * Get the feedback from a {FeedbackConfig}\n * @param {FeedbackConfig} feedback\n * @param {string} fallback\n */\nexport const getActualFeedback = (feedback, fallback) => {\n if (!feedback || feedback.type === 'none') {\n return undefined;\n }\n\n return feedback[feedback.type] || fallback;\n};\n"],"names":["defaults","correct","type","default","custom","incorrect","partial","unanswered","normalizeCorrectness","c","getFeedbackForCorrectness","correctness","feedback","Promise","resolve","fb","d","getFeedback","then","result","fallback","undefined","out","getActualFeedbackForCorrectness","defaultFeedback","getActualFeedback"],"mappings":";;;;;;;;;;;;;;;;;;AAAO,MAAMA,QAAQ,GAAG;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AACzC,IAAA,OAAOmB,SAAP;AACD,EAAA;;AAED,EAAA,OAAOT,QAAQ,CAACA,QAAQ,CAACV,IAAV,CAAR,IAA2BkB,QAAlC;AACD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/feedback",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"description": "Feedback utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -10,5 +10,12 @@
|
|
|
10
10
|
"scripts": {},
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "8a327571bd64249e4c88c0c8e750d16d6213f535",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./esm/index.js",
|
|
17
|
+
"require": "./lib/index.js",
|
|
18
|
+
"default": "./esm/index.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
14
21
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Copyright 2019 CoreSpring Inc
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
-
|
|
5
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|