@drodil/backstage-plugin-qeta-common 2.5.3 → 2.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/dist/index.cjs.js CHANGED
@@ -30,10 +30,27 @@ const filterTags = (input) => {
30
30
  );
31
31
  };
32
32
 
33
+ const truncate = (str, n) => {
34
+ return str.length > n ? `${str.slice(0, n - 1)}...` : str;
35
+ };
36
+ const removeMarkdownFormatting = (text) => {
37
+ let fixed = text.replace(/^(-\s*?|\*\s*?|_\s*?){3,}\s*/gm, "");
38
+ fixed = text.replace(/<[^>]*>/g, "");
39
+ fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
40
+ return match.replace(/(^```[a-z]*\n)|(```$)/g, "").trim();
41
+ });
42
+ fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, "$1");
43
+ fixed = fixed.replace(/(?:\*\*|__)([^\n*]+)(?:\*\*|__)/g, "$1").replace(/(?:\*|_)([^\n*]+)(?:\*|_)/g, "$1").replace(/(?:~~)([^~]+)(?:~~)/g, "$1").replace(/^[>\t]{0,3}>+\s?/gm, "").replace(/\[\^.+?\](: .*?$)?/g, "").replace(/^([ \t]*)([*\-+]|\d+\.)\s+/gm, "").replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/^#{1,6}[ \t]+/gm, "").replace(/^[=-]{2,}\s*$/g, "").replace(/(?:\r\n|\r|\n)/g, " ").replace(/(^\s+|\s+$)/g, "");
44
+ fixed = fixed.replace(/<[^>]*>/g, "");
45
+ return fixed;
46
+ };
47
+
33
48
  exports.TAGS_REGEX = TAGS_REGEX;
34
49
  exports.filterTags = filterTags;
35
50
  exports.qetaCreateAnswerPermission = qetaCreateAnswerPermission;
36
51
  exports.qetaCreateQuestionPermission = qetaCreateQuestionPermission;
37
52
  exports.qetaPermissions = qetaPermissions;
38
53
  exports.qetaReadPermission = qetaReadPermission;
