skewer-format 1.0.0 → 1.2.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/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { lexer } from "./src/lexer";
2
2
  export { parser } from "./src/parser";
3
+ export { skewerToJSON } from "./src/methods";
4
+ export { type Question, type QuestionSet } from "./src/interface";
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parser = exports.lexer = void 0;
4
- var lexer_1 = require("./src/lexer");
5
- Object.defineProperty(exports, "lexer", { enumerable: true, get: function () { return lexer_1.lexer; } });
6
- var parser_1 = require("./src/parser");
7
- Object.defineProperty(exports, "parser", { enumerable: true, get: function () { return parser_1.parser; } });
1
+ export { lexer } from "./src/lexer";
2
+ export { parser } from "./src/parser";
3
+ export { skewerToJSON } from "./src/methods";
@@ -0,0 +1,17 @@
1
+ export interface Question {
2
+ id?: string;
3
+ type?: string;
4
+ question?: string;
5
+ options?: {
6
+ key: string;
7
+ value: string;
8
+ }[];
9
+ answer?: string | Array<string>;
10
+ explanation?: string;
11
+ }
12
+ export interface QuestionSet {
13
+ id: string;
14
+ type: string;
15
+ para: string;
16
+ questions: Array<Question>;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/src/lexer.js CHANGED
@@ -1,26 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lexer = lexer;
4
- function lexer(input) {
1
+ export function lexer(input) {
5
2
  const tokens = [];
6
3
  const lines = input
7
4
  .split("\n")
8
- .map(line => line.trim())
5
+ .map((line) => line.trim())
9
6
  .filter(Boolean);
10
7
  for (const line of lines) {
11
8
  const optionMatch = line.match(/^([A-Z])\.\s*(.+)$/);
12
9
  if (optionMatch) {
13
10
  tokens.push({
14
11
  type: "OPTION_KEY",
15
- value: optionMatch[1]
12
+ value: optionMatch[1],
16
13
  });
17
14
  tokens.push({
18
15
  type: "DOT",
19
- value: "."
16
+ value: ".",
20
17
  });
21
18
  tokens.push({
22
19
  type: "OPTION_VALUE",
23
- value: optionMatch[2]
20
+ value: optionMatch[2],
24
21
  });
25
22
  continue;
26
23
  }
@@ -28,47 +25,25 @@ function lexer(input) {
28
25
  if (keyValueMatch) {
29
26
  tokens.push({
30
27
  type: "KEY",
31
- value: keyValueMatch[1]
28
+ value: keyValueMatch[1],
32
29
  });
33
30
  tokens.push({
34
31
  type: "COLON",
35
- value: ":"
32
+ value: ":",
36
33
  });
37
34
  tokens.push({
38
35
  type: "VALUE",
39
- value: keyValueMatch[2]
36
+ value: keyValueMatch[2],
40
37
  });
41
38
  }
42
39
  const sentinalMatch = line.match(/^---$/m);
43
40
  if (sentinalMatch) {
44
41
  tokens.push({
45
42
  type: "SENTINEL",
46
- value: "---"
43
+ value: "---",
47
44
  });
48
45
  continue;
49
46
  }
50
47
  }
51
48
  return tokens;
52
49
  }
53
- const input = `
54
-
55
- ---
56
- QUESTION: Which of the following best describes the primary purpose of a preloader in web design?
57
- A. To enhance the visual aesthetics of the website
58
- B. To ensure faster actual loading times of the website
59
- C. To create the perception of faster loading times through engaging animations or progress indicators
60
- D. To provide additional information about the website's content
61
- ANSWER: C
62
- EXPLANATION: Preloaders are used to create the perception of faster loading times, engaging users with animations or progress indicators while the website content loads in the background.
63
-
64
- ---
65
- QUESTION: In the context of web design, what does SVG stand for and what is its primary use?
66
- A. Scalable Vector Graphics, used for defining three-dimensional graphics
67
- B. Simple Vector Graphics, used for creating basic two-dimensional images
68
- C. Scalable Vector Graphics, used for defining two-dimensional graphics with interactivity and animation support
69
- D. Standard Vector Graphics, used for standardizing image formats across different platforms
70
- ANSWER: C
71
- EXPLANATION: SVG stands for Scalable Vector Graphics, an XML-based vector image format for two-dimensional graphics with support for interactivity and animation.
72
-
73
- ---
74
- `;
@@ -0,0 +1,2 @@
1
+ import { type Question, type QuestionSet } from "./interface";
2
+ export declare function skewerToJSON(input: string): Array<Question | QuestionSet>;
@@ -0,0 +1,5 @@
1
+ import { lexer } from "./lexer";
2
+ import { parser } from "./parser";
3
+ export function skewerToJSON(input) {
4
+ return parser(lexer(input));
5
+ }
@@ -1,20 +1,3 @@
1
1
  import type { Token } from "./lexer.js";
2
- interface Question {
3
- id?: string;
4
- type?: string;
5
- question?: string;
6
- options?: {
7
- key: string;
8
- value: string;
9
- }[];
10
- answer?: string | Array<string>;
11
- explanation?: string;
12
- }
13
- interface QuestionSet {
14
- id: string;
15
- type: string;
16
- para: string;
17
- questions: Array<Question>;
18
- }
2
+ import { type Question, type QuestionSet } from "./interface";
19
3
  export declare function parser(tokens: Token[]): Array<Question | QuestionSet>;
20
- export {};
@@ -1,19 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parser = parser;
4
- const lexer_js_1 = require("./lexer.js");
5
- function parser(tokens) {
6
- var _a;
1
+ import { lexer } from "./lexer.js";
2
+ export function parser(tokens) {
7
3
  const resultArr = [];
8
4
  let question = {
9
- options: []
5
+ options: [],
10
6
  };
11
7
  let sentinel = "close";
12
- let currentType;
8
+ // let currentType: string;
13
9
  let i = 0;
14
10
  function resetQuestion() {
15
11
  question = {
16
- options: []
12
+ options: [],
17
13
  };
18
14
  }
19
15
  while (i < tokens.length) {
@@ -32,7 +28,7 @@ function parser(tokens) {
32
28
  switch (key) {
33
29
  case "TYPE":
34
30
  question.type = valueToken.value;
35
- currentType = valueToken.value;
31
+ // currentType = valueToken.value;
36
32
  break;
37
33
  case "QUESTION":
38
34
  if (sentinel === "open") {
@@ -52,7 +48,8 @@ function parser(tokens) {
52
48
  else {
53
49
  question.answer = valueToken.value;
54
50
  }
55
- if (question.answer.length == 1 && question.type == undefined) {
51
+ if (question.answer.length == 1 &&
52
+ question.type == undefined) {
56
53
  question.type = "MCQ";
57
54
  }
58
55
  break;
@@ -66,11 +63,10 @@ function parser(tokens) {
66
63
  }
67
64
  if (token.type == "OPTION_KEY") {
68
65
  const optionValueToken = tokens[i + 2];
69
- if (optionValueToken &&
70
- optionValueToken.type === "OPTION_VALUE") {
71
- (_a = question.options) === null || _a === void 0 ? void 0 : _a.push({
66
+ if (optionValueToken && optionValueToken.type === "OPTION_VALUE") {
67
+ question.options?.push({
72
68
  key: token.value,
73
- value: optionValueToken.value
69
+ value: optionValueToken.value,
74
70
  });
75
71
  i += 3;
76
72
  continue;
@@ -136,6 +132,6 @@ ANSWER: B
136
132
  EXPLANATION: Serif fonts are often chosen for their historical significance and readability, making them a popular choice for body text in web design to ensure clarity and ease of reading.
137
133
 
138
134
  ---`;
139
- let lex_out = (0, lexer_js_1.lexer)(input);
135
+ const lex_out = lexer(input);
140
136
  // console.log(lex_out);
141
137
  console.log(parser(lex_out));
@@ -0,0 +1 @@
1
+ {"root":["../index.ts","../src/interface.ts","../src/lexer.ts","../src/methods.ts","../src/parser.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "skewer-format",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "New format to store quiz in text format",
5
5
  "license": "MIT",
6
6
  "author": "sassykumar <sasikumarstu@gamil.com>",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
- "type": "commonjs",
10
+ "type": "module",
11
11
  "main": "dist/index.js",
12
12
  "scripts": {
13
13
  "dev": "vite",
14
- "build": "tsc -b && vite build",
14
+ "build": "tsc -b ",
15
15
  "lint": "eslint .",
16
16
  "preview": "vite preview",
17
17
  "prepare": "husky"
@@ -42,11 +42,7 @@
42
42
  "vite": "^8.0.0"
43
43
  },
44
44
  "lint-staged": {
45
- "*.{js,ts,tsx,json,css,md}": [
46
- "prettier --write"
47
- ],
48
- "*.{js,ts,tsx}": [
49
- "eslint --fix --max-warnings=10"
50
- ]
45
+ "*.{js,ts,tsx,json,css,md}": "prettier --write",
46
+ "*.{js,ts,tsx}": "eslint --fix --max-warnings=10"
51
47
  }
52
48
  }