@pie-lib/feedback 0.5.1-beta.0 → 0.7.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.json CHANGED
@@ -1,212 +1 @@
1
- [
2
- {
3
- "type": "fix",
4
- "scope": null,
5
- "subject": "rm child prepack in favour of root prepack",
6
- "merge": null,
7
- "header": "fix: rm child prepack in favour of root prepack",
8
- "body": null,
9
- "footer": null,
10
- "notes": [],
11
- "hash": "381d8d6485269b641d8d4655148966d2e70803be",
12
- "gitTags": "",
13
- "committerDate": "2019-03-15 09:51:11 +0000",
14
- "isTagged": true,
15
- "tag": "@pie-lib/feedback@0.4.9"
16
- },
17
- {
18
- "type": "chore",
19
- "scope": null,
20
- "subject": "get packages to call changelog function on prepack",
21
- "merge": null,
22
- "header": "chore: get packages to call changelog function on prepack",
23
- "body": null,
24
- "footer": null,
25
- "notes": [],
26
- "hash": "8828f01f2d16d29404ba837c1de40d09e7230ec5",
27
- "gitTags": "",
28
- "committerDate": "2019-03-14 12:40:05 +0000",
29
- "isTagged": true,
30
- "tag": "@pie-lib/feedback@0.4.5"
31
- },
32
- {
33
- "type": "chore",
34
- "scope": null,
35
- "subject": "call changelog on prepack",
36
- "merge": null,
37
- "header": "chore: call changelog on prepack",
38
- "body": null,
39
- "footer": null,
40
- "notes": [],
41
- "hash": "b672c012de096c55b765a765f758da3fc5df2f90",
42
- "gitTags": "",
43
- "committerDate": "2019-03-13 23:00:44 +0000",
44
- "isTagged": true,
45
- "tag": "@pie-lib/feedback@0.4.4"
46
- },
47
- {
48
- "type": "chore",
49
- "scope": null,
50
- "subject": "generate changelog.json instead of markdown",
51
- "merge": null,
52
- "header": "chore: generate changelog.json instead of markdown",
53
- "body": null,
54
- "footer": null,
55
- "notes": [],
56
- "hash": "eaa5019a11f70c53425d55856bd3b940237f8c7d",
57
- "gitTags": "",
58
- "committerDate": "2019-03-13 17:24:09 +0000",
59
- "isTagged": true,
60
- "tag": "@pie-lib/feedback@0.4.2"
61
- },
62
- {
63
- "type": "fix",
64
- "scope": null,
65
- "subject": "handle undefined feedback arguments",
66
- "merge": null,
67
- "header": "fix: handle undefined feedback arguments",
68
- "body": null,
69
- "footer": null,
70
- "notes": [],
71
- "hash": "66b981c24a3dbb48e9926771199fd5e30475b27d",
72
- "gitTags": "",
73
- "committerDate": "2018-05-10 21:34:40 -0400",
74
- "isTagged": true,
75
- "tag": "@pie-lib/feedback@0.4.1"
76
- },
77
- {
78
- "type": "chore",
79
- "scope": "test",
80
- "subject": "update tests",
81
- "merge": null,
82
- "header": "chore(test): update tests",
83
- "body": null,
84
- "footer": null,
85
- "notes": [],
86
- "hash": "b970b4822f4bb19fa9e2b64f9a8e6466d9ad7a76",
87
- "gitTags": "",
88
- "committerDate": "2018-05-10 21:19:11 -0400",
89
- "isTagged": true,
90
- "tag": "@pie-lib/feedback@0.4.0"
91
- },
92
- {
93
- "type": "feat",
94
- "scope": "unanswered",
95
- "subject": "add unanswered feedback",
96
- "merge": null,
97
- "header": "feat(unanswered): add unanswered feedback",
98
- "body": null,
99
- "footer": null,
100
- "notes": [],
101
- "hash": "a6835c4f026a92bb29316838aee7c31d5a895285",
102
- "gitTags": "",
103
- "committerDate": "2018-05-10 21:18:13 -0400",
104
- "isTagged": true,
105
- "tag": "@pie-lib/feedback@0.4.0"
106
- },
107
- {
108
- "type": "feat",
109
- "scope": "defaults",
110
- "subject": "expose defaults",
111
- "merge": null,
112
- "header": "feat(defaults): expose defaults",
113
- "body": null,
114
- "footer": null,
115
- "notes": [],
116
- "hash": "f818355448d44f0f86a7ab41b7afe7663909e0cc",
117
- "gitTags": "",
118
- "committerDate": "2018-05-10 21:10:09 -0400",
119
- "isTagged": true,
120
- "tag": "@pie-lib/feedback@0.3.0"
121
- },
122
- {
123
- "type": "fix",
124
- "scope": "partial",
125
- "subject": "normalize 'partially-correct' to 'partial'",
126
- "merge": null,
127
- "header": "fix(partial): normalize 'partially-correct' to 'partial'",
128
- "body": null,
129
- "footer": null,
130
- "notes": [],
131
- "hash": "4c5f21d1fa8e6566a5ea5d828448e3685480f0e5",
132
- "gitTags": "",
133
- "committerDate": "2018-05-10 19:05:12 -0400",
134
- "isTagged": true,
135
- "tag": "@pie-lib/feedback@0.2.1"
136
- },
137
- {
138
- "type": "feat",
139
- "scope": "api",
140
- "subject": "add getFeedbackForCorrectness + getFeedback",
141
- "merge": null,
142
- "header": "feat(api): add getFeedbackForCorrectness + getFeedback",
143
- "body": null,
144
- "footer": null,
145
- "notes": [],
146
- "hash": "8fc064b49dfcadf6c1e11249d3f8ec08b16efc1b",
147
- "gitTags": "",
148
- "committerDate": "2018-05-10 09:21:54 -0400",
149
- "isTagged": true,
150
- "tag": "@pie-lib/feedback@0.2.0"
151
- },
152
- {
153
- "type": "feat",
154
- "scope": "getFeedback",
155
- "subject": "add getFeedback function",
156
- "merge": null,
157
- "header": "feat(getFeedback): add getFeedback function",
158
- "body": null,
159
- "footer": null,
160
- "notes": [],
161
- "hash": "6329fb68a08fbbc7f7c98276905082da3184826b",
162
- "gitTags": "",
163
- "committerDate": "2018-05-09 21:51:01 -0400",
164
- "isTagged": true,
165
- "tag": "@pie-lib/feedback@0.1.0"
166
- },
167
- {
168
- "type": "feat",
169
- "scope": "feedback",
170
- "subject": "add new feedback package",
171
- "merge": null,
172
- "header": "feat(feedback): add new feedback package",
173
- "body": null,
174
- "footer": null,
175
- "notes": [],
176
- "hash": "540769dc539f0f4eb27d8da520f228ed20174ecc",
177
- "gitTags": "",
178
- "committerDate": "2018-05-09 15:08:07 -0400",
179
- "isTagged": true,
180
- "tag": "@pie-lib/feedback@0.1.0"
181
- },
182
- {
183
- "type": "fix",
184
- "scope": null,
185
- "subject": "add module prop to package.json",
186
- "merge": null,
187
- "header": "fix: add module prop to package.json",
188
- "body": null,
189
- "footer": null,
190
- "notes": [],
191
- "hash": "e5c19defe16b64b01d07418da78636a2564b4eed",
192
- "gitTags": "",
193
- "committerDate": "2020-03-29 23:09:02 +0100",
194
- "isTagged": true,
195
- "tag": "@pie-lib/feedback@0.4.10"
196
- },
197
- {
198
- "type": "fix",
199
- "scope": null,
200
- "subject": "add module prop to package.json",
201
- "merge": null,
202
- "header": "fix: add module prop to package.json",
203
- "body": null,
204
- "footer": null,
205
- "notes": [],
206
- "hash": "bb8039dc77228e49315cd52de46be4a423ddef7e",
207
- "gitTags": "",
208
- "committerDate": "2020-03-30 13:01:19 +0100",
209
- "isTagged": true,
210
- "tag": "@pie-lib/feedback@0.4.11"
211
- }
212
- ]
1
+ []
package/CHANGELOG.md CHANGED
@@ -3,7 +3,151 @@
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.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)
6
+ # [0.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.7.0) (2025-07-31)
7
+
8
+ **Note:** Version bump only for package @pie-lib/feedback
9
+
10
+
11
+
12
+
13
+
14
+ # [0.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.6.0) (2025-07-31)
15
+
16
+ **Note:** Version bump only for package @pie-lib/feedback
17
+
18
+
19
+
20
+
21
+
22
+ # [0.5.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.8) (2025-07-25)
23
+
24
+ **Note:** Version bump only for package @pie-lib/feedback
25
+
26
+
27
+
28
+
29
+
30
+ # [0.5.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.7) (2025-07-25)
31
+
32
+ **Note:** Version bump only for package @pie-lib/feedback
33
+
34
+
35
+
36
+
37
+
38
+ # [0.5.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.7) (2025-07-25)
39
+
40
+ **Note:** Version bump only for package @pie-lib/feedback
41
+
42
+
43
+
44
+
45
+
46
+ # [0.5.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.6) (2025-07-25)
47
+
48
+ **Note:** Version bump only for package @pie-lib/feedback
49
+
50
+
51
+
52
+
53
+
54
+ # [0.5.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.6) (2025-07-25)
55
+
56
+ **Note:** Version bump only for package @pie-lib/feedback
57
+
58
+
59
+
60
+
61
+
62
+ # [0.5.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.5) (2025-07-25)
63
+
64
+ **Note:** Version bump only for package @pie-lib/feedback
65
+
66
+
67
+
68
+
69
+
70
+ # [0.5.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.5) (2025-07-25)
71
+
72
+ **Note:** Version bump only for package @pie-lib/feedback
73
+
74
+
75
+
76
+
77
+
78
+ # [0.5.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.4) (2025-07-25)
79
+
80
+ **Note:** Version bump only for package @pie-lib/feedback
81
+
82
+
83
+
84
+
85
+
86
+ # [0.5.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.3) (2025-07-25)
87
+
88
+ **Note:** Version bump only for package @pie-lib/feedback
89
+
90
+
91
+
92
+
93
+
94
+ # [0.5.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.4) (2025-07-23)
95
+
96
+ **Note:** Version bump only for package @pie-lib/feedback
97
+
98
+
99
+
100
+
101
+
102
+ # [0.5.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.3) (2025-07-23)
103
+
104
+ **Note:** Version bump only for package @pie-lib/feedback
105
+
106
+
107
+
108
+
109
+
110
+ # [0.5.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.3) (2025-07-20)
111
+
112
+ **Note:** Version bump only for package @pie-lib/feedback
113
+
114
+
115
+
116
+
117
+
118
+ # [0.5.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.2) (2025-07-20)
119
+
120
+ **Note:** Version bump only for package @pie-lib/feedback
121
+
122
+
123
+
124
+
125
+
126
+ # [0.5.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.1) (2025-07-20)
127
+
128
+ **Note:** Version bump only for package @pie-lib/feedback
129
+
130
+
131
+
132
+
133
+
134
+ # [0.5.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.2) (2025-07-20)
135
+
136
+ **Note:** Version bump only for package @pie-lib/feedback
137
+
138
+
139
+
140
+
141
+
142
+ # [0.5.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.1) (2025-07-20)
143
+
144
+ **Note:** Version bump only for package @pie-lib/feedback
145
+
146
+
147
+
148
+
149
+
150
+ # [0.5.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/feedback@0.4.43...@pie-lib/feedback@0.5.0-beta.1) (2025-07-20)
7
151
 