54
+ exports.removeMarkdownFormatting = removeMarkdownFormatting;
55
+ exports.truncate = truncate;
39
56
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/permissions.ts","../src/tags.ts"],"sourcesContent":["import { createPermission } from '@backstage/plugin-permission-common';\n\nexport const qetaReadPermission = createPermission({\n name: 'qeta.read',\n attributes: { action: 'create' },\n});\n\nexport const qetaCreateQuestionPermission = createPermission({\n name: 'qeta.create.question',\n attributes: { action: 'create' },\n});\n\nexport const qetaCreateAnswerPermission = createPermission({\n name: 'qeta.create.answer',\n attributes: { action: 'create' },\n});\n\nexport const qetaPermissions = [\n qetaReadPermission,\n qetaCreateQuestionPermission,\n qetaCreateAnswerPermission,\n];\n","export const TAGS_REGEX = new RegExp('^[a-z0-9+#]+((\\\\-|_)[a-z0-9+#_]+)*$');\n\nexport const filterTags = (input?: null | string | string[]) => {\n if (!input) {\n return undefined;\n }\n return (Array.isArray(input) ? input : input.split(',')).filter(\n v => v.length > 0 && v.length < 255 && TAGS_REGEX.test(v),\n );\n};\n"],"names":["createPermission"],"mappings":";;;;AAEO,MAAM,qBAAqBA,uCAAiB,CAAA;AAAA,EACjD,IAAM,EAAA,WAAA;AAAA,EACN,UAAA,EAAY,EAAE,MAAA,EAAQ,QAAS,EAAA;AACjC,CAAC,EAAA;AAEM,MAAM,+BAA+BA,uCAAiB,CAAA;AAAA,EAC3D,IAAM,EAAA,sBAAA;AAAA,EACN,UAAA,EAAY,EAAE,MAAA,EAAQ,QAAS,EAAA;AACjC,CAAC,EAAA;AAEM,MAAM,6BAA6BA,uCAAiB,CAAA;AAAA,EACzD,IAAM,EAAA,oBAAA;AAAA,EACN,UAAA,EAAY,EAAE,MAAA,EAAQ,QAAS,EAAA;AACjC,CAAC,EAAA;AAEM,MAAM,eAAkB,GAAA;AAAA,EAC7B,kBAAA;AAAA,EACA,4BAAA;AAAA,EACA,0BAAA;AACF;;ACrBa,MAAA,UAAA,GAAa,IAAI,MAAA,CAAO,qCAAqC,EAAA;AAE7D,MAAA,UAAA,GAAa,CAAC,KAAqC,KAAA;AAC9D,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAQ,OAAA,CAAA,KAAA,CAAM,QAAQ,KAAK,CAAA,GAAI,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,CAAG,EAAA,MAAA;AAAA,IACvD,CAAA,CAAA,KAAK,EAAE,MAAS,GAAA,CAAA,IAAK,EAAE,MAAS,GAAA,GAAA,IAAO,UAAW,CAAA,IAAA,CAAK,CAAC,CAAA;AAAA,GAC1D,CAAA;AACF;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/permissions.ts","../src/tags.ts","../src/utils.ts"],"sourcesContent":["import { createPermission } from '@backstage/plugin-permission-common';\n\nexport const qetaReadPermission = createPermission({\n name: 'qeta.read',\n attributes: { action: 'create' },\n});\n\nexport const qetaCreateQuestionPermission = createPermission({\n name: 'qeta.create.question',\n attributes: { action: 'create' },\n});\n\nexport const qetaCreateAnswerPermission = createPermission({\n name: 'qeta.create.answer',\n attributes: { action: 'create' },\n});\n\nexport const qetaPermissions = [\n qetaReadPermission,\n qetaCreateQuestionPermission,\n qetaCreateAnswerPermission,\n];\n","export const TAGS_REGEX = new RegExp('^[a-z0-9+#]+((\\\\-|_)[a-z0-9+#_]+)*$');\n\nexport const filterTags = (input?: null | string | string[]) => {\n if (!input) {\n return undefined;\n }\n return (Array.isArray(input) ? input : input.split(',')).filter(\n v => v.length > 0 && v.length < 255 && TAGS_REGEX.test(v),\n );\n};\n","export const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove horizontal rules\n let fixed = text.replace(/^(-\\s*?|\\*\\s*?|_\\s*?){3,}\\s*/gm, '');\n\n // Remove HTML tags\n fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":["createPermission"],"mappings":";;;;AAEO,MAAM,qBAAqBA,uCAAiB,CAAA;AAAA,EACjD,IAAM,EAAA,WAAA;AAAA,EACN,UAAA,EAAY,EAAE,MAAA,EAAQ,QAAS,EAAA;AACjC,CAAC,EAAA;AAEM,MAAM,+BAA+BA,uCAAiB,CAAA;AAAA,EAC3D,IAAM,EAAA,sBAAA;AAAA,EACN,UAAA,EAAY,EAAE,MAAA,EAAQ,QAAS,EAAA;AACjC,CAAC,EAAA;AAEM,MAAM,6BAA6BA,uCAAiB,CAAA;AAAA,EACzD,IA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K,EAAA,CAAA;AAAA,GACzD,CAAA,CAAA;AAGD,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,sBAAA,EAAwB,IAAI,CAAA,CAAA;AAGlD,EAAQ,KAAA,GAAA,KAAA,CACL,QAAQ,kCAAoC,EAAA,IAAI,EAChD,OAAQ,CAAA,4BAAA,EAA8B,IAAI,CAC1C,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA,CACpC,QAAQ,oBAAsB,EAAA,EAAE,EAChC,OAAQ,CAAA,qBAAA,EAAuB,EAAE,CAAA,CACjC,OAAQ,CAAA,8BAAA,EAAgC,EAAE,CAC1C,CAAA,OAAA,CAAQ,2BAA2B,IAAI,CAAA,CACvC,QAAQ,wBAA0B,EAAA,IAAI,CACtC,CAAA,OAAA,CAAQ,iBAAmB,EAAA,EAAE,EAC7B,OAAQ,CAAA,gBAAA,EAAkB,EAAE,CAC5B,CAAA,OAAA,CAAQ,mBAAmB,GAAG,CAAA,CAC9B,OAAQ,CAAA,cAAA,EAAgB,EAAE,CAAA,CAAA;AAG7B,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAEpC,EAAO,OAAA,KAAA,CAAA;AACT;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -146,4 +146,7 @@ type QetaSignal = QetaQuestionStatsSignal | QetaAnswerStatsSignal;
146
146
  declare const TAGS_REGEX: RegExp;
147
147
  declare const filterTags: (input?: null | string | string[]) => string[] | undefined;
148
148
 
