@pie-lib/feedback 0.4.43-next.0 → 0.5.1-beta.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/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [0.4.42](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.40...@pie-lib/feedback@0.4.42) (2023-01-31)
6
+ ## [0.5.1-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.1-beta.0) (2025-07-20)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/feedback
9
9
 
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- ## [0.4.40](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.39...@pie-lib/feedback@0.4.40) (2023-01-31)
14
+ # [0.5.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.0) (2025-07-20)
15
15
 
16
16
  **Note:** Version bump only for package @pie-lib/feedback
17
17
 
@@ -19,54 +19,50 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
19
19
 
20
20
 
21
21
 
22
- ## [0.4.39](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.38...@pie-lib/feedback@0.4.39) (2023-01-31)
22
+ # [0.6.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.6.0-beta.0) (2025-07-15)
23
23
 
24
24
  **Note:** Version bump only for package @pie-lib/feedback
25
25
 
26
+ # [0.5.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.0) (2025-07-15)
26
27
 
28
+ **Note:** Version bump only for package @pie-lib/feedback
27
29
 
28
-
29
-
30
- ## [0.4.38](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.37...@pie-lib/feedback@0.4.38) (2023-01-31)
30
+ ## [0.4.43](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.42...@pie-lib/feedback@0.4.43) (2023-06-24)
31
31
 
32
32
  **Note:** Version bump only for package @pie-lib/feedback
33
33
 
34
+ ## [0.4.42](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.40...@pie-lib/feedback@0.4.42) (2023-01-31)
34
35
 
36
+ **Note:** Version bump only for package @pie-lib/feedback
35
37
 
38
+ ## [0.4.40](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.39...@pie-lib/feedback@0.4.40) (2023-01-31)
36
39
 
40
+ **Note:** Version bump only for package @pie-lib/feedback
37
41
 
38
- ## [0.4.37](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.32...@pie-lib/feedback@0.4.37) (2023-01-31)
42
+ ## [0.4.39](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.38...@pie-lib/feedback@0.4.39) (2023-01-31)
39
43
 
40
44
  **Note:** Version bump only for package @pie-lib/feedback
41
45
 
46
+ ## [0.4.38](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.37...@pie-lib/feedback@0.4.38) (2023-01-31)
42
47
 
48
+ **Note:** Version bump only for package @pie-lib/feedback
43
49
 
50
+ ## [0.4.37](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.32...@pie-lib/feedback@0.4.37) (2023-01-31)
44
51
 
52
+ **Note:** Version bump only for package @pie-lib/feedback
45
53
 
46
54
  ## [0.4.32](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.30...@pie-lib/feedback@0.4.32) (2023-01-31)
47
55
 
48
56
  **Note:** Version bump only for package @pie-lib/feedback
49
57
 
50
-
51
-
52
-
53
-
54
58
  ## [0.4.30](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.28...@pie-lib/feedback@0.4.30) (2023-01-31)
55
59
 
56
60
  **Note:** Version bump only for package @pie-lib/feedback
57
61
 
58
-
59
-
60
-
61
-
62
62
  ## [0.4.28](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.27...@pie-lib/feedback@0.4.28) (2022-11-23)
63
63
 
64
64
  **Note:** Version bump only for package @pie-lib/feedback
65
65
 
66
-
67
-
68
-
69
-
70
66
  ## [0.4.27](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.25...@pie-lib/feedback@0.4.27) (2021-06-25)
71
67
 
72
68
  **Note:** Version bump only for package @pie-lib/feedback
@@ -0,0 +1 @@
1
+ []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/feedback",
3
- "version": "0.4.43-next.0+2f8c6198",
3
+ "version": "0.5.1-beta.0",
4
4
  "description": "Feedback utilities",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -10,5 +10,5 @@
10
10
  "scripts": {},
11
11
  "author": "",
12
12
  "license": "ISC",
13
- "gitHead": "2f8c619845b4aa9a1c862b2ac549a975fe0bd13f"
13
+ "gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453"
14
14
  }
