@pie-lib/feedback 0.21.0 → 0.21.3
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 +29 -30
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
20
|
-
var defaults = {
|
|
19
|
+
const defaults = {
|
|
21
20
|
correct: {
|
|
22
21
|
type: 'default',
|
|
23
22
|
default: 'Correct',
|
|
@@ -51,7 +50,7 @@ var defaults = {
|
|
|
51
50
|
* @property {FeedbackConfig} partial
|
|
52
51
|
*/
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
const normalizeCorrectness = c => {
|
|
55
54
|
if (c === 'partially-correct') {
|
|
56
55
|
return 'partial';
|
|
57
56
|
}
|
|
@@ -66,11 +65,11 @@ var normalizeCorrectness = c => {
|
|
|
66
65
|
*/
|
|
67
66
|
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
feedback =
|
|
68
|
+
const getFeedbackForCorrectness = (correctness, feedback) => new Promise(resolve => {
|
|
69
|
+
feedback = _extends({}, defaults, feedback);
|
|
71
70
|
correctness = normalizeCorrectness(correctness);
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const fb = feedback[correctness] || defaults[correctness] || {};
|
|
72
|
+
const d = defaults[correctness] || {};
|
|
74
73
|
getFeedback(fb, d[fb.type || 'default']).then(result => resolve(result));
|
|
75
74
|
});
|
|
76
75
|
/**
|
|
@@ -80,14 +79,14 @@ var getFeedbackForCorrectness = (correctness, feedback) => new Promise(resolve =
|
|
|
80
79
|
* @param {string} fallback
|
|
81
80
|
*/
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
const getFeedback = (feedback, fallback) => new Promise(resolve => {
|
|
84
83
|
if (!feedback || feedback.type === 'none') {
|
|
85
84
|
resolve(undefined);
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
feedback = feedback || {};
|
|
90
|
-
|
|
89
|
+
const out = feedback[feedback.type] || fallback;
|
|
91
90
|
resolve(out);
|
|
92
91
|
}); // TODO: should replace getFeedbackForCorrectness
|
|
93
92
|
|
|
@@ -97,12 +96,12 @@ var getFeedback = (feedback, fallback) => new Promise(resolve => {
|
|
|
97
96
|
* @param {Feedback} feedback
|
|
98
97
|
*/
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
feedback =
|
|
99
|
+
const getActualFeedbackForCorrectness = (correctness, feedback) => {
|
|
100
|
+
feedback = _extends({}, defaults, feedback); // normalize correctness
|
|
102
101
|
|
|
103
102
|
correctness = correctness === 'partially-correct' ? 'partial' : correctness;
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const defaultFeedback = defaults[correctness] || {};
|
|
104
|
+
const fb = feedback[correctness] || defaultFeedback;
|
|
106
105
|
return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);
|
|
107
106
|
}; // TODO: should replace getFeedback
|
|
108
107
|
|
|
@@ -112,7 +111,7 @@ var getActualFeedbackForCorrectness = (correctness, feedback) => {
|
|
|
112
111
|
* @param {string} fallback
|
|
113
112
|
*/
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
const getActualFeedback = (feedback, fallback) => {
|
|
116
115
|
if (!feedback || feedback.type === 'none') {
|
|
117
116
|
return undefined;
|
|
118
117
|
}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["
|
|
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;AACtBC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,IAAI,EAAE,SAAR;AAAmBC,IAAAA,OAAO,EAAE,SAA5B;AAAuCC,IAAAA,MAAM,EAAE;AAA/C,GADa;AAEtBC,EAAAA,SAAS,EAAE;AAAEH,IAAAA,IAAI,EAAE,SAAR;AAAmBC,IAAAA,OAAO,EAAE,WAA5B;AAAyCC,IAAAA,MAAM,EAAE;AAAjD,GAFW;AAGtBE,EAAAA,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,QAAQ,CAACV,IAAT,KAAkB,MAAnC,EAA2C;AACzCY,IAAAA,OAAO,CAACO,SAAD,CAAP;AACA,IAAA;AACD,EAAA;;AACDT,EAAAA,QAAQ,GAAGA,QAAQ,IAAI,EAAvB;AACA,EAAA,MAAMU,GAAG,GAAGV,QAAQ,CAACA,QAAQ,CAACV,IAAV,CAAR,IAA2BkB,QAAvC;AACAN,EAAAA,OAAO,CAACQ,GAAD,CAAP;AACD,CARD;;AAWF;AACA;AACA;AACA;AACA;;MACaC,+BAA+B,GAAG,CAACZ,WAAD,EAAcC,QAAd,KAA2B;AACxEA,EAAAA,QAAQ,GAAA,QAAA,CAAA,EAAA,EAAQZ,QAAR,EAAqBY,QAArB,CAAR,CADwE;;AAIxED,EAAAA,WAAW,GAAGA,WAAW,KAAK,mBAAhB,GAAsC,SAAtC,GAAkDA,WAAhE;AAEA,EAAA,MAAMa,eAAe,GAAGxB,QAAQ,CAACW,WAAD,CAAR,IAAyB,EAAjD;AACA,EAAA,MAAMI,EAAE,GAAGH,QAAQ,CAACD,WAAD,CAAR,IAAyBa,eAApC;AAEA,EAAA,OAAOC,iBAAiB,CAACV,EAAD,EAAKS,eAAe,CAACT,EAAE,CAACb,IAAH,IAAW,SAAZ,CAApB,CAAxB;AACD;;AAGD;AACA;AACA;AACA;AACA;;MACauB,iBAAiB,GAAG,CAACb,QAAD,EAAWQ,QAAX,KAAwB;AACvD,EAAA,IAAI,CAACR,QAAD,IAAaA,QAAQ,CAACV,IAAT,KAAkB,MAAnC,EAA2C;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.21.
|
|
3
|
+
"version": "0.21.3",
|
|
4
4
|
"description": "Feedback utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {},
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "3b10dbe1c14708ccf9a9e8af8f1eafec6ed7dd2d",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./esm/index.js",
|