psytools 0.3.2 → 0.4.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/README.md +29 -15
- package/SOURCES.md +2 -0
- package/dist/cjs/assessment.d.ts +6 -4
- package/dist/cjs/assessment.js +10 -6
- package/dist/cjs/errors.d.ts +4 -2
- package/dist/cjs/evaluation.d.ts +10 -5
- package/dist/cjs/evaluation.js +68 -31
- package/dist/cjs/i18n.d.ts +1 -1
- package/dist/cjs/i18n.js +2 -2
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/inventories/aq10.js +35 -5
- package/dist/cjs/inventories/asrs6.js +28 -6
- package/dist/cjs/inventories/audit.js +107 -16
- package/dist/cjs/inventories/common.js +10 -0
- package/dist/cjs/inventories/dass21.js +75 -19
- package/dist/cjs/inventories/gad7.js +23 -5
- package/dist/cjs/inventories/mini-ipip.js +107 -9
- package/dist/cjs/inventories/phq9.js +30 -6
- package/dist/cjs/inventories/who5.js +31 -5
- package/dist/cjs/types.d.ts +30 -1
- package/dist/esm/assessment.d.ts +6 -4
- package/dist/esm/assessment.js +11 -7
- package/dist/esm/errors.d.ts +4 -2
- package/dist/esm/evaluation.d.ts +10 -5
- package/dist/esm/evaluation.js +68 -31
- package/dist/esm/i18n.d.ts +1 -1
- package/dist/esm/i18n.js +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/inventories/aq10.js +35 -5
- package/dist/esm/inventories/asrs6.js +28 -6
- package/dist/esm/inventories/audit.js +107 -16
- package/dist/esm/inventories/common.js +10 -0
- package/dist/esm/inventories/dass21.js +75 -19
- package/dist/esm/inventories/gad7.js +23 -5
- package/dist/esm/inventories/mini-ipip.js +107 -9
- package/dist/esm/inventories/phq9.js +30 -6
- package/dist/esm/inventories/who5.js +31 -5
- package/dist/esm/types.d.ts +30 -1
- package/package.json +1 -1
- package/schema/assessment-definition.schema.json +15 -3
- package/src/assessment.ts +15 -9
- package/src/errors.ts +25 -2
- package/src/evaluation.ts +103 -30
- package/src/i18n.ts +1 -1
- package/src/index.ts +6 -1
- package/src/inventories/aq10.ts +35 -5
- package/src/inventories/asrs6.ts +28 -6
- package/src/inventories/audit.ts +107 -16
- package/src/inventories/common.ts +10 -0
- package/src/inventories/dass21.ts +75 -19
- package/src/inventories/gad7.ts +23 -5
- package/src/inventories/mini-ipip.ts +107 -9
- package/src/inventories/phq9.ts +30 -6
- package/src/inventories/who5.ts +31 -5
- package/src/types.ts +38 -6
package/dist/cjs/types.d.ts
CHANGED
|
@@ -57,6 +57,28 @@ export interface ScoreFlag {
|
|
|
57
57
|
minValue: number;
|
|
58
58
|
label: LocalizedText;
|
|
59
59
|
}
|
|
60
|
+
/** How a scorer treats unanswered items among the ones it uses. */
|
|
61
|
+
export type MissingDataStrategy = "ignore" | "prorate" | "require-complete";
|
|
62
|
+
/**
|
|
63
|
+
* Missing-data policy for declarative scoring. Applies when incomplete
|
|
64
|
+
* answers reach the scorer (raw answer maps, or `allowIncomplete`).
|
|
65
|
+
*
|
|
66
|
+
* - `ignore` (default): unanswered items contribute nothing — partial
|
|
67
|
+
* totals understate severity, so use deliberately.
|
|
68
|
+
* - `prorate`: the raw score is scaled up by totalItems / answeredItems
|
|
69
|
+
* and rounded before any multiplier, per scale/subscale.
|
|
70
|
+
* - `require-complete`: evaluation throws `incomplete_response` when any
|
|
71
|
+
* contributing item is unanswered.
|
|
72
|
+
*/
|
|
73
|
+
export interface MissingDataPolicy {
|
|
74
|
+
strategy: MissingDataStrategy;
|
|
75
|
+
/**
|
|
76
|
+
* Minimum answered contributing items (per scale/subscale) needed to
|
|
77
|
+
* produce a score; below it evaluation throws `incomplete_response`.
|
|
78
|
+
* Defaults to 1 for `prorate`, 0 otherwise.
|
|
79
|
+
*/
|
|
80
|
+
minAnswered?: number;
|
|
81
|
+
}
|
|
60
82
|
/** Sums all answers into a single total score (PHQ-9, GAD-7, ...). */
|
|
61
83
|
export interface SumScoring {
|
|
62
84
|
kind: "sum";
|
|
@@ -65,6 +87,7 @@ export interface SumScoring {
|
|
|
65
87
|
/** Severity bands the (multiplied) total is matched against. */
|
|
66
88
|
bands?: ScoreBand[];
|
|
67
89
|
flags?: ScoreFlag[];
|
|
90
|
+
missing?: MissingDataPolicy;
|
|
68
91
|
}
|
|
69
92
|
/** One subscale of a multi-scale scoring definition. */
|
|
70
93
|
export interface SubscaleDefinition {
|
|
@@ -82,6 +105,8 @@ export interface SubscaleScoring {
|
|
|
82
105
|
kind: "subscales";
|
|
83
106
|
subscales: SubscaleDefinition[];
|
|
84
107
|
flags?: ScoreFlag[];
|
|
108
|
+
/** Applied to each subscale independently. */
|
|
109
|
+
missing?: MissingDataPolicy;
|
|
85
110
|
}
|
|
86
111
|
/** One item of a `count` scoring: when it counts as screen-positive. */
|
|
87
112
|
export interface CountScoringItem {
|
|
@@ -102,6 +127,8 @@ export interface CountScoring {
|
|
|
102
127
|
/** Bands the positive-item count is matched against. */
|
|
103
128
|
bands?: ScoreBand[];
|
|
104
129
|
flags?: ScoreFlag[];
|
|
130
|
+
/** `prorate` scales the positive count by totalItems / answeredItems. */
|
|
131
|
+
missing?: MissingDataPolicy;
|
|
105
132
|
}
|
|
106
133
|
/** Declarative, serializable scoring rules built into psytools. */
|
|
107
134
|
export type ScoringDefinition = SumScoring | SubscaleScoring | CountScoring;
|
|
@@ -156,9 +183,11 @@ export interface ResponseData {
|
|
|
156
183
|
submittedAt?: string;
|
|
157
184
|
meta?: Record<string, unknown>;
|
|
158
185
|
}
|
|
186
|
+
/** Codes a validation issue can carry (a subset of `PsytoolsErrorCode`). */
|
|
187
|
+
export type ValidationIssueCode = "unknown_question" | "invalid_value" | "missing_answer" | "duplicate_question" | "malformed";
|
|
159
188
|
/** A single validation problem. */
|
|
160
189
|
export interface ValidationIssue {
|
|
161
|
-
code:
|
|
190
|
+
code: ValidationIssueCode;
|
|
162
191
|
message: string;
|
|
163
192
|
questionId?: string;
|
|
164
193
|
}
|
package/dist/esm/assessment.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { AssessmentDefinition, AssessmentOption, AssessmentQuestion, EvaluationResult,
|
|
1
|
+
import type { AssessmentDefinition, AssessmentOption, AssessmentQuestion, EvaluationResult, LocalizedAssessmentView, ValidationResult } from "./types.ts";
|
|
2
2
|
import { AssessmentResponse } from "./response.ts";
|
|
3
|
+
import { type EvaluateOptions } from "./evaluation.ts";
|
|
3
4
|
/**
|
|
4
5
|
* Structurally validates an assessment definition (useful before persisting
|
|
5
6
|
* user-created assessments). Returns issues instead of throwing.
|
|
@@ -34,16 +35,17 @@ export declare class Assessment {
|
|
|
34
35
|
}): AssessmentResponse;
|
|
35
36
|
/**
|
|
36
37
|
* Evaluates a response (or raw answers) with the definition's declarative
|
|
37
|
-
* scoring, or with `evaluator` when provided.
|
|
38
|
+
* scoring, or with `options.evaluator` when provided.
|
|
38
39
|
*
|
|
39
40
|
* When given an `AssessmentResponse`, its status must be `complete` or
|
|
40
41
|
* `submitted` — pass `allowIncomplete` to score partial responses anyway.
|
|
41
42
|
* Raw answer maps skip the completeness check, but their values are
|
|
42
|
-
* still validated against the option scales
|
|
43
|
+
* still validated against the option scales, and the scoring definition's
|
|
44
|
+
* missing-data policy still applies.
|
|
43
45
|
*
|
|
44
46
|
* @throws PsytoolsError `incomplete_response` | `unknown_question` | `invalid_value` | `no_scoring`
|
|
45
47
|
*/
|
|
46
|
-
evaluate(response: AssessmentResponse | Record<string, number>,
|
|
48
|
+
evaluate(response: AssessmentResponse | Record<string, number>, options?: EvaluateOptions & {
|
|
47
49
|
allowIncomplete?: boolean;
|
|
48
50
|
}): EvaluationResult;
|
|
49
51
|
/** The plain serializable definition (used by `JSON.stringify`). */
|
package/dist/esm/assessment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PsytoolsError } from "./errors.js";
|
|
2
|
-
import { collectLocales,
|
|
2
|
+
import { collectLocales, localizeText } from "./i18n.js";
|
|
3
3
|
import { AssessmentResponse } from "./response.js";
|
|
4
4
|
import { evaluate } from "./evaluation.js";
|
|
5
5
|
/**
|
|
@@ -187,16 +187,20 @@ export class Assessment {
|
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
189
189
|
* Evaluates a response (or raw answers) with the definition's declarative
|
|
190
|
-
* scoring, or with `evaluator` when provided.
|
|
190
|
+
* scoring, or with `options.evaluator` when provided.
|
|
191
191
|
*
|
|
192
192
|
* When given an `AssessmentResponse`, its status must be `complete` or
|
|
193
193
|
* `submitted` — pass `allowIncomplete` to score partial responses anyway.
|
|
194
194
|
* Raw answer maps skip the completeness check, but their values are
|
|
195
|
-
* still validated against the option scales
|
|
195
|
+
* still validated against the option scales, and the scoring definition's
|
|
196
|
+
* missing-data policy still applies.
|
|
196
197
|
*
|
|
197
198
|
* @throws PsytoolsError `incomplete_response` | `unknown_question` | `invalid_value` | `no_scoring`
|
|
198
199
|
*/
|
|
199
|
-
evaluate(response,
|
|
200
|
+
evaluate(response, options) {
|
|
201
|
+
if (typeof options === "function") {
|
|
202
|
+
throw new PsytoolsError("invalid_argument", "Pass the evaluator as an option: assessment.evaluate(response, { evaluator })");
|
|
203
|
+
}
|
|
200
204
|
if (response instanceof AssessmentResponse) {
|
|
201
205
|
const scorable = response.status === "complete" || response.status === "submitted";
|
|
202
206
|
if (!scorable && !options?.allowIncomplete) {
|
|
@@ -204,9 +208,9 @@ export class Assessment {
|
|
|
204
208
|
throw new PsytoolsError("incomplete_response", `Cannot evaluate a response with status "${response.status}" (unanswered: ${missing}); ` +
|
|
205
209
|
"pass { allowIncomplete: true } to score it anyway");
|
|
206
210
|
}
|
|
207
|
-
return evaluate(this.definition, response.answers, evaluator);
|
|
211
|
+
return evaluate(this.definition, response.answers, { evaluator: options?.evaluator });
|
|
208
212
|
}
|
|
209
|
-
return evaluate(this.definition, response, evaluator);
|
|
213
|
+
return evaluate(this.definition, response, { evaluator: options?.evaluator });
|
|
210
214
|
}
|
|
211
215
|
/** The plain serializable definition (used by `JSON.stringify`). */
|
|
212
216
|
toJSON() {
|
|
@@ -233,6 +237,6 @@ export class Assessment {
|
|
|
233
237
|
return new Assessment(raw);
|
|
234
238
|
}
|
|
235
239
|
text(text, locale) {
|
|
236
|
-
return
|
|
240
|
+
return localizeText(text, locale ?? this.definition.defaultLocale, this.definition.defaultLocale);
|
|
237
241
|
}
|
|
238
242
|
}
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Every error code psytools can throw, for exhaustive handling. */
|
|
2
|
+
export type PsytoolsErrorCode = "malformed" | "duplicate_question" | "invalid_definition" | "unknown_question" | "invalid_value" | "missing_answer" | "already_submitted" | "invalid_response" | "incomplete_response" | "assessment_mismatch" | "no_scoring" | "invalid_json" | "unknown_inventory" | "invalid_argument";
|
|
1
3
|
/** Error thrown by psytools, carrying a stable machine-readable code. */
|
|
2
4
|
export declare class PsytoolsError extends Error {
|
|
3
|
-
readonly code:
|
|
4
|
-
constructor(code:
|
|
5
|
+
readonly code: PsytoolsErrorCode;
|
|
6
|
+
constructor(code: PsytoolsErrorCode, message: string);
|
|
5
7
|
}
|
package/dist/esm/evaluation.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { AnswerMap, AssessmentDefinition, EvaluationResult, Evaluator } from "./types.ts";
|
|
2
|
+
export interface EvaluateOptions {
|
|
3
|
+
/** Custom evaluator used instead of the definition's declarative scoring. */
|
|
4
|
+
evaluator?: Evaluator;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Evaluates answers against an assessment definition.
|
|
4
8
|
*
|
|
5
9
|
* Every answer is first validated against the assessment: the question must
|
|
6
|
-
* exist and the value must belong to its option scale. Then
|
|
7
|
-
* used when given; otherwise the definition's
|
|
8
|
-
* (`sum` or `
|
|
10
|
+
* exist and the value must belong to its option scale. Then
|
|
11
|
+
* `options.evaluator` is used when given; otherwise the definition's
|
|
12
|
+
* declarative `scoring` (`sum`, `subscales`, or `count`) applies, honoring
|
|
13
|
+
* its missing-data policy.
|
|
9
14
|
*
|
|
10
|
-
* @throws PsytoolsError `unknown_question` | `invalid_value` | `no_scoring`
|
|
15
|
+
* @throws PsytoolsError `unknown_question` | `invalid_value` | `incomplete_response` | `no_scoring`
|
|
11
16
|
*/
|
|
12
|
-
export declare function evaluate(definition: AssessmentDefinition, answers: AnswerMap,
|
|
17
|
+
export declare function evaluate(definition: AssessmentDefinition, answers: AnswerMap, options?: EvaluateOptions): EvaluationResult;
|
package/dist/esm/evaluation.js
CHANGED
|
@@ -3,16 +3,20 @@ import { PsytoolsError } from "./errors.js";
|
|
|
3
3
|
* Evaluates answers against an assessment definition.
|
|
4
4
|
*
|
|
5
5
|
* Every answer is first validated against the assessment: the question must
|
|
6
|
-
* exist and the value must belong to its option scale. Then
|
|
7
|
-
* used when given; otherwise the definition's
|
|
8
|
-
* (`sum` or `
|
|
6
|
+
* exist and the value must belong to its option scale. Then
|
|
7
|
+
* `options.evaluator` is used when given; otherwise the definition's
|
|
8
|
+
* declarative `scoring` (`sum`, `subscales`, or `count`) applies, honoring
|
|
9
|
+
* its missing-data policy.
|
|
9
10
|
*
|
|
10
|
-
* @throws PsytoolsError `unknown_question` | `invalid_value` | `no_scoring`
|
|
11
|
+
* @throws PsytoolsError `unknown_question` | `invalid_value` | `incomplete_response` | `no_scoring`
|
|
11
12
|
*/
|
|
12
|
-
export function evaluate(definition, answers,
|
|
13
|
+
export function evaluate(definition, answers, options) {
|
|
14
|
+
if (typeof options === "function") {
|
|
15
|
+
throw new PsytoolsError("invalid_argument", "Pass the evaluator as an option: evaluate(definition, answers, { evaluator })");
|
|
16
|
+
}
|
|
13
17
|
assertValidAnswers(definition, answers);
|
|
14
|
-
if (evaluator)
|
|
15
|
-
return evaluator(definition, answers);
|
|
18
|
+
if (options?.evaluator)
|
|
19
|
+
return options.evaluator(definition, answers);
|
|
16
20
|
const scoring = definition.scoring;
|
|
17
21
|
if (!scoring) {
|
|
18
22
|
throw new PsytoolsError("no_scoring", `Assessment "${definition.id}" has no scoring definition; pass a custom evaluator`);
|
|
@@ -21,19 +25,22 @@ export function evaluate(definition, answers, evaluator) {
|
|
|
21
25
|
case "sum":
|
|
22
26
|
return evaluateSum(definition, answers, scoring);
|
|
23
27
|
case "count": {
|
|
24
|
-
|
|
28
|
+
const questions = scoring.items.map((item) => requireQuestion(definition, item.questionId));
|
|
29
|
+
const answered = enforceMissing(questions, answers, scoring.missing);
|
|
30
|
+
let positives = 0;
|
|
25
31
|
for (const item of scoring.items) {
|
|
26
32
|
const question = requireQuestion(definition, item.questionId);
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
33
|
+
const value = answers[question.id];
|
|
34
|
+
if (value === undefined)
|
|
29
35
|
continue;
|
|
30
36
|
const values = (question.options ?? definition.options).map((o) => o.value);
|
|
31
37
|
const effective = question.reverseScored
|
|
32
|
-
? Math.max(...values) + Math.min(...values) -
|
|
33
|
-
:
|
|
38
|
+
? Math.max(...values) + Math.min(...values) - value
|
|
39
|
+
: value;
|
|
34
40
|
if (effective >= item.minValue)
|
|
35
|
-
|
|
41
|
+
positives += 1;
|
|
36
42
|
}
|
|
43
|
+
const score = prorate(positives, answered, questions.length, scoring.missing);
|
|
37
44
|
return {
|
|
38
45
|
kind: "scale",
|
|
39
46
|
score,
|
|
@@ -46,15 +53,12 @@ export function evaluate(definition, answers, evaluator) {
|
|
|
46
53
|
case "subscales": {
|
|
47
54
|
const scales = scoring.subscales.map((subscale) => {
|
|
48
55
|
const questions = subscale.questionIds.map((id) => requireQuestion(definition, id));
|
|
49
|
-
const
|
|
50
|
-
const { score, min, max } = sumQuestions(definition, questions, answers, multiplier);
|
|
56
|
+
const scored = scoreQuestionSet(definition, questions, answers, subscale.multiplier ?? 1, scoring.missing, subscale.id);
|
|
51
57
|
return {
|
|
52
58
|
id: subscale.id,
|
|
53
59
|
label: subscale.label,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
max,
|
|
57
|
-
...bandOf(score, subscale.bands),
|
|
60
|
+
...scored,
|
|
61
|
+
...bandOf(scored.score, subscale.bands),
|
|
58
62
|
};
|
|
59
63
|
});
|
|
60
64
|
return {
|
|
@@ -82,19 +86,21 @@ function assertValidAnswers(definition, answers) {
|
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
function evaluateSum(definition, answers, scoring) {
|
|
85
|
-
const
|
|
86
|
-
const { score, min, max } = sumQuestions(definition, definition.questions, answers, multiplier);
|
|
89
|
+
const result = scoreQuestionSet(definition, definition.questions, answers, scoring.multiplier ?? 1, scoring.missing);
|
|
87
90
|
return {
|
|
88
91
|
kind: "scale",
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
max,
|
|
92
|
-
...bandOf(score, scoring.bands),
|
|
92
|
+
...result,
|
|
93
|
+
...bandOf(result.score, scoring.bands),
|
|
93
94
|
flags: triggeredFlags(answers, scoring.flags),
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Sums one set of questions (the whole assessment or one subscale),
|
|
99
|
+
* applying reverse scoring, the missing-data policy, and the multiplier.
|
|
100
|
+
*/
|
|
101
|
+
function scoreQuestionSet(definition, questions, answers, multiplier, missing, scaleId) {
|
|
102
|
+
const answered = enforceMissing(questions, answers, missing, scaleId);
|
|
103
|
+
let raw = 0;
|
|
98
104
|
let min = 0;
|
|
99
105
|
let max = 0;
|
|
100
106
|
for (const question of questions) {
|
|
@@ -103,12 +109,43 @@ function sumQuestions(definition, questions, answers, multiplier) {
|
|
|
103
109
|
const highest = Math.max(...values);
|
|
104
110
|
min += lowest;
|
|
105
111
|
max += highest;
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
112
|
+
const value = answers[question.id];
|
|
113
|
+
if (value === undefined)
|
|
108
114
|
continue;
|
|
109
|
-
|
|
115
|
+
raw += question.reverseScored ? highest + lowest - value : value;
|
|
110
116
|
}
|
|
111
|
-
|
|
117
|
+
raw = prorate(raw, answered, questions.length, missing);
|
|
118
|
+
return { score: raw * multiplier, min: min * multiplier, max: max * multiplier };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Enforces the missing-data policy over one set of contributing questions
|
|
122
|
+
* and returns how many of them are answered.
|
|
123
|
+
*
|
|
124
|
+
* `require-complete` only demands questions that are not marked `optional`.
|
|
125
|
+
*/
|
|
126
|
+
function enforceMissing(questions, answers, missing, scaleId) {
|
|
127
|
+
const strategy = missing?.strategy ?? "ignore";
|
|
128
|
+
const minAnswered = missing?.minAnswered ?? (strategy === "prorate" ? 1 : 0);
|
|
129
|
+
const scope = scaleId ? ` in subscale "${scaleId}"` : "";
|
|
130
|
+
const answered = questions.filter((q) => answers[q.id] !== undefined).length;
|
|
131
|
+
if (strategy === "require-complete") {
|
|
132
|
+
const unanswered = questions
|
|
133
|
+
.filter((q) => !(q.optional ?? false) && answers[q.id] === undefined)
|
|
134
|
+
.map((q) => q.id);
|
|
135
|
+
if (unanswered.length > 0) {
|
|
136
|
+
throw new PsytoolsError("incomplete_response", `Scoring requires complete answers${scope}; unanswered: ${unanswered.join(", ")}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (answered < minAnswered) {
|
|
140
|
+
throw new PsytoolsError("incomplete_response", `Scoring requires at least ${minAnswered} answered item(s)${scope}, got ${answered}`);
|
|
141
|
+
}
|
|
142
|
+
return answered;
|
|
143
|
+
}
|
|
144
|
+
/** Scales a partial raw score up to the full item count (rounded). */
|
|
145
|
+
function prorate(raw, answered, total, missing) {
|
|
146
|
+
if (missing?.strategy !== "prorate" || answered === 0 || answered === total)
|
|
147
|
+
return raw;
|
|
148
|
+
return Math.round((raw * total) / answered);
|
|
112
149
|
}
|
|
113
150
|
function bandOf(score, bands) {
|
|
114
151
|
const match = bands?.find((band) => score >= band.min && score <= band.max);
|
package/dist/esm/i18n.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ import type { LocalizedText } from "./types.ts";
|
|
|
5
5
|
* Resolution order: exact locale -> base language of the locale
|
|
6
6
|
* (`"de-AT"` -> `"de"`) -> `fallbackLocale` -> first available entry.
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function localizeText(text: LocalizedText, locale: string, fallbackLocale?: string): string;
|
|
9
9
|
/** Collects the union of locales present in a set of localized texts. */
|
|
10
10
|
export declare function collectLocales(texts: Array<LocalizedText | undefined>): string[];
|
package/dist/esm/i18n.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Resolution order: exact locale -> base language of the locale
|
|
5
5
|
* (`"de-AT"` -> `"de"`) -> `fallbackLocale` -> first available entry.
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function localizeText(text, locale, fallbackLocale) {
|
|
8
8
|
const exact = text[locale];
|
|
9
9
|
if (exact !== undefined)
|
|
10
10
|
return exact;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export type { LocalizedText, AssessmentOption, AssessmentQuestion, AssessmentDefinition, ScoreBand, ScoreFlag, SumScoring, SubscaleDefinition, SubscaleScoring, CountScoringItem, CountScoring, ScoringDefinition, AnswerMap, ResponseStatus, ResponseData, ValidationIssue, ValidationResult, BandResult, TriggeredFlag, ScaleScore, ScaleResult, MultiScaleResult, CategoricalResult, CustomResult, EvaluationResult, Evaluator, LocalizedAssessmentView, } from "./types.ts";
|
|
1
|
+
export type { LocalizedText, AssessmentOption, AssessmentQuestion, AssessmentDefinition, ScoreBand, ScoreFlag, SumScoring, SubscaleDefinition, SubscaleScoring, CountScoringItem, CountScoring, MissingDataPolicy, MissingDataStrategy, ScoringDefinition, ValidationIssueCode, AnswerMap, ResponseStatus, ResponseData, ValidationIssue, ValidationResult, BandResult, TriggeredFlag, ScaleScore, ScaleResult, MultiScaleResult, CategoricalResult, CustomResult, EvaluationResult, Evaluator, LocalizedAssessmentView, } from "./types.ts";
|
|
2
2
|
export { PsytoolsError } from "./errors.ts";
|
|
3
|
-
export {
|
|
3
|
+
export type { PsytoolsErrorCode } from "./errors.ts";
|
|
4
|
+
export { localizeText, collectLocales } from "./i18n.ts";
|
|
4
5
|
export { Assessment, validateDefinition } from "./assessment.ts";
|
|
5
6
|
export { AssessmentResponse } from "./response.ts";
|
|
6
7
|
export { evaluate } from "./evaluation.ts";
|
|
8
|
+
export type { EvaluateOptions } from "./evaluation.ts";
|
|
7
9
|
export { phq9, gad7, dass21, who5, asrs6, aq10, audit, miniIpip, inventories, loadInventory, twoWeekFrequencyOptions, twoWeekInstructions, } from "./inventories/index.ts";
|
|
8
10
|
export type { InventoryId } from "./inventories/index.ts";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { PsytoolsError } from "./errors.js";
|
|
2
|
-
export {
|
|
2
|
+
export { localizeText, collectLocales } from "./i18n.js";
|
|
3
3
|
export { Assessment, validateDefinition } from "./assessment.js";
|
|
4
4
|
export { AssessmentResponse } from "./response.js";
|
|
5
5
|
export { evaluate } from "./evaluation.js";
|
|
@@ -15,34 +15,40 @@ export const aq10 = {
|
|
|
15
15
|
en: "Autism Spectrum Quotient (AQ-10) — Adult",
|
|
16
16
|
tr: "Otizm Spektrum Anketi (AQ-10) — Yetişkin",
|
|
17
17
|
de: "Autismus-Spektrum-Quotient (AQ-10) — Erwachsene",
|
|
18
|
+
zh: "自闭症谱系商数问卷(AQ-10)— 成人版",
|
|
19
|
+
es: "Cociente del Espectro Autista (AQ-10) — Adultos",
|
|
18
20
|
},
|
|
19
21
|
description: {
|
|
20
22
|
en: "A 10-item screening questionnaire for autistic traits in adults, condensed from the 50-item Autism Spectrum Quotient.",
|
|
21
23
|
tr: "50 maddelik Otizm Spektrum Anketi'nden kısaltılmış, yetişkinlerde otistik özellikleri taramak için 10 maddelik bir ölçek.",
|
|
22
24
|
de: "Ein 10-Item-Screeningfragebogen für autistische Merkmale bei Erwachsenen, verkürzt aus dem 50-Item-Autismus-Spektrum-Quotienten.",
|
|
25
|
+
zh: "一份用于筛查成人自闭症特质的10条目问卷,由50条目的自闭症谱系商数量表精简而成。",
|
|
26
|
+
es: "Un cuestionario de cribado de 10 ítems para rasgos autistas en adultos, condensado a partir del Cociente del Espectro Autista de 50 ítems.",
|
|
23
27
|
},
|
|
24
28
|
instructions: {
|
|
25
29
|
en: "For each statement, select the answer that best describes you.",
|
|
26
30
|
tr: "Her ifade için sizi en iyi tanımlayan yanıtı işaretleyin.",
|
|
27
31
|
de: "Wählen Sie zu jeder Aussage die Antwort, die Sie am besten beschreibt.",
|
|
32
|
+
zh: "请针对每条陈述,选择最符合您情况的答案。",
|
|
33
|
+
es: "Para cada afirmación, seleccione la respuesta que mejor lo describa.",
|
|
28
34
|
},
|
|
29
35
|
defaultLocale: "en",
|
|
30
36
|
options: [
|
|
31
37
|
{
|
|
32
38
|
value: 0,
|
|
33
|
-
label: { en: "Definitely disagree", tr: "Kesinlikle katılmıyorum", de: "Stimme überhaupt nicht zu" },
|
|
39
|
+
label: { en: "Definitely disagree", tr: "Kesinlikle katılmıyorum", de: "Stimme überhaupt nicht zu", zh: "完全不同意", es: "Totalmente en desacuerdo" },
|
|
34
40
|
},
|
|
35
41
|
{
|
|
36
42
|
value: 1,
|
|
37
|
-
label: { en: "Slightly disagree", tr: "Biraz katılmıyorum", de: "Stimme eher nicht zu" },
|
|
43
|
+
label: { en: "Slightly disagree", tr: "Biraz katılmıyorum", de: "Stimme eher nicht zu", zh: "有点不同意", es: "Ligeramente en desacuerdo" },
|
|
38
44
|
},
|
|
39
45
|
{
|
|
40
46
|
value: 2,
|
|
41
|
-
label: { en: "Slightly agree", tr: "Biraz katılıyorum", de: "Stimme eher zu" },
|
|
47
|
+
label: { en: "Slightly agree", tr: "Biraz katılıyorum", de: "Stimme eher zu", zh: "有点同意", es: "Ligeramente de acuerdo" },
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
50
|
value: 3,
|
|
45
|
-
label: { en: "Definitely agree", tr: "Kesinlikle katılıyorum", de: "Stimme voll und ganz zu" },
|
|
51
|
+
label: { en: "Definitely agree", tr: "Kesinlikle katılıyorum", de: "Stimme voll und ganz zu", zh: "完全同意", es: "Totalmente de acuerdo" },
|
|
46
52
|
},
|
|
47
53
|
],
|
|
48
54
|
questions: [
|
|
@@ -52,6 +58,8 @@ export const aq10 = {
|
|
|
52
58
|
en: "I often notice small sounds when others do not",
|
|
53
59
|
tr: "Başkalarının fark etmediği küçük sesleri sıklıkla fark ederim",
|
|
54
60
|
de: "Ich nehme oft leise Geräusche wahr, die andere nicht bemerken",
|
|
61
|
+
zh: "我经常注意到别人注意不到的微小声音",
|
|
62
|
+
es: "A menudo noto pequeños sonidos que otras personas no perciben",
|
|
55
63
|
},
|
|
56
64
|
},
|
|
57
65
|
{
|
|
@@ -60,6 +68,8 @@ export const aq10 = {
|
|
|
60
68
|
en: "I usually concentrate more on the whole picture, rather than the small details",
|
|
61
69
|
tr: "Genellikle küçük ayrıntılardan çok resmin bütününe odaklanırım",
|
|
62
70
|
de: "Ich konzentriere mich meist mehr auf das Gesamtbild als auf die kleinen Details",
|
|
71
|
+
zh: "我通常更关注事情的整体,而不是小细节",
|
|
72
|
+
es: "Normalmente me concentro más en la imagen global que en los pequeños detalles",
|
|
63
73
|
},
|
|
64
74
|
reverseScored: true,
|
|
65
75
|
},
|
|
@@ -69,6 +79,8 @@ export const aq10 = {
|
|
|
69
79
|
en: "I find it easy to do more than one thing at once",
|
|
70
80
|
tr: "Aynı anda birden fazla iş yapmak benim için kolaydır",
|
|
71
81
|
de: "Es fällt mir leicht, mehrere Dinge gleichzeitig zu tun",
|
|
82
|
+
zh: "我觉得同时做几件事情很容易",
|
|
83
|
+
es: "Me resulta fácil hacer más de una cosa a la vez",
|
|
72
84
|
},
|
|
73
85
|
reverseScored: true,
|
|
74
86
|
},
|
|
@@ -78,6 +90,8 @@ export const aq10 = {
|
|
|
78
90
|
en: "If there is an interruption, I can switch back to what I was doing very quickly",
|
|
79
91
|
tr: "Bir kesinti olursa, yapmakta olduğum işe çok hızlı bir şekilde geri dönebilirim",
|
|
80
92
|
de: "Wenn ich unterbrochen werde, kann ich sehr schnell zu meiner Tätigkeit zurückkehren",
|
|
93
|
+
zh: "如果被打断,我能很快回到原来正在做的事情上",
|
|
94
|
+
es: "Si hay una interrupción, puedo volver muy rápidamente a lo que estaba haciendo",
|
|
81
95
|
},
|
|
82
96
|
reverseScored: true,
|
|
83
97
|
},
|
|
@@ -87,6 +101,8 @@ export const aq10 = {
|
|
|
87
101
|
en: "I find it easy to 'read between the lines' when someone is talking to me",
|
|
88
102
|
tr: "Biri benimle konuşurken 'satır aralarını okumak' benim için kolaydır",
|
|
89
103
|
de: "Es fällt mir leicht, 'zwischen den Zeilen zu lesen', wenn jemand mit mir spricht",
|
|
104
|
+
zh: "当别人和我说话时,我觉得'听出言外之意'很容易",
|
|
105
|
+
es: "Me resulta fácil 'leer entre líneas' cuando alguien me está hablando",
|
|
90
106
|
},
|
|
91
107
|
reverseScored: true,
|
|
92
108
|
},
|
|
@@ -96,6 +112,8 @@ export const aq10 = {
|
|
|
96
112
|
en: "I know how to tell if someone listening to me is getting bored",
|
|
97
113
|
tr: "Beni dinleyen birinin sıkılmaya başladığını nasıl anlayacağımı bilirim",
|
|
98
114
|
de: "Ich erkenne, ob jemand, der mir zuhört, sich zu langweilen beginnt",
|
|
115
|
+
zh: "我知道如何判断听我说话的人是否开始感到厌烦",
|
|
116
|
+
es: "Sé darme cuenta de si la persona que me escucha se está aburriendo",
|
|
99
117
|
},
|
|
100
118
|
reverseScored: true,
|
|
101
119
|
},
|
|
@@ -105,6 +123,8 @@ export const aq10 = {
|
|
|
105
123
|
en: "When I'm reading a story I find it difficult to work out the characters' intentions",
|
|
106
124
|
tr: "Bir öykü okurken karakterlerin niyetlerini anlamakta zorlanırım",
|
|
107
125
|
de: "Wenn ich eine Geschichte lese, fällt es mir schwer, die Absichten der Figuren zu erkennen",
|
|
126
|
+
zh: "读故事时,我很难弄清人物的意图",
|
|
127
|
+
es: "Cuando leo una historia, me resulta difícil deducir las intenciones de los personajes",
|
|
108
128
|
},
|
|
109
129
|
},
|
|
110
130
|
{
|
|
@@ -113,6 +133,8 @@ export const aq10 = {
|
|
|
113
133
|
en: "I like to collect information about categories of things (e.g. types of car, types of bird, types of train, types of plant etc)",
|
|
114
134
|
tr: "Belirli kategorilerdeki şeyler hakkında bilgi toplamayı severim (örneğin araba türleri, kuş türleri, tren türleri, bitki türleri vb.)",
|
|
115
135
|
de: "Ich sammle gern Informationen über Kategorien von Dingen (z. B. Auto-, Vogel-, Zug- oder Pflanzenarten)",
|
|
136
|
+
zh: "我喜欢收集各类事物的信息(例如汽车的类型、鸟的种类、火车的类型、植物的种类等)",
|
|
137
|
+
es: "Me gusta recopilar información sobre categorías de cosas (p. ej., tipos de coches, de aves, de trenes, de plantas, etc.)",
|
|
116
138
|
},
|
|
117
139
|
},
|
|
118
140
|
{
|
|
@@ -121,6 +143,8 @@ export const aq10 = {
|
|
|
121
143
|
en: "I find it easy to work out what someone is thinking or feeling just by looking at their face",
|
|
122
144
|
tr: "Sadece yüzüne bakarak birinin ne düşündüğünü ya da hissettiğini anlamak benim için kolaydır",
|
|
123
145
|
de: "Es fällt mir leicht, allein am Gesicht abzulesen, was jemand denkt oder fühlt",
|
|
146
|
+
zh: "我觉得只看别人的脸就能轻松看出对方在想什么或有什么感受",
|
|
147
|
+
es: "Me resulta fácil deducir lo que alguien piensa o siente con solo mirarle la cara",
|
|
124
148
|
},
|
|
125
149
|
reverseScored: true,
|
|
126
150
|
},
|
|
@@ -130,6 +154,8 @@ export const aq10 = {
|
|
|
130
154
|
en: "I find it difficult to work out people's intentions",
|
|
131
155
|
tr: "İnsanların niyetlerini anlamakta zorlanırım",
|
|
132
156
|
de: "Es fällt mir schwer, die Absichten anderer Menschen zu erkennen",
|
|
157
|
+
zh: "我很难弄清别人的意图",
|
|
158
|
+
es: "Me resulta difícil deducir las intenciones de las personas",
|
|
133
159
|
},
|
|
134
160
|
},
|
|
135
161
|
],
|
|
@@ -156,6 +182,8 @@ export const aq10 = {
|
|
|
156
182
|
en: "Below screening threshold",
|
|
157
183
|
tr: "Tarama eşiğinin altında",
|
|
158
184
|
de: "Unterhalb der Screening-Schwelle",
|
|
185
|
+
zh: "低于筛查阈值",
|
|
186
|
+
es: "Por debajo del umbral de cribado",
|
|
159
187
|
},
|
|
160
188
|
},
|
|
161
189
|
{
|
|
@@ -166,6 +194,8 @@ export const aq10 = {
|
|
|
166
194
|
en: "At or above threshold — consider referral for a specialist autism assessment",
|
|
167
195
|
tr: "Eşikte ya da üzerinde — uzman otizm değerlendirmesine yönlendirme düşünülmelidir",
|
|
168
196
|
de: "An oder über der Schwelle — Überweisung zu einer spezialisierten Autismus-Diagnostik erwägen",
|
|
197
|
+
zh: "达到或超过阈值——建议考虑转介进行自闭症专科评估",
|
|
198
|
+
es: "En el umbral o por encima — considere la derivación para una evaluación especializada de autismo",
|
|
169
199
|
},
|
|
170
200
|
},
|
|
171
201
|
],
|
|
@@ -174,7 +204,7 @@ export const aq10 = {
|
|
|
174
204
|
reference: "Allison, C., Auyeung, B., & Baron-Cohen, S. (2012). Toward brief \"Red Flags\" for autism screening: The Short Autism Spectrum Quotient and the Short Quantitative Checklist in 1,000 cases and 3,000 controls. Journal of the American Academy of Child & Adolescent Psychiatry, 51(2), 202-212.",
|
|
175
205
|
license: "Free with conditions — (c) Autism Research Centre, University of Cambridge; distributed free of charge, NICE-recommended for clinical screening. Verify licensing with ARC before embedding in commercial products.",
|
|
176
206
|
licenseFlag: "free-with-conditions",
|
|
177
|
-
translationProvenance: "en: reproduced from the original. tr
|
|
207
|
+
translationProvenance: "en: reproduced from the original. Other locales (tr, de, zh, es): AI translation (Anthropic Claude, claude-fable-5) from the original English; official translations were not consulted and the texts are unverified. See SOURCES.md.",
|
|
178
208
|
note: "Each item scores 1 point in the trait direction; disagree-scored items are modeled as reverseScored.",
|
|
179
209
|
},
|
|
180
210
|
};
|