@wg-npm/survey-core 0.3.377-8.develop → 0.3.3791

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.
@@ -54,7 +54,7 @@ class QuestionFactory {
54
54
  this.creatorHash[questionType] = questionCreator;
55
55
  }
56
56
  createQuestion(questionType) {
57
- let creator = this.creatorHash[questionType];
57
+ const creator = this.creatorHash[questionType];
58
58
  return creator(this.locale);
59
59
  }
60
60
  }
@@ -135,7 +135,7 @@ class BaseQuestionModel {
135
135
  return _.sumBy(question.choices, (item) => parseFloat(_.get(item, "options.score") || 0));
136
136
  }
137
137
  else if (question.type == "MATRIX") {
138
- let score = _.max(_.map(question.choices, (choice) => parseFloat(_.get(choice, "options.score", 0) || 0)));
138
+ const score = _.max(_.map(question.choices, (choice) => parseFloat(_.get(choice, "options.score", 0) || 0)));
139
139
  return score * question.subQuestions.length;
140
140
  }
141
141
  return 0;
@@ -153,7 +153,7 @@ class BaseQuestionModel {
153
153
  }
154
154
  static calculationAllQuestionCount(questions) {
155
155
  let count = 0;
156
- let exclude = ["TEXT_TITLE"];
156
+ const exclude = ["TEXT_TITLE"];
157
157
  _.forEach(questions, (question) => {
158
158
  if (!_.includes(exclude, question.type)) {
159
159
  count++;
@@ -251,7 +251,7 @@ class QuestionMatrixModel extends BaseQuestionModel {
251
251
  this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
252
252
  }
253
253
  static getNumber(preNumber, question) {
254
- let number = preNumber + 1;
254
+ const number = preNumber + 1;
255
255
  _.forEach(question.subQuestions, (sq, index) => {
256
256
  sq.number = index + 1;
257
257
  });
@@ -271,23 +271,27 @@ const ZH_CN = _.camelCase("zh-CN");
271
271
  const EN_US = _.camelCase("en-US");
272
272
  const ZH_TW = _.camelCase("zh-TW");
273
273
  function getValue(obj, locale) {
274
- let value = _.get(obj, _.camelCase(locale), '');
274
+ const value = _.get(obj, _.camelCase(locale), "");
275
275
  if (!_.isEmpty(value)) {
276
276
  return value;
277
277
  }
278
- return _.get(obj, locale, '');
278
+ return _.get(obj, locale, "");
279
279
  }
280
280
  function translate(obj, locale, prettyMath = false) {
281
- let value = getValue(obj, locale);
281
+ const value = getValue(obj, locale);
282
282
  if (!_.isEmpty(value) || !prettyMath) {
283
283
  return value;
284
284
  }
285
- return obj[ZH_CN] || obj["zh-CN"] || obj[EN_US] || obj["en-US"]
286
- || obj[ZH_TW] || obj["zh-TW"];
285
+ return (obj[ZH_CN] ||
286
+ obj["zh-CN"] ||
287
+ obj[EN_US] ||
288
+ obj["en-US"] ||
289
+ obj[ZH_TW] ||
290
+ obj["zh-TW"]);
287
291
  }
288
292
 
289
293
  function move(array, fromIndex, toIndex) {
290
- let moveValue = array[fromIndex];
294
+ const moveValue = array[fromIndex];
291
295
  array[fromIndex] = array[toIndex];
292
296
  array[toIndex] = moveValue;
293
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-core",
3
- "version": "0.3.3778.develop",
3
+ "version": "0.3.3791",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -1,5 +1,9 @@
1
- export function move(array: Array<any>, fromIndex: number, toIndex: number): void {
2
- let moveValue: any = array[fromIndex];
1
+ export function move(
2
+ array: Array<any>,
3
+ fromIndex: number,
4
+ toIndex: number
5
+ ): void {
6
+ const moveValue: any = array[fromIndex];
3
7
  array[fromIndex] = array[toIndex];
4
8
  array[toIndex] = moveValue;
5
9
  }
package/src/index.ts CHANGED
@@ -1,35 +1,33 @@
1
1
  export {
2
- SurveyLocales,
3
- SurveyLayout,
4
- QuestionType,
5
- ResponseStatisticsModel,
6
- PlanStatisticsModel,
7
- QuestionOptionsModel,
8
- QuestionHeaderModel,
9
- BaseQuestionModel,
10
- QuestionCheckBoxModel,
11
- QuestionTextTitleModel,
12
- QuestionMatrixModel,
13
- QuestionFillBlankModel,
14
- QuestionMulitSelectionModel,
15
- QuestionShortAnswerModel,
16
- QuestionSingleSelectionModel,
17
- QuestionEvaluationModel,
18
- SubQuestionModel,
19
- SurveyOptionsModel,
20
- SurveyModel,
21
- ChoiceModel,
22
- ResponseModel,
23
- PlanModel,
24
- EvaluationType,
25
- EvaluationItemModel,
26
- StarEvaluationItemModel,
27
- ExprEvaluationItemModel,
28
- ExprConditionModel,
29
- ExprConditionType
2
+ SurveyLocales,
3
+ SurveyLayout,
4
+ QuestionType,
5
+ ResponseStatisticsModel,
6
+ PlanStatisticsModel,
7
+ QuestionOptionsModel,
8
+ QuestionHeaderModel,
9
+ BaseQuestionModel,
10
+ QuestionCheckBoxModel,
11
+ QuestionTextTitleModel,
12
+ QuestionMatrixModel,
13
+ QuestionFillBlankModel,
14
+ QuestionMulitSelectionModel,
15
+ QuestionShortAnswerModel,
16
+ QuestionSingleSelectionModel,
17
+ QuestionEvaluationModel,
18
+ SubQuestionModel,
19
+ SurveyOptionsModel,
20
+ SurveyModel,
21
+ ChoiceModel,
22
+ ResponseModel,
23
+ PlanModel,
24
+ EvaluationType,
25
+ EvaluationItemModel,
26
+ StarEvaluationItemModel,
27
+ ExprEvaluationItemModel,
28
+ ExprConditionModel,
29
+ ExprConditionType,
30
30
  } from "./models";
31
- export {
32
- QuestionFactory
33
- } from "./quetion-factory"
31
+ export { QuestionFactory } from "./quetion-factory";
34
32
  export { translate } from "./locale-utils";
35
33
  export { move } from "./array-utils";
@@ -1,23 +1,33 @@
1
- import _ from 'lodash';
2
- import { SurveyLocales } from './models';
1
+ import _ from "lodash";
2
+ import { SurveyLocales } from "./models";
3
3
 
4
4
  const ZH_CN: string = _.camelCase(SurveyLocales.ZH_CN);
5
5
  const EN_US: string = _.camelCase(SurveyLocales.EN_US);
6
6
  const ZH_TW: string = _.camelCase(SurveyLocales.ZH_TW);
7
7
 
8
8
  function getValue(obj: any, locale: string) {
9
- let value: any = _.get(obj, _.camelCase(locale), '');
9
+ const value: any = _.get(obj, _.camelCase(locale), "");
10
10
  if (!_.isEmpty(value)) {
11
11
  return value;
12
12
  }
13
- return _.get(obj, locale, '');
13
+ return _.get(obj, locale, "");
14
14
  }
15
15
 
16
- export function translate(obj: any, locale: string, prettyMath: boolean = false): any {
17
- let value: any = getValue(obj, locale);
16
+ export function translate(
17
+ obj: any,
18
+ locale: string,
19
+ prettyMath: boolean = false
20
+ ): any {
21
+ const value: any = getValue(obj, locale);
18
22
  if (!_.isEmpty(value) || !prettyMath) {
19
23
  return value;
20
24
  }
21
- return obj[ZH_CN] || obj[SurveyLocales.ZH_CN] || obj[EN_US] || obj[SurveyLocales.EN_US]
22
- || obj[ZH_TW] || obj[SurveyLocales.ZH_TW];
25
+ return (
26
+ obj[ZH_CN] ||
27
+ obj[SurveyLocales.ZH_CN] ||
28
+ obj[EN_US] ||
29
+ obj[SurveyLocales.EN_US] ||
30
+ obj[ZH_TW] ||
31
+ obj[SurveyLocales.ZH_TW]
32
+ );
23
33
  }
package/src/models.ts CHANGED
@@ -184,7 +184,7 @@ export class BaseQuestionModel {
184
184
  parseFloat(_.get(item, "options.score") || 0)
185
185
  );
186
186
  } else if (question.type == QuestionType.MATRIX) {
187
- let score = _.max(
187
+ const score = _.max(
188
188
  _.map(question.choices, (choice) =>
189
189
  parseFloat(_.get(choice, "options.score", 0) || 0)
190
190
  )
@@ -217,7 +217,7 @@ export class BaseQuestionModel {
217
217
 
218
218
  static calculationAllQuestionCount(questions): number {
219
219
  let count = 0;
220
- let exclude = [QuestionType.TEXT_TITLE];
220
+ const exclude = [QuestionType.TEXT_TITLE];
221
221
  _.forEach(questions, (question) => {
222
222
  if (!_.includes(exclude, question.type)) {
223
223
  count++;
@@ -346,7 +346,7 @@ export class QuestionMatrixModel extends BaseQuestionModel {
346
346
  preNumber: number,
347
347
  question: QuestionMatrixModel
348
348
  ): null | number {
349
- let number = preNumber + 1;
349
+ const number = preNumber + 1;
350
350
  _.forEach(question.subQuestions, (sq, index) => {
351
351
  sq.number = index + 1;
352
352
  });
@@ -1,90 +1,90 @@
1
1
  import {
2
- BaseQuestionModel,
3
- ChoiceModel,
4
- QuestionType,
5
- QuestionMatrixModel,
6
- QuestionTextTitleModel,
7
- QuestionCheckBoxModel,
8
- SubQuestionModel,
9
- QuestionEvaluationModel,
10
- StarEvaluationItemModel
2
+ BaseQuestionModel,
3
+ ChoiceModel,
4
+ QuestionType,
5
+ QuestionMatrixModel,
6
+ QuestionTextTitleModel,
7
+ QuestionCheckBoxModel,
8
+ SubQuestionModel,
9
+ QuestionEvaluationModel,
10
+ StarEvaluationItemModel,
11
11
  } from "./models";
12
12
  import _ from "lodash";
13
13
 
14
14
  interface HashTable<T> {
15
- [key: string]: T;
15
+ [key: string]: T;
16
16
  }
17
17
 
18
18
  export class QuestionFactory {
19
- private creatorHash: HashTable<(locale: string) => BaseQuestionModel> = {};
20
- private static instance: QuestionFactory;
21
- private locale: string;
19
+ private creatorHash: HashTable<(locale: string) => BaseQuestionModel> = {};
20
+ private static instance: QuestionFactory;
21
+ private locale: string;
22
22
 
23
- public static getInstance(locale: string): QuestionFactory {
24
- if (!QuestionFactory.instance) {
25
- QuestionFactory.instance = new QuestionFactory(locale);
26
- }
27
- return QuestionFactory.instance;
23
+ public static getInstance(locale: string): QuestionFactory {
24
+ if (!QuestionFactory.instance) {
25
+ QuestionFactory.instance = new QuestionFactory(locale);
28
26
  }
27
+ return QuestionFactory.instance;
28
+ }
29
29
 
30
- private constructor(locale: string) {
31
- this.locale = locale;
32
- this.registerQuestion(QuestionType.FILL_BLANK, (locale: string) => {
33
- return new BaseQuestionModel(QuestionType.FILL_BLANK, locale);
34
- });
35
- this.registerQuestion(QuestionType.SHORT_ANSWER, (locale: string) => {
36
- return new BaseQuestionModel(QuestionType.SHORT_ANSWER, locale);
37
- });
38
- this.registerQuestion(QuestionType.MATRIX, (locale: string) => {
39
- return new QuestionMatrixModel(QuestionType.MATRIX, locale);
40
- });
41
- this.registerQuestion(QuestionType.TEXT_TITLE, (locale: string) => {
42
- return new QuestionTextTitleModel(QuestionType.TEXT_TITLE, locale);
43
- });
44
- this.registerQuestion(QuestionType.SINGLE_SELECTION, (locale: string) => {
45
- return new QuestionCheckBoxModel(QuestionType.SINGLE_SELECTION, locale);
46
- });
47
- this.registerQuestion(QuestionType.MULTI_SELECTION, (locale: string) => {
48
- return new QuestionCheckBoxModel(QuestionType.MULTI_SELECTION, locale);
49
- });
50
- this.registerQuestion(QuestionType.EVALUATION, (locale: string) => {
51
- return new QuestionEvaluationModel(QuestionType.EVALUATION, locale);
52
- });
53
- }
30
+ private constructor(locale: string) {
31
+ this.locale = locale;
32
+ this.registerQuestion(QuestionType.FILL_BLANK, (locale: string) => {
33
+ return new BaseQuestionModel(QuestionType.FILL_BLANK, locale);
34
+ });
35
+ this.registerQuestion(QuestionType.SHORT_ANSWER, (locale: string) => {
36
+ return new BaseQuestionModel(QuestionType.SHORT_ANSWER, locale);
37
+ });
38
+ this.registerQuestion(QuestionType.MATRIX, (locale: string) => {
39
+ return new QuestionMatrixModel(QuestionType.MATRIX, locale);
40
+ });
41
+ this.registerQuestion(QuestionType.TEXT_TITLE, (locale: string) => {
42
+ return new QuestionTextTitleModel(QuestionType.TEXT_TITLE, locale);
43
+ });
44
+ this.registerQuestion(QuestionType.SINGLE_SELECTION, (locale: string) => {
45
+ return new QuestionCheckBoxModel(QuestionType.SINGLE_SELECTION, locale);
46
+ });
47
+ this.registerQuestion(QuestionType.MULTI_SELECTION, (locale: string) => {
48
+ return new QuestionCheckBoxModel(QuestionType.MULTI_SELECTION, locale);
49
+ });
50
+ this.registerQuestion(QuestionType.EVALUATION, (locale: string) => {
51
+ return new QuestionEvaluationModel(QuestionType.EVALUATION, locale);
52
+ });
53
+ }
54
54
 
55
- public static createDefault(locale: string): ChoiceModel {
56
- return new ChoiceModel(locale);
57
- }
55
+ public static createDefault(locale: string): ChoiceModel {
56
+ return new ChoiceModel(locale);
57
+ }
58
58
 
59
- public static createSubQuestion(locale: string): SubQuestionModel {
60
- return new SubQuestionModel(locale);
61
- }
59
+ public static createSubQuestion(locale: string): SubQuestionModel {
60
+ return new SubQuestionModel(locale);
61
+ }
62
62
 
63
- public static createEvaluationItem(locale: string): ChoiceModel {
64
- return new StarEvaluationItemModel(locale);
65
- }
63
+ public static createEvaluationItem(locale: string): ChoiceModel {
64
+ return new StarEvaluationItemModel(locale);
65
+ }
66
66
 
67
- public static createSelectionQuestionChoices(locale: string) {
68
- return _.range(4).map(() => this.createDefault(locale));
69
- }
67
+ public static createSelectionQuestionChoices(locale: string) {
68
+ return _.range(4).map(() => this.createDefault(locale));
69
+ }
70
70
 
71
- public static createMatrixQuestionChoices(locale: string) {
72
- return _.range(5).map(() => this.createDefault(locale));
73
- }
71
+ public static createMatrixQuestionChoices(locale: string) {
72
+ return _.range(5).map(() => this.createDefault(locale));
73
+ }
74
74
 
75
- public static createEvaluationItems(locale: string) {
76
- return _.range(5).map(() => this.createEvaluationItem(locale));
77
- }
75
+ public static createEvaluationItems(locale: string) {
76
+ return _.range(5).map(() => this.createEvaluationItem(locale));
77
+ }
78
78
 
79
- public registerQuestion(
80
- questionType: string,
81
- questionCreator: (locale: string) => BaseQuestionModel
82
- ) {
83
- this.creatorHash[questionType] = questionCreator;
84
- }
79
+ public registerQuestion(
80
+ questionType: string,
81
+ questionCreator: (locale: string) => BaseQuestionModel
82
+ ) {
83
+ this.creatorHash[questionType] = questionCreator;
84
+ }
85
85
 
86
- public createQuestion(questionType: string): BaseQuestionModel {
87
- let creator = this.creatorHash[questionType];
88
- return creator(this.locale);
89
- }
86
+ public createQuestion(questionType: string): BaseQuestionModel {
87
+ const creator = this.creatorHash[questionType];
88
+ return creator(this.locale);
89
+ }
90
90
  }