8
152
  **Note:** Version bump only for package @pie-lib/feedback
9
153
 
package/lib/index.js ADDED
@@ -0,0 +1,137 @@
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.getActualFeedbackForCorrectness = exports.getActualFeedback = 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
+ }; // TODO: should replace getFeedbackForCorrectness
100
+
101
+ /**
102
+ * Get feedback for correctness
103
+ * @param {'correct'|'incorrect'|'partial'} correctness
104
+ * @param {Feedback} feedback
105
+ */
106
+
107
+
108
+ exports.getFeedback = getFeedback;
109
+
110
+ var getActualFeedbackForCorrectness = function getActualFeedbackForCorrectness(correctness, feedback) {
111
+ feedback = _objectSpread(_objectSpread({}, defaults), feedback); // normalize correctness
112
+
113
+ correctness = correctness === 'partially-correct' ? 'partial' : correctness;
114
+ var defaultFeedback = defaults[correctness] || {};
115
+ var fb = feedback[correctness] || defaultFeedback;
116
+ return getActualFeedback(fb, defaultFeedback[fb.type || 'default']);
117
+ }; // TODO: should replace getFeedback
118
+
119
+ /**
120
+ * Get the feedback from a {FeedbackConfig}
121
+ * @param {FeedbackConfig} feedback
122
+ * @param {string} fallback
123
+ */
124
+
125
+
126
+ exports.getActualFeedbackForCorrectness = getActualFeedbackForCorrectness;
127
+
128
+ var getActualFeedback = function getActualFeedback(feedback, fallback) {
129
+ if (!feedback || feedback.type === 'none') {
130
+ return undefined;
131
+ }
132
+
133
+ return feedback[feedback.type] || fallback;
134
+ };
135
+
136
+ exports.getActualFeedback = getActualFeedback;
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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","getActualFeedbackForCorrectness","defaultFeedback","getActualFeedback"],"mappings":"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","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"],"file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/feedback",
3
- "version": "0.5.1-beta.0",
3
+ "version": "0.7.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": "e2aa3ddac60f49bcb8c2562370f496323642f453"
13
+ "gitHead": "ecb1ca31aa1c24d23af00d5ad04ce73ed8871057"
14
14
  }