@@ -0,0 +1,61 @@
1
+ import { getFeedbackForCorrectness, getFeedback, defaults } from '../index';
2
+ describe('feedback', () => {
3
+ describe('getFeedback', () => {
4
+ const assert = (config, fallback, expected) => {
5
+ it(`${JSON.stringify(config)} -> ${expected}`, async () => {
6
+ const result = await getFeedback(config, fallback);
7
+ expect(result).toEqual(expected);
8
+ });
9
+ };
10
+
11
+ assert({ type: 'none' }, 'foo', undefined);
12
+ assert({ type: 'default' }, 'foo', 'foo');
13
+ assert({ type: 'default', default: 'bar' }, 'foo', 'bar');
14
+ });
15
+
16
+ describe('getFeedbackForCorrectness', () => {
17
+ const assert = (correctness, config, expected) => {
18
+ it(`${correctness} + ${JSON.stringify(config)} -> ${expected}`, async () => {
19
+ const result = await getFeedbackForCorrectness(correctness, config);
20
+ expect(result).toEqual(expected);
21
+ });
22
+ };
23
+
24
+ describe('correct', () => {
25
+ assert('correct', null, 'Correct');
26
+ assert('correct', {}, 'Correct');
27
+ assert('correct', { correct: { type: 'default' } }, 'Correct');
28
+ assert('correct', { correct: { type: 'default', default: 'C' } }, 'C');
29
+ assert('correct', { correct: { type: 'none', default: 'C' } }, undefined);
30
+ assert('correct', { correct: { type: 'custom', custom: 'Custom' } }, 'Custom');
31
+ });
32
+
33
+ describe('incorrect', () => {
34
+ assert('incorrect', {}, 'Incorrect');
35
+ assert('incorrect', { incorrect: { type: 'default' } }, 'Incorrect');
36
+ assert('incorrect', { incorrect: { type: 'default', default: 'I' } }, 'I');
37
+ assert('incorrect', { incorrect: { type: 'none', default: 'C' } }, undefined);
38
+ assert('incorrect', { incorrect: { type: 'custom', custom: 'Custom' } }, 'Custom');
39
+ });
40
+
41
+ describe('unanswered', () => {
42
+ assert('unanswered', {}, defaults.unanswered.default);
43
+ });
44
+
45
+ describe('unknown', () => {
46
+ assert('unknown', {}, undefined);
47
+ });
48
+
49
+ describe('partially-correct', () => {
50
+ assert('partially-correct', {}, 'Nearly');
51
+ });
52
+
53
+ describe('partial', () => {
54
+ assert('partial', {}, 'Nearly');
55
+ assert('partial', { partial: { type: 'default' } }, 'Nearly');
56
+ assert('partial', { partial: { type: 'default', default: 'I' } }, 'I');
57
+ assert('partial', { partial: { type: 'none', default: 'C' } }, undefined);
58
+ assert('partial', { partial: { type: 'custom', custom: 'Custom' } }, 'Custom');
59
+ });
60
+ });
61
+ });
package/src/index.js CHANGED
@@ -59,3 +59,35 @@ export const getFeedback = (feedback, fallback) =>
59
59
  const out = feedback[feedback.type] || fallback;
60
60
  resolve(out);
61
61
  });