149
- export { type Answer, type AnswerRequest, type AnswerResponse, type AnswerResponseBody, type AnswersResponse, type AnswersResponseBody, type Attachment, type AttachmentResponseBody, type Comment, type EntityResponse, type QetaAnswerStatsSignal, type QetaDocument, type QetaEntity, type QetaQuestionStatsSignal, type QetaSignal, type Question, type QuestionAnswerEntity, type QuestionRequest, type QuestionResponse, type QuestionResponseBody, type QuestionsResponse, type QuestionsResponseBody, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, TAGS_REGEX, type TagResponse, type Vote, filterTags, qetaCreateAnswerPermission, qetaCreateQuestionPermission, qetaPermissions, qetaReadPermission };
149
+ declare const truncate: (str: string, n: number) => string;
150
+ declare const removeMarkdownFormatting: (text: string) => string;
151
+
152
+ export { type Answer, type AnswerRequest, type AnswerResponse, type AnswerResponseBody, type AnswersResponse, type AnswersResponseBody, type Attachment, type AttachmentResponseBody, type Comment, type EntityResponse, type QetaAnswerStatsSignal, type QetaDocument, type QetaEntity, type QetaQuestionStatsSignal, type QetaSignal, type Question, type QuestionAnswerEntity, type QuestionRequest, type QuestionResponse, type QuestionResponseBody, type QuestionsResponse, type QuestionsResponseBody, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, TAGS_REGEX, type TagResponse, type Vote, filterTags, qetaCreateAnswerPermission, qetaCreateQuestionPermission, qetaPermissions, qetaReadPermission, removeMarkdownFormatting, truncate };
package/dist/index.esm.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { qetaCreateAnswerPermission, qetaCreateQuestionPermission, qetaPermissions, qetaReadPermission } from './permissions.esm.js';
2
2
  export { TAGS_REGEX, filterTags } from './tags.esm.js';
3
+ export { removeMarkdownFormatting, truncate } from './utils.esm.js';
3
4
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,17 @@
1
+ const truncate = (str, n) => {
2
+ return str.length > n ? `${str.slice(0, n - 1)}...` : str;
3
+ };
4
+ const removeMarkdownFormatting = (text) => {
5
+ let fixed = text.replace(/^(-\s*?|\*\s*?|_\s*?){3,}\s*/gm, "");
6
+ fixed = text.replace(/<[^>]*>/g, "");
7
+ fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
8
+ return match.replace(/(^```[a-z]*\n)|(```$)/g, "").trim();
9
+ });
10
+ fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, "$1");
11
+ fixed = fixed.replace(/(?:\*\*|__)([^\n*]+)(?:\*\*|__)/g, "$1").replace(/(?:\*|_)([^\n*]+)(?:\*|_)/g, "$1").replace(/(?:~~)([^~]+)(?:~~)/g, "$1").replace(/^[>\t]{0,3}>+\s?/gm, "").replace(/\[\^.+?\](: .*?$)?/g, "").replace(/^([ \t]*)([*\-+]|\d+\.)\s+/gm, "").replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/^#{1,6}[ \t]+/gm, "").replace(/^[=-]{2,}\s*$/g, "").replace(/(?:\r\n|\r|\n)/g, " ").replace(/(^\s+|\s+$)/g, "");
12
+ fixed = fixed.replace(/<[^>]*>/g, "");
13
+ return fixed;
14
+ };
15
+
16
+ export { removeMarkdownFormatting, truncate };
17
+ //# sourceMappingURL=utils.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.esm.js","sources":["../src/utils.ts"],"sourcesContent":["export const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove horizontal rules\n let fixed = text.replace(/^(-\\s*?|\\*\\s*?|_\\s*?){3,}\\s*/gm, '');\n\n // Remove HTML tags\n fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":[],"mappings":"AAAa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB,KAAA;AAC1D,EAAO,OAAA,GAAA,CAAI,MAAS,GAAA,CAAA,GAAI,CAAG,EAAA,GAAA,CAAI,MAAM,CAAG,EAAA,CAAA,GAAI,CAAC,CAAC,CAAQ,GAAA,CAAA,GAAA,GAAA,CAAA;AACxD,EAAA;AAGa,MAAA,wBAAA,GAA2B,CAAC,IAAyB,KAAA;AAEhE,EAAA,IAAI,KAAQ,GAAA,IAAA,CAAK,OAAQ,CAAA,gCAAA,EAAkC,EAAE,CAAA,CAAA;AAG7D,EAAQ,KAAA,GAAA,IAAA,CAAK,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAGnC,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,iBAAA,EAAmB,CAAS,KAAA,KAAA;AAChD,IAAA,OAAO,KAAM,CAAA,OAAA,CAAQ,wBAA0B,EAAA,EAAE,EAAE,IAAK,EAAA,CAAA;AAAA,GACzD,CAAA,CAAA;AAGD,EAAQ,KAAA,GAAA,KAAA,CAAM,OA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