@pie-lib/feedback 0.20.0 → 0.21.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/esm/index.js +124 -0
- package/esm/index.js.map +1 -0
- package/package.json +9 -2
package/esm/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
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 = {
|
|
21
|
+
correct: {
|
|
22
|
+
type: 'default',
|
|
23
|
+
default: 'Correct',
|
|
24
|
+
custom: 'Correct'
|
|
25
|
+
},
|
|
26
|
+
incorrect: {
|
|
27
|
+
type: 'default',
|
|
28
|
+
default: 'Incorrect',
|
|
29
|
+
custom: 'Incorrect'
|
|
30
|
+
},
|
|
31
|
+
partial: {
|
|
32
|
+
type: 'default',
|
|
33
|
+
default: 'Nearly',
|
|
34
|
+
custom: 'Nearly'
|
|
35
|
+
},
|
|
36
|
+
unanswered: {
|
|
37
|
+
type: 'default',
|
|
38
|
+
default: 'You have not entered a response',
|
|
39
|
+
custom: 'You have not entered a response'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} FeedbackConfig
|
|
44
|
+
* @property {'default'|'none'|'custom'} type
|
|
45
|
+
* @property {string} default
|
|
46
|
+
* @property {string} custom
|
|
47
|
+
*
|
|
48
|
+
* @typedef {Object} Feedback
|
|
49
|
+
* @property {FeedbackConfig} correct
|
|
50
|
+
* @property {FeedbackConfig} incorrect
|
|
51
|
+
* @property {FeedbackConfig} partial
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
var normalizeCorrectness = c => {
|
|
55
|
+
if (c === 'partially-correct') {
|
|
56
|
+
return 'partial';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return c;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Get the feedback for the correctness
|
|
63
|
+
*
|
|
64
|
+
* @param {'correct'|'incorrect'|'partial'} correctness
|
|
65
|
+
* @param {Feedback} feedback
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
var getFeedbackForCorrectness = (correctness, feedback) => new Promise(resolve => {
|
|
70
|
+
feedback = _objectSpread(_objectSpread({}, defaults), feedback);
|
|
71
|
+
correctness = normalizeCorrectness(correctness);
|
|
72
|
+
var fb = feedback[correctness] || defaults[correctness] || {};
|
|
73
|
+
var d = defaults[correctness] || {};
|
|
74
|
+
getFeedback(fb, d[fb.type || 'default']).then(result => resolve(result));
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Get the feedback from a {FeedbackConfig}
|
|
78
|
+
*
|
|
79
|
+
* @param {FeedbackConfig} feedback
|
|
80
|
+
* @param {string} fallback
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
var getFeedback = (feedback, fallback) => new Promise(resolve => {
|
|
84
|
+
if (!feedback || feedback.type === 'none') {
|
|
85
|
+
resolve(undefined);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
feedback = feedback || {};
|
|
90
|
+
var out = feedback[feedback.type] || fallback;
|
|
91
|
+
resolve(out);
|
|
92
|
+
}); // TODO: should replace getFeedbackForCorrectness
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get feedback for correctness
|
|
96
|
+
* @param {'correct'|'incorrect'|'partial'} correctness
|
|
97
|
+
* @param {Feedback} feedback
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
var getActualFeedbackForCorrectness = (correctness, feedback) => {
|
|
101
|
+
feedback = _objectSpread(_objectSpread({}, defaults), feedback); // normalize correctness
|
|
102
|
+
|
|
103
|
+
correctness = correctness === 'partially-correct' ? 'partial' : correctness;
|
|
104
|
+
var defaultFeedback = defaults[correctness] || {};
|
|
105
|
+
var fb = feedback[correctness] || defaultFeedback;
|
|
106
|
+
return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);
|
|
107
|
+
}; // TODO: should replace getFeedback
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the feedback from a {FeedbackConfig}
|
|
111
|
+
* @param {FeedbackConfig} feedback
|
|
112
|
+
* @param {string} fallback
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
var getActualFeedback = (feedback, fallback) => {
|
|
116
|
+
if (!feedback || feedback.type === 'none') {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return feedback[feedback.type] || fallback;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { defaults, getActualFeedback, getActualFeedbackForCorrectness, getFeedback, getFeedbackForCorrectness };
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../src/index.js"],"sourcesContent":["export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","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":"AAAe,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE;AACzD,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;AAClB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE;AACpC,MAAM,KAAK,EAAE,KAAK;AAClB,MAAM,UAAU,EAAE,IAAI;AACtB,MAAM,YAAY,EAAE,IAAI;AACxB,MAAM,QAAQ,EAAE;AAChB,KAAK,CAAC;AACN,EAAE,CAAC,MAAM;AACT,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK;AACpB,EAAE;;AAEF,EAAE,OAAO,GAAG;AACZ;;;;;;ACbO,IAAMA,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,GAF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
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
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": "d6cccc4cca72fde471ababc7dce4c6236f5cbc0a",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./esm/index.js",
|
|
17
|
+
"require": "./lib/index.js",
|
|
18
|
+
"default": "./esm/index.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
14
21
|
}
|