62
+
63
+ // TODO: should replace getFeedbackForCorrectness
64
+ /**
65
+ * Get feedback for correctness
66
+ * @param {'correct'|'incorrect'|'partial'} correctness
67
+ * @param {Feedback} feedback
68
+ */
69
+ export const getActualFeedbackForCorrectness = (correctness, feedback) => {
70
+ feedback = { ...defaults, ...feedback };
71
+
72
+ // normalize correctness
73
+ correctness = correctness === 'partially-correct' ? 'partial' : correctness;
74
+
75
+ const defaultFeedback = defaults[correctness] || {};
76
+ const fb = feedback[correctness] || defaultFeedback;
77
+
78
+ return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);
79
+ };
80
+
81
+ // TODO: should replace getFeedback
82
+ /**
83
+ * Get the feedback from a {FeedbackConfig}
84
+ * @param {FeedbackConfig} feedback
85
+ * @param {string} fallback
86
+ */
87
+ export const getActualFeedback = (feedback, fallback) => {
88
+ if (!feedback || feedback.type === 'none') {
89
+ return undefined;
90
+ }
91
+
92
+ return feedback[feedback.type] || fallback;
93
+ };
package/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "6"
4
- branches:
5
- only:
6
- - master
7
- - develop
package/README.md DELETED
@@ -1 +0,0 @@
1
- # feedback
package/lib/index.js DELETED
@@ -1,102 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getFeedbackForCorrectness = exports.getFeedback = exports.defaults = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- 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; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(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; }
15
-
16
- var defaults = {
17
- correct: {
18
- type: 'default',
19
- "default": 'Correct',
20
- custom: 'Correct'
21
- },
22
- incorrect: {
23
- type: 'default',
24
- "default": 'Incorrect',
25
- custom: 'Incorrect'
26
- },
27
- partial: {
28
- type: 'default',
29
- "default": 'Nearly',
30
- custom: 'Nearly'
31
- },
32
- unanswered: {
33
- type: 'default',
34
- "default": 'You have not entered a response',
35
- custom: 'You have not entered a response'
36
- }
37
- };
38
- /**
39
- * @typedef {Object} FeedbackConfig
40
- * @property {'default'|'none'|'custom'} type
41
- * @property {string} default
42
- * @property {string} custom
43
- *
44
- * @typedef {Object} Feedback
45
- * @property {FeedbackConfig} correct
46
- * @property {FeedbackConfig} incorrect
47
- * @property {FeedbackConfig} partial
48
- */
49
-
50
- exports.defaults = defaults;
51
-
52
- var normalizeCorrectness = function normalizeCorrectness(c) {
53
- if (c === 'partially-correct') {
54
- return 'partial';
55
- }
56
-
57
- return c;
58
- };
59
- /**
60
- * Get the feedback for the correctness
61
- *
62
- * @param {'correct'|'incorrect'|'partial'} correctness
63
- * @param {Feedback} feedback
64
- */
65
-
66
-
67
- var getFeedbackForCorrectness = function getFeedbackForCorrectness(correctness, feedback) {
68
- return new Promise(function (resolve) {
69
- feedback = _objectSpread(_objectSpread({}, defaults), feedback);
70
- correctness = normalizeCorrectness(correctness);
71
- var fb = feedback[correctness] || defaults[correctness] || {};
72
- var d = defaults[correctness] || {};
73
- getFeedback(fb, d[fb.type || 'default']).then(function (result) {
74
- return resolve(result);
75
- });
76
- });
77
- };
78
- /**
79
- * Get the feedback from a {FeedbackConfig}
80
- *
81
- * @param {FeedbackConfig} feedback
82
- * @param {string} fallback
83
- */
84
-
85
-
86
- exports.getFeedbackForCorrectness = getFeedbackForCorrectness;
87
-
88
- var getFeedback = function getFeedback(feedback, fallback) {
89
- return new Promise(function (resolve) {
90
- if (!feedback || feedback.type === 'none') {
91
- resolve(undefined);
92
- return;
93
- }
94
-
95
- feedback = feedback || {};
96
- var out = feedback[feedback.type] || fallback;
97
- resolve(out);
98
- });
99
- };
100
-
101
- exports.getFeedback = getFeedback;
102
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["defaults","correct","type","custom","incorrect","partial","unanswered","normalizeCorrectness","c","getFeedbackForCorrectness","correctness","feedback","Promise","resolve","fb","d","getFeedback","then","result","fallback","undefined","out"],"mappings":";;;;;;;;;;;;;;;AAAO,IAAMA,QAAQ,GAAG;AACtBC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,IAAI,EAAE,SAAR;AAAmB,eAAS,SAA5B;AAAuCC,IAAAA,MAAM,EAAE;AAA/C,GADa;AAEtBC,EAAAA,SAAS,EAAE;AAAEF,IAAAA,IAAI,EAAE,SAAR;AAAmB,eAAS,WAA5B;AAAyCC,IAAAA,MAAM,EAAE;AAAjD,GAFW;AAGtBE,EAAAA,OAAO,EAAE;AAAEH,IAAAA,IAAI,EAAE,SAAR;AAAmB,eAAS,QAA5B;AAAsCC,IAAAA,MAAM,EAAE;AAA9C,GAHa;AAItBG,EAAAA,UAAU,EAAE;AACVJ,IAAAA,IAAI,EAAE,SADI;AAEV,eAAS,iCAFC;AAGVC,IAAAA,MAAM,EAAE;AAHE;AAJU,CAAjB;AAWP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AAEA,IAAMI,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,CAAD,EAAO;AAClC,MAAIA,CAAC,KAAK,mBAAV,EAA+B;AAC7B,WAAO,SAAP;AACD;;AACD,SAAOA,CAAP;AACD,CALD;AAOA;AACA;AACA;AACA;AACA;AACA;;;AACO,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,WAAD,EAAcC,QAAd;AAAA,SACvC,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AACvBF,IAAAA,QAAQ,mCAAQX,QAAR,GAAqBW,QAArB,CAAR;AACAD,IAAAA,WAAW,GAAGH,oBAAoB,CAACG,WAAD,CAAlC;AACA,QAAMI,EAAE,GAAGH,QAAQ,CAACD,WAAD,CAAR,IAAyBV,QAAQ,CAACU,WAAD,CAAjC,IAAkD,EAA7D;AACA,QAAMK,CAAC,GAAGf,QAAQ,CAACU,WAAD,CAAR,IAAyB,EAAnC;AACAM,IAAAA,WAAW,CAACF,EAAD,EAAKC,CAAC,CAACD,EAAE,CAACZ,IAAH,IAAW,SAAZ,CAAN,CAAX,CAAyCe,IAAzC,CAA8C,UAACC,MAAD;AAAA,aAAYL,OAAO,CAACK,MAAD,CAAnB;AAAA,KAA9C;AACD,GAND,CADuC;AAAA,CAAlC;AASP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMF,WAAW,GAAG,SAAdA,WAAc,CAACL,QAAD,EAAWQ,QAAX;AAAA,SACzB,IAAIP,OAAJ,CAAY,UAACC,OAAD,EAAa;AACvB,QAAI,CAACF,QAAD,IAAaA,QAAQ,CAACT,IAAT,KAAkB,MAAnC,EAA2C;AACzCW,MAAAA,OAAO,CAACO,SAAD,CAAP;AACA;AACD;;AACDT,IAAAA,QAAQ,GAAGA,QAAQ,IAAI,EAAvB;AACA,QAAMU,GAAG,GAAGV,QAAQ,CAACA,QAAQ,CAACT,IAAV,CAAR,IAA2BiB,QAAvC;AACAN,IAAAA,OAAO,CAACQ,GAAD,CAAP;AACD,GARD,CADyB;AAAA,CAApB","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"],"file":"index.js"}