@salesforcedevs/dx-components 0.61.1 → 0.63.0-alpha.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/package.json +2 -3
- package/src/modules/dx/codeBlock/codeBlock.ts +13 -0
- package/src/modules/dx/footer/footer.html +23 -16
- package/src/modules/dx/footer/footer.ts +19 -15
- package/src/modules/dx/footer/links.ts +104 -38
- package/src/modules/dxUtils/codeLanguageDetector/codeLanguageDetector.ts +81 -0
- package/src/modules/dxUtils/codeLanguageDetector/languageList.ts +345 -0
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0-alpha.0",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -24,6 +24,5 @@
|
|
|
24
24
|
"@types/debounce": "^1.2.0",
|
|
25
25
|
"@types/lodash.get": "^4.4.6",
|
|
26
26
|
"@types/vimeo__player": "^2.16.2"
|
|
27
|
-
}
|
|
28
|
-
"gitHead": "6e9bf005600ca7a99a22b99cf5d5e0618590d9ce"
|
|
27
|
+
}
|
|
29
28
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LightningElement, api, wire, track } from "lwc";
|
|
2
2
|
import { CodeBlockTheme, CodeBlockLanguage } from "typings/custom";
|
|
3
3
|
import cx from "classnames";
|
|
4
|
+
import { detect } from "dxUtils/codeLanguageDetector";
|
|
4
5
|
import Prism from "dxUtils/prismjs";
|
|
5
6
|
import {
|
|
6
7
|
getLocalStorageData,
|
|
@@ -212,6 +213,18 @@ export default class CodeBlock extends LightningElement {
|
|
|
212
213
|
) || this.allLanguages[0];
|
|
213
214
|
this.selectedLanguageLabel = this.selectedLanguage.label;
|
|
214
215
|
this.selectedLanguageId = this.selectedLanguage.id;
|
|
216
|
+
|
|
217
|
+
// Auto detect code language if it isn't specified
|
|
218
|
+
if (!this.language) {
|
|
219
|
+
const detectedLanguage = detect(this.codeBlock);
|
|
220
|
+
this.selectedLanguage = {
|
|
221
|
+
label: detectedLanguage,
|
|
222
|
+
id: detectedLanguage.toLowerCase()
|
|
223
|
+
};
|
|
224
|
+
this.selectedLanguageLabel = detectedLanguage;
|
|
225
|
+
this.selectedLanguageId = detectedLanguage.toLowerCase();
|
|
226
|
+
}
|
|
227
|
+
|
|
215
228
|
this.formatCodeBlock();
|
|
216
229
|
this._codeBlockRendered = true;
|
|
217
230
|
}
|
|
@@ -103,17 +103,17 @@
|
|
|
103
103
|
</dx-button>
|
|
104
104
|
</dx-dropdown>
|
|
105
105
|
<div class="general">
|
|
106
|
-
<template for:each={generalLinks} for:item="
|
|
107
|
-
<div class="footer-group" key={
|
|
108
|
-
<h2 class="subheading">{
|
|
109
|
-
<template for:each={
|
|
106
|
+
<template for:each={generalLinks} for:item="item">
|
|
107
|
+
<div class="footer-group" key={item.id}>
|
|
108
|
+
<h2 class="subheading">{item.label}</h2>
|
|
109
|
+
<template for:each={item.options} for:item="option">
|
|
110
110
|
<dx-footer-option
|
|
111
|
-
key={option.
|
|
112
|
-
general-label={
|
|
111
|
+
key={option.id}
|
|
112
|
+
general-label={item.label}
|
|
113
113
|
label={option.label}
|
|
114
|
-
href={option.href}
|
|
114
|
+
href={option.link.href}
|
|
115
115
|
icon-symbol={option.iconSymbol}
|
|
116
|
-
target={option.target}
|
|
116
|
+
target={option.link.target}
|
|
117
117
|
></dx-footer-option>
|
|
118
118
|
</template>
|
|
119
119
|
</div>
|
|
@@ -129,15 +129,22 @@
|
|
|
129
129
|
</span>
|
|
130
130
|
<div class="terms_links">
|
|
131
131
|
<template for:each={termsLinks} for:item="term">
|
|
132
|
-
<
|
|
132
|
+
<template if:true={term.onclick}>
|
|
133
|
+
<a
|
|
134
|
+
href={term.href}
|
|
135
|
+
key={term.label}
|
|
136
|
+
rel={term.rel}
|
|
137
|
+
onclick={term.onclick}
|
|
138
|
+
>
|
|
139
|
+
{term.label}
|
|
140
|
+
</a>
|
|
141
|
+
</template>
|
|
142
|
+
<template if:false={term.onclick}>
|
|
143
|
+
<a href={term.href} key={term.label} rel={term.rel}>
|
|
144
|
+
{term.label}
|
|
145
|
+
</a>
|
|
146
|
+
</template>
|
|
133
147
|
</template>
|
|
134
|
-
<a
|
|
135
|
-
href="#"
|
|
136
|
-
rel="nofollow"
|
|
137
|
-
onclick={openOneTrustInfoDisplay}
|
|
138
|
-
>
|
|
139
|
-
Cookie Preferences
|
|
140
|
-
</a>
|
|
141
148
|
</div>
|
|
142
149
|
</div>
|
|
143
150
|
</div>
|
|
@@ -3,7 +3,7 @@ import cx from "classnames";
|
|
|
3
3
|
import { FooterVariant, OptionWithLink } from "typings/custom";
|
|
4
4
|
import { toJson } from "dxUtils/normalizers";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
defaultGeneralLinks,
|
|
7
7
|
termsLinks,
|
|
8
8
|
socialLinks,
|
|
9
9
|
privacyHref,
|
|
@@ -31,16 +31,26 @@ export default class Footer extends LightningElement {
|
|
|
31
31
|
this._locales = toJson(value);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
@api
|
|
35
|
+
get generalLinks() {
|
|
36
|
+
return this._generalLinks;
|
|
37
|
+
}
|
|
38
|
+
set generalLinks(value) {
|
|
39
|
+
if (value) {
|
|
40
|
+
this._generalLinks = toJson(value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private _generalLinks = defaultGeneralLinks;
|
|
34
45
|
private _locales?: OptionWithLink[] | null = null;
|
|
35
|
-
private termsLinks = termsLinks;
|
|
36
|
-
private generalLinks = generalLinks;
|
|
37
|
-
private socialLinks = socialLinks;
|
|
38
|
-
private privacyHref = privacyHref;
|
|
39
|
-
private intellectualHref = intellectualHref;
|
|
40
|
-
private inputSubmitLabel = "Subscribe";
|
|
41
|
-
private inputPlaceholder = "Email";
|
|
42
|
-
private inputAriaLabel = "Email sign up for developer updates newsletter";
|
|
43
46
|
private _variant: FooterVariant = "small-signup";
|
|
47
|
+
private inputAriaLabel = "Email sign up for developer updates newsletter";
|
|
48
|
+
private inputPlaceholder = "Email";
|
|
49
|
+
private inputSubmitLabel = "Subscribe";
|
|
50
|
+
private intellectualHref = intellectualHref;
|
|
51
|
+
private privacyHref = privacyHref;
|
|
52
|
+
private socialLinks = socialLinks;
|
|
53
|
+
private termsLinks = termsLinks;
|
|
44
54
|
|
|
45
55
|
@api
|
|
46
56
|
set variant(value: FooterVariant) {
|
|
@@ -108,12 +118,6 @@ export default class Footer extends LightningElement {
|
|
|
108
118
|
);
|
|
109
119
|
}
|
|
110
120
|
|
|
111
|
-
private openOneTrustInfoDisplay = () => {
|
|
112
|
-
if (window.OneTrust && window.OneTrust.ToggleInfoDisplay) {
|
|
113
|
-
window.OneTrust.ToggleInfoDisplay();
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
121
|
private isFooterVariant(value: string): value is FooterVariant {
|
|
118
122
|
return [
|
|
119
123
|
"no-signup",
|
|
@@ -1,83 +1,137 @@
|
|
|
1
|
-
|
|
1
|
+
import { OptionWithRequiredNested } from "typings/custom";
|
|
2
|
+
|
|
3
|
+
export const generalLinksRaw: OptionWithRequiredNested[] = [
|
|
2
4
|
{
|
|
5
|
+
id: "Developer Centers",
|
|
3
6
|
label: "Developer Centers",
|
|
4
7
|
options: [
|
|
5
|
-
{ href: "https://devcenter.heroku.com/", label: "Heroku" },
|
|
6
|
-
{ href: "https://developer.mulesoft.com/", label: "MuleSoft" },
|
|
7
|
-
{ href: "https://www.tableau.com/developer", label: "Tableau" },
|
|
8
8
|
{
|
|
9
|
-
href: "https://
|
|
10
|
-
label: "
|
|
9
|
+
link: { href: "https://devcenter.heroku.com/" },
|
|
10
|
+
label: "Heroku",
|
|
11
|
+
id: "Heroku"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
link: { href: "https://developer.mulesoft.com/" },
|
|
15
|
+
label: "MuleSoft",
|
|
16
|
+
id: "MuleSoft"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
link: { href: "https://www.tableau.com/developer" },
|
|
20
|
+
label: "Tableau",
|
|
21
|
+
id: "Tableau"
|
|
11
22
|
},
|
|
12
23
|
{
|
|
13
|
-
href: "https://
|
|
14
|
-
label: "
|
|
24
|
+
link: { href: "https://developer.commercecloud.com/s/" },
|
|
25
|
+
label: "Commerce Cloud",
|
|
26
|
+
id: "Commerce Cloud"
|
|
15
27
|
},
|
|
16
28
|
{
|
|
17
|
-
href: "https://
|
|
18
|
-
label: "
|
|
29
|
+
link: { href: "https://www.lightningdesignsystem.com/" },
|
|
30
|
+
label: "Lightning Design System",
|
|
31
|
+
id: "Lightning Design System"
|
|
19
32
|
},
|
|
20
|
-
{
|
|
33
|
+
{
|
|
34
|
+
link: { href: "https://metamind.readme.io/" },
|
|
35
|
+
label: "Einstein",
|
|
36
|
+
id: "Einstein"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
link: { href: "https://salesforce.quip.com/dev" },
|
|
40
|
+
label: "Quip",
|
|
41
|
+
id: "Quip"
|
|
42
|
+
}
|
|
21
43
|
]
|
|
22
44
|
},
|
|
23
45
|
{
|
|
46
|
+
id: "Popular Resources",
|
|
24
47
|
label: "Popular Resources",
|
|
25
48
|
options: [
|
|
26
|
-
{ href: "/docs", label: "Documentation" },
|
|
27
49
|
{
|
|
28
|
-
href: "/docs
|
|
29
|
-
label: "
|
|
50
|
+
link: { href: "/docs" },
|
|
51
|
+
label: "Documentation",
|
|
52
|
+
id: "Documentation"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
link: { href: "/docs/component-library" },
|
|
56
|
+
label: "Component Library",
|
|
57
|
+
id: "Component Library"
|
|
58
|
+
},
|
|
59
|
+
{ link: { href: "/docs/apis" }, label: "APIs", id: "APIs" },
|
|
60
|
+
{
|
|
61
|
+
link: { href: "https://trailhead.salesforce.com/" },
|
|
62
|
+
label: "Trailhead",
|
|
63
|
+
id: "Trailhead"
|
|
30
64
|
},
|
|
31
|
-
{ href: "/docs/apis", label: "APIs" },
|
|
32
|
-
{ href: "https://trailhead.salesforce.com/", label: "Trailhead" },
|
|
33
65
|
{
|
|
34
|
-
href: "/code-samples-and-sdks",
|
|
35
|
-
label: "Code Samples and SDKs"
|
|
66
|
+
link: { href: "/code-samples-and-sdks" },
|
|
67
|
+
label: "Code Samples and SDKs",
|
|
68
|
+
id: "Code Samples and SDKs"
|
|
36
69
|
},
|
|
37
|
-
{ href: "/podcast", label: "Podcasts" },
|
|
70
|
+
{ link: { href: "/podcast" }, label: "Podcasts", id: "Podcasts" },
|
|
38
71
|
{
|
|
39
|
-
href: "https://appexchange.salesforce.com/",
|
|
40
|
-
label: "AppExchange"
|
|
72
|
+
link: { href: "https://appexchange.salesforce.com/" },
|
|
73
|
+
label: "AppExchange",
|
|
74
|
+
id: "AppExchange"
|
|
41
75
|
}
|
|
42
76
|
]
|
|
43
77
|
},
|
|
44
78
|
{
|
|
45
79
|
label: "Community",
|
|
80
|
+
id: "Community",
|
|
46
81
|
options: [
|
|
47
82
|
{
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
link: {
|
|
84
|
+
href: "https://trailhead.salesforce.com/trailblazer-community/feed"
|
|
85
|
+
},
|
|
86
|
+
label: "Trailblazer Community",
|
|
87
|
+
id: "Trailblazer Community"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
link: {
|
|
91
|
+
href: "/forums#!/feedtype=RECENT&criteria=ALLQUESTIONS&"
|
|
92
|
+
},
|
|
93
|
+
label: "Forums",
|
|
94
|
+
id: "Forums"
|
|
50
95
|
},
|
|
51
96
|
{
|
|
52
|
-
href: "/
|
|
53
|
-
label: "
|
|
97
|
+
link: { href: "/events" },
|
|
98
|
+
label: "Events and Calendar",
|
|
99
|
+
id: "Events and Calendar"
|
|
54
100
|
},
|
|
55
|
-
{ href: "/events", label: "Events and Calendar" },
|
|
56
101
|
{
|
|
57
|
-
href: "https://go.appexchange.com/partnerprogram",
|
|
58
|
-
label: "Partner Community"
|
|
102
|
+
link: { href: "https://go.appexchange.com/partnerprogram" },
|
|
103
|
+
label: "Partner Community",
|
|
104
|
+
id: "Partner Community"
|
|
59
105
|
},
|
|
60
|
-
{ href: "/blogs", label: "Blog" },
|
|
106
|
+
{ link: { href: "/blogs" }, label: "Blog", id: "Blog" },
|
|
61
107
|
{
|
|
62
|
-
href: "https://admin.salesforce.com/",
|
|
63
|
-
label: "Salesforce Admins"
|
|
108
|
+
link: { href: "https://admin.salesforce.com/" },
|
|
109
|
+
label: "Salesforce Admins",
|
|
110
|
+
id: "Salesforce Admins"
|
|
64
111
|
},
|
|
65
112
|
{
|
|
66
|
-
href: "https://architect.salesforce.com/",
|
|
67
|
-
label: "Salesforce Architects"
|
|
113
|
+
link: { href: "https://architect.salesforce.com/" },
|
|
114
|
+
label: "Salesforce Architects",
|
|
115
|
+
id: "Salesforce Architects"
|
|
68
116
|
}
|
|
69
117
|
]
|
|
70
118
|
}
|
|
71
119
|
];
|
|
72
120
|
|
|
73
|
-
export const
|
|
121
|
+
export const defaultGeneralLinks = generalLinksRaw.map((section) => ({
|
|
74
122
|
...section,
|
|
75
123
|
options: section.options.map((option) => {
|
|
76
|
-
|
|
124
|
+
if (!option.link) {
|
|
125
|
+
return option;
|
|
126
|
+
}
|
|
127
|
+
const external = option.link.href.startsWith("http");
|
|
77
128
|
return {
|
|
78
129
|
...option,
|
|
79
|
-
|
|
80
|
-
|
|
130
|
+
link: {
|
|
131
|
+
...option.link,
|
|
132
|
+
iconSymbol: external ? "new_window" : null,
|
|
133
|
+
target: external ? "_blank" : null
|
|
134
|
+
}
|
|
81
135
|
};
|
|
82
136
|
})
|
|
83
137
|
}));
|
|
@@ -87,6 +141,12 @@ export const privacyHref = "https://www.salesforce.com/company/privacy/";
|
|
|
87
141
|
export const intellectualHref =
|
|
88
142
|
"https://www.salesforce.com/company/legal/intellectual/";
|
|
89
143
|
|
|
144
|
+
const openOneTrustInfoDisplay = () => {
|
|
145
|
+
if (window.OneTrust && window.OneTrust.ToggleInfoDisplay) {
|
|
146
|
+
window.OneTrust.ToggleInfoDisplay();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
90
150
|
export const termsLinks = [
|
|
91
151
|
{ href: privacyHref, label: "Privacy Statement" },
|
|
92
152
|
{
|
|
@@ -97,7 +157,13 @@ export const termsLinks = [
|
|
|
97
157
|
href: "https://www.salesforce.com/company/privacy/full_privacy/#nav_info",
|
|
98
158
|
label: "Use of Cookies"
|
|
99
159
|
},
|
|
100
|
-
{ href: "https://trust.salesforce.com/en/", label: "Trust" }
|
|
160
|
+
{ href: "https://trust.salesforce.com/en/", label: "Trust" },
|
|
161
|
+
{
|
|
162
|
+
href: "#",
|
|
163
|
+
rel: "nofollow",
|
|
164
|
+
label: "Cookie Preferences",
|
|
165
|
+
onclick: openOneTrustInfoDisplay
|
|
166
|
+
}
|
|
101
167
|
];
|
|
102
168
|
|
|
103
169
|
export const socialLinks = [
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import LANGUAGES from "./languageList";
|
|
2
|
+
import {
|
|
3
|
+
codeLanguages,
|
|
4
|
+
codeLanguagePattern,
|
|
5
|
+
codeLanguagePatternList
|
|
6
|
+
} from "typings/custom";
|
|
7
|
+
|
|
8
|
+
function getPoints(lineOfCode: string, checkers: codeLanguagePatternList) {
|
|
9
|
+
return checkers
|
|
10
|
+
.map((checker: codeLanguagePattern) => {
|
|
11
|
+
if (checker.pattern.test(lineOfCode)) {
|
|
12
|
+
return checker.points;
|
|
13
|
+
}
|
|
14
|
+
return 0;
|
|
15
|
+
})
|
|
16
|
+
.reduce((memo, num) => memo + num, 0);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function detect(snippet: string) {
|
|
20
|
+
const opts = Object.assign({
|
|
21
|
+
heuristic: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
let linesOfCode = snippet
|
|
25
|
+
.replace(/\r\n?/g, "\n")
|
|
26
|
+
.replace(/\n{2,}/g, "\n")
|
|
27
|
+
.split("\n");
|
|
28
|
+
|
|
29
|
+
function nearTop(index: number) {
|
|
30
|
+
return linesOfCode.length <= 10 || index < linesOfCode.length / 10;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (opts.heuristic && linesOfCode.length > 500) {
|
|
34
|
+
linesOfCode = linesOfCode.filter((lineOfCode, index) => {
|
|
35
|
+
return (
|
|
36
|
+
nearTop(index) ||
|
|
37
|
+
index % Math.ceil(linesOfCode.length / 500) === 0
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pairs = Object.keys(LANGUAGES).map((key) => {
|
|
43
|
+
return {
|
|
44
|
+
language: key,
|
|
45
|
+
checkers: LANGUAGES[key as keyof typeof LANGUAGES]
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const results = pairs.map((pair) => {
|
|
50
|
+
const language = pair.language;
|
|
51
|
+
const checkers = pair.checkers;
|
|
52
|
+
|
|
53
|
+
if (language === "Unknown") {
|
|
54
|
+
return { language: "Unknown", points: 1 };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const pointsList = linesOfCode.map((lineOfCode) => {
|
|
58
|
+
return getPoints(lineOfCode, checkers);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const points = pointsList.reduce((memo, num) => memo + num);
|
|
62
|
+
|
|
63
|
+
return { language, points };
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const sortedResult = results.sort(
|
|
67
|
+
(prev, next) => prev.points - next.points
|
|
68
|
+
);
|
|
69
|
+
const bestResult = sortedResult[sortedResult.length - 1];
|
|
70
|
+
|
|
71
|
+
return bestResult.language;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const languages: any = Object.keys(LANGUAGES);
|
|
75
|
+
const LANG: { [key: string]: codeLanguages } = {};
|
|
76
|
+
|
|
77
|
+
languages.forEach((language: codeLanguages) => {
|
|
78
|
+
LANG[language] = language;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export { detect, languages, LANG };
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
JavaScript: [
|
|
3
|
+
// undefined keyword
|
|
4
|
+
{ pattern: /undefined/g, points: 2 },
|
|
5
|
+
// console.log('ayy lmao')
|
|
6
|
+
{ pattern: /console\.log( )*\(/, points: 2 },
|
|
7
|
+
// Variable declaration
|
|
8
|
+
{ pattern: /(var|const|let)( )+\w+( )*=?/, points: 2 },
|
|
9
|
+
// Array/Object declaration
|
|
10
|
+
{ pattern: /(('|").+('|")( )*|\w+):( )*[{[]/, points: 2 },
|
|
11
|
+
// === operator
|
|
12
|
+
{ pattern: /===/g, points: 1 },
|
|
13
|
+
// !== operator
|
|
14
|
+
{ pattern: /!==/g, points: 1 },
|
|
15
|
+
// Function definition
|
|
16
|
+
{
|
|
17
|
+
pattern: /function\*?(( )+[$\w]+( )*\(.*\)|( )*\(.*\))/g,
|
|
18
|
+
points: 1
|
|
19
|
+
},
|
|
20
|
+
// null keyword
|
|
21
|
+
{ pattern: /null/g, points: 1 },
|
|
22
|
+
// lambda expression
|
|
23
|
+
{ pattern: /\(.*\)( )*=>( )*.+/, points: 1 },
|
|
24
|
+
// (else )if statement
|
|
25
|
+
{ pattern: /(else )?if( )+\(.+\)/, points: 1 },
|
|
26
|
+
// while loop
|
|
27
|
+
{ pattern: /while( )+\(.+\)/, points: 1 },
|
|
28
|
+
// C style variable declaration.
|
|
29
|
+
{
|
|
30
|
+
pattern: /(^|\s)(char|long|int|float|double)( )+\w+( )*=?/,
|
|
31
|
+
points: -1
|
|
32
|
+
},
|
|
33
|
+
// pointer
|
|
34
|
+
{ pattern: /(\w+)( )*\*( )*\w+/, points: -1 },
|
|
35
|
+
// HTML <script> tag
|
|
36
|
+
{
|
|
37
|
+
pattern: /<(\/)?script( type=('|")text\/javascript('|"))?>/,
|
|
38
|
+
points: -50
|
|
39
|
+
},
|
|
40
|
+
// ES6 import / export
|
|
41
|
+
{
|
|
42
|
+
pattern:
|
|
43
|
+
/(import|export(\s+)default)\s+({\s+[\w\s,]+\s+}|\w+)\s+from\s/,
|
|
44
|
+
points: 2
|
|
45
|
+
},
|
|
46
|
+
// ES6 arrow function
|
|
47
|
+
{ pattern: /\([^()]{0,}\)\s+=>(\s+{)?/, points: 3 }
|
|
48
|
+
// () => {}
|
|
49
|
+
// (a) => {}
|
|
50
|
+
// (a, b) => {}
|
|
51
|
+
// ({ a, b}) => {}
|
|
52
|
+
// ([ a, b ]) => {}
|
|
53
|
+
],
|
|
54
|
+
|
|
55
|
+
C: [
|
|
56
|
+
// Primitive variable declaration.
|
|
57
|
+
{ pattern: /(char|long|int|float|double)( )+\w+( )*=?/, points: 2 },
|
|
58
|
+
// malloc function call
|
|
59
|
+
{ pattern: /malloc\(.+\)/, points: 2 },
|
|
60
|
+
// #include <whatever.h>
|
|
61
|
+
{ pattern: /#include (<|")\w+\.h(>|")/, points: 2, nearTop: true },
|
|
62
|
+
// pointer
|
|
63
|
+
{ pattern: /(\w+)( )*\*( )*\w+/, points: 2 },
|
|
64
|
+
// Variable declaration and/or initialisation.
|
|
65
|
+
{ pattern: /(\w+)( )+\w+(;|( )*=)/, points: 1 },
|
|
66
|
+
// Array declaration.
|
|
67
|
+
{ pattern: /(\w+)( )+\w+\[.+\]/, points: 1 },
|
|
68
|
+
// #define macro
|
|
69
|
+
{ pattern: /#define( )+.+/, points: 1 },
|
|
70
|
+
// NULL constant
|
|
71
|
+
{ pattern: /NULL/, points: 1 },
|
|
72
|
+
// void keyword
|
|
73
|
+
{ pattern: /void/g, points: 1 },
|
|
74
|
+
// (else )if statement
|
|
75
|
+
{ pattern: /(else )?if( )*\(.+\)/, points: 1 },
|
|
76
|
+
// while loop
|
|
77
|
+
{ pattern: /while( )+\(.+\)/, points: 1 },
|
|
78
|
+
// printf function
|
|
79
|
+
{ pattern: /(printf|puts)( )*\(.+\)/, points: 1 },
|
|
80
|
+
// new Keyword from C++
|
|
81
|
+
{ pattern: /new \w+/, points: -1 },
|
|
82
|
+
// Single quote multicharacter string
|
|
83
|
+
{ pattern: /'.{2,}'/, points: -1 },
|
|
84
|
+
// JS variable declaration
|
|
85
|
+
{ pattern: /var( )+\w+( )*=?/, points: -1 }
|
|
86
|
+
],
|
|
87
|
+
|
|
88
|
+
"C++": [
|
|
89
|
+
// Primitive variable declaration.
|
|
90
|
+
{ pattern: /(char|long|int|float|double)( )+\w+( )*=?/, points: 2 },
|
|
91
|
+
// #include <whatever.h>
|
|
92
|
+
{
|
|
93
|
+
pattern: /#include( )*(<|")\w+(\.h)?(>|")/,
|
|
94
|
+
points: 2,
|
|
95
|
+
nearTop: true
|
|
96
|
+
},
|
|
97
|
+
// using namespace something
|
|
98
|
+
{ pattern: /using( )+namespace( )+.+( )*;/, points: 2 },
|
|
99
|
+
// template declaration
|
|
100
|
+
{ pattern: /template( )*<.*>/, points: 2 },
|
|
101
|
+
// std
|
|
102
|
+
{ pattern: /std::\w+/g, points: 2 },
|
|
103
|
+
// cout/cin/endl
|
|
104
|
+
{ pattern: /(cout|cin|endl)/g, points: 2 },
|
|
105
|
+
// Visibility specifiers
|
|
106
|
+
{ pattern: /(public|protected|private):/, points: 2 },
|
|
107
|
+
// nullptr
|
|
108
|
+
{ pattern: /nullptr/, points: 2 },
|
|
109
|
+
// new Keyword
|
|
110
|
+
{ pattern: /new \w+(\(.*\))?/, points: 1 },
|
|
111
|
+
// #define macro
|
|
112
|
+
{ pattern: /#define( )+.+/, points: 1 },
|
|
113
|
+
// template usage
|
|
114
|
+
{ pattern: /\w+<\w+>/, points: 1 },
|
|
115
|
+
// class keyword
|
|
116
|
+
{ pattern: /class( )+\w+/, points: 1 },
|
|
117
|
+
// void keyword
|
|
118
|
+
{ pattern: /void/g, points: 1 },
|
|
119
|
+
// (else )if statement
|
|
120
|
+
{ pattern: /(else )?if( )*\(.+\)/, points: 1 },
|
|
121
|
+
// while loop
|
|
122
|
+
{ pattern: /while( )+\(.+\)/, points: 1 },
|
|
123
|
+
// Scope operator
|
|
124
|
+
{ pattern: /\w*::\w+/, points: 1 },
|
|
125
|
+
// Single quote multicharacter string
|
|
126
|
+
{ pattern: /'.{2,}'/, points: -1 },
|
|
127
|
+
// Java List/ArrayList
|
|
128
|
+
{
|
|
129
|
+
pattern: /(List<\w+>|ArrayList<\w*>( )*\(.*\))(( )+[\w]+|;)/,
|
|
130
|
+
points: -1
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
|
|
134
|
+
Python: [
|
|
135
|
+
// Function definition
|
|
136
|
+
{ pattern: /def( )+\w+\(.*\)( )*:/, points: 2 },
|
|
137
|
+
// while loop
|
|
138
|
+
{ pattern: /while (.+):/, points: 2 },
|
|
139
|
+
// from library import something
|
|
140
|
+
{ pattern: /from [\w.]+ import (\w+|\*)/, points: 2 },
|
|
141
|
+
// class keyword
|
|
142
|
+
{ pattern: /class( )*\w+(\(( )*\w+( )*\))?( )*:/, points: 2 },
|
|
143
|
+
// if keyword
|
|
144
|
+
{ pattern: /if( )+(.+)( )*:/, points: 2 },
|
|
145
|
+
// elif keyword
|
|
146
|
+
{ pattern: /elif( )+(.+)( )*:/, points: 2 },
|
|
147
|
+
// else keyword
|
|
148
|
+
{ pattern: /else:/, points: 2 },
|
|
149
|
+
// for loop
|
|
150
|
+
{ pattern: /for (\w+|\(?\w+,( )*\w+\)?) in (.+):/, points: 2 },
|
|
151
|
+
// Python variable declaration.
|
|
152
|
+
{ pattern: /\w+( )*=( )*\w+(?!;)(\n|$)/, points: 1 },
|
|
153
|
+
// import something
|
|
154
|
+
{ pattern: /import ([[^.]\w])+/, points: 1, nearTop: true },
|
|
155
|
+
// print statement/function
|
|
156
|
+
{ pattern: /print((( )*\(.+\))|( )+.+)/, points: 1 },
|
|
157
|
+
// &&/|| operators
|
|
158
|
+
{ pattern: /(&{2}|\|{2})/, points: -1 }
|
|
159
|
+
],
|
|
160
|
+
|
|
161
|
+
Java: [
|
|
162
|
+
// System.out.println() etc.
|
|
163
|
+
{ pattern: /System\.(in|out)\.\w+/, points: 2 },
|
|
164
|
+
// Class variable declarations
|
|
165
|
+
{
|
|
166
|
+
pattern: /(private|protected|public)( )*\w+( )*\w+(( )*=( )*[\w])?/,
|
|
167
|
+
points: 2
|
|
168
|
+
},
|
|
169
|
+
// Method
|
|
170
|
+
{
|
|
171
|
+
pattern: /(private|protected|public)( )*\w+( )*[\w]+\(.+\)/,
|
|
172
|
+
points: 2
|
|
173
|
+
},
|
|
174
|
+
// String class
|
|
175
|
+
{ pattern: /(^|\s)(String)( )+[\w]+( )*=?/, points: 2 },
|
|
176
|
+
// List/ArrayList
|
|
177
|
+
{
|
|
178
|
+
pattern: /(List<\w+>|ArrayList<\w*>( )*\(.*\))(( )+[\w]+|;)/,
|
|
179
|
+
points: 2
|
|
180
|
+
},
|
|
181
|
+
// class keyword
|
|
182
|
+
{ pattern: /(public( )*)?class( )*\w+/, points: 2 },
|
|
183
|
+
// Array declaration.
|
|
184
|
+
{ pattern: /(\w+)(\[( )*\])+( )+\w+/, points: 2 },
|
|
185
|
+
// final keyword
|
|
186
|
+
{ pattern: /final( )*\w+/, points: 2 },
|
|
187
|
+
// getter & setter
|
|
188
|
+
{ pattern: /\w+\.(get|set)\(.+\)/, points: 2 },
|
|
189
|
+
// new Keyword (Java)
|
|
190
|
+
{ pattern: /new [A-Z]\w*( )*\(.+\)/, points: 2 },
|
|
191
|
+
// C style variable declaration.
|
|
192
|
+
{
|
|
193
|
+
pattern: /(^|\s)(char|long|int|float|double)( )+[\w]+( )*=?/,
|
|
194
|
+
points: 1
|
|
195
|
+
},
|
|
196
|
+
// extends/implements keywords
|
|
197
|
+
{ pattern: /(extends|implements)/, points: 2, nearTop: true },
|
|
198
|
+
// null keyword
|
|
199
|
+
{ pattern: /null/g, points: 1 },
|
|
200
|
+
// (else )if statement
|
|
201
|
+
{ pattern: /(else )?if( )*\(.+\)/, points: 1 },
|
|
202
|
+
// while loop
|
|
203
|
+
{ pattern: /while( )+\(.+\)/, points: 1 },
|
|
204
|
+
// void keyword
|
|
205
|
+
{ pattern: /void/g, points: 1 },
|
|
206
|
+
// const
|
|
207
|
+
{ pattern: /const( )*\w+/, points: -1 },
|
|
208
|
+
// pointer
|
|
209
|
+
{ pattern: /(\w+)( )*\*( )*\w+/, points: -1 },
|
|
210
|
+
// Single quote multicharacter string
|
|
211
|
+
{ pattern: /'.{2,}'/, points: -1 },
|
|
212
|
+
// C style include
|
|
213
|
+
{
|
|
214
|
+
pattern: /#include( )*(<|")\w+(\.h)?(>|")/,
|
|
215
|
+
points: -1,
|
|
216
|
+
nearTop: true
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
|
|
220
|
+
HTML: [
|
|
221
|
+
{
|
|
222
|
+
pattern: /<!DOCTYPE (html|HTML PUBLIC .+)>/,
|
|
223
|
+
points: 2,
|
|
224
|
+
nearTop: true
|
|
225
|
+
},
|
|
226
|
+
// Tags
|
|
227
|
+
{
|
|
228
|
+
pattern: /<[a-z0-9]+(( )*[\w]+=('|").+('|")( )*)?>.*<\/[a-z0-9]+>/g,
|
|
229
|
+
points: 2
|
|
230
|
+
},
|
|
231
|
+
// Properties
|
|
232
|
+
{ pattern: /[a-z-]+=("|').+("|')/g, points: 2 },
|
|
233
|
+
// PHP tag
|
|
234
|
+
{ pattern: /<\?php/, points: -50 }
|
|
235
|
+
],
|
|
236
|
+
|
|
237
|
+
CSS: [
|
|
238
|
+
// Properties
|
|
239
|
+
{ pattern: /[a-z-]+:(?!:).+;/, points: 2 },
|
|
240
|
+
// <style> tag from HTML
|
|
241
|
+
{ pattern: /<(\/)?style>/, points: -50 }
|
|
242
|
+
],
|
|
243
|
+
|
|
244
|
+
Ruby: [
|
|
245
|
+
// require/include
|
|
246
|
+
{
|
|
247
|
+
pattern: /(require|include)( )+'\w+(\.rb)?'/,
|
|
248
|
+
points: 2,
|
|
249
|
+
nearTop: true
|
|
250
|
+
},
|
|
251
|
+
// Function definition
|
|
252
|
+
{ pattern: /def( )+\w+( )*(\(.+\))?( )*\n/, points: 2 },
|
|
253
|
+
// Instance variables
|
|
254
|
+
{ pattern: /@\w+/, points: 2 },
|
|
255
|
+
// Boolean property
|
|
256
|
+
{ pattern: /\.\w+\?/, points: 2 },
|
|
257
|
+
// puts (Ruby print)
|
|
258
|
+
{ pattern: /puts( )+("|').+("|')/, points: 2 },
|
|
259
|
+
// Inheriting class
|
|
260
|
+
{ pattern: /class [A-Z]\w*( )*<( )*([A-Z]\w*(::)?)+/, points: 2 },
|
|
261
|
+
// attr_accessor
|
|
262
|
+
{ pattern: /attr_accessor( )+(:\w+(,( )*)?)+/, points: 2 },
|
|
263
|
+
// new
|
|
264
|
+
{ pattern: /\w+\.new( )+/, points: 2 },
|
|
265
|
+
// elsif keyword
|
|
266
|
+
{ pattern: /elsif/, points: 2 },
|
|
267
|
+
// do
|
|
268
|
+
{ pattern: /do( )*\|(\w+(,( )*\w+)?)+\|/, points: 2 },
|
|
269
|
+
// for loop
|
|
270
|
+
{ pattern: /for (\w+|\(?\w+,( )*\w+\)?) in (.+)/, points: 1 },
|
|
271
|
+
// nil keyword
|
|
272
|
+
{ pattern: /nil/, points: 1 },
|
|
273
|
+
// Scope operator
|
|
274
|
+
{ pattern: /[A-Z]\w*::[A-Z]\w*/, points: 1 }
|
|
275
|
+
],
|
|
276
|
+
|
|
277
|
+
Go: [
|
|
278
|
+
// package something
|
|
279
|
+
{ pattern: /package( )+[a-z]+\n/, points: 2, nearTop: true },
|
|
280
|
+
// import
|
|
281
|
+
{
|
|
282
|
+
pattern: /(import( )*\(( )*\n)|(import( )+"[a-z0-9/.]+")/,
|
|
283
|
+
points: 2,
|
|
284
|
+
nearTop: true
|
|
285
|
+
},
|
|
286
|
+
// error check
|
|
287
|
+
{ pattern: /if.+err( )*!=( )*nil.+{/, points: 2 },
|
|
288
|
+
// Go print
|
|
289
|
+
{ pattern: /fmt\.Print(f|ln)?\(.*\)/, points: 2 },
|
|
290
|
+
// function
|
|
291
|
+
{ pattern: /func(( )+\w+( )*)?\(.*\).*{/, points: 2 },
|
|
292
|
+
// variable initialisation
|
|
293
|
+
{ pattern: /\w+( )*:=( )*.+[^;\n]/, points: 2 },
|
|
294
|
+
// if/else if
|
|
295
|
+
{ pattern: /(}( )*else( )*)?if[^()]+{/, points: 2 },
|
|
296
|
+
// var/const declaration
|
|
297
|
+
{ pattern: /(var|const)( )+\w+( )+[\w*]+(\n|( )*=|$)/, points: 2 },
|
|
298
|
+
// public access on package
|
|
299
|
+
{ pattern: /[a-z]+\.[A-Z]\w*/, points: 1 },
|
|
300
|
+
// nil keyword
|
|
301
|
+
{ pattern: /nil/, points: 1 },
|
|
302
|
+
// Single quote multicharacter string
|
|
303
|
+
{ pattern: /'.{2,}'/, points: -1 }
|
|
304
|
+
],
|
|
305
|
+
|
|
306
|
+
PHP: [
|
|
307
|
+
// PHP tag
|
|
308
|
+
{ pattern: /<\?php/, points: 2 },
|
|
309
|
+
// PHP style variables.
|
|
310
|
+
{ pattern: /\$\w+/, points: 2 },
|
|
311
|
+
// use Something\Something;
|
|
312
|
+
{ pattern: /use( )+\w+(\\\w+)+( )*;/, points: 2, nearTop: true },
|
|
313
|
+
// arrow
|
|
314
|
+
{ pattern: /\$\w+->\w+/, points: 2 },
|
|
315
|
+
// require/include
|
|
316
|
+
{
|
|
317
|
+
pattern:
|
|
318
|
+
/(require|include)(_once)?( )*\(?( )*('|").+\.php('|")( )*\)?( )*;/,
|
|
319
|
+
points: 2
|
|
320
|
+
},
|
|
321
|
+
// echo 'something';
|
|
322
|
+
{ pattern: /echo( )+('|").+('|")( )*;/, points: 1 },
|
|
323
|
+
// NULL constant
|
|
324
|
+
{ pattern: /NULL/, points: 1 },
|
|
325
|
+
// new keyword
|
|
326
|
+
{ pattern: /new( )+((\\\w+)+|\w+)(\(.*\))?/, points: 1 },
|
|
327
|
+
// Function definition
|
|
328
|
+
{ pattern: /function(( )+[$\w]+\(.*\)|( )*\(.*\))/g, points: 1 },
|
|
329
|
+
// (else)if statement
|
|
330
|
+
{ pattern: /(else)?if( )+\(.+\)/, points: 1 },
|
|
331
|
+
// scope operator
|
|
332
|
+
{ pattern: /\w+::\w+/, points: 1 },
|
|
333
|
+
// === operator
|
|
334
|
+
{ pattern: /===/g, points: 1 },
|
|
335
|
+
// !== operator
|
|
336
|
+
{ pattern: /!==/g, points: 1 },
|
|
337
|
+
// C/JS style variable declaration.
|
|
338
|
+
{
|
|
339
|
+
pattern: /(^|\s)(var|char|long|int|float|double)( )+\w+( )*=?/,
|
|
340
|
+
points: -1
|
|
341
|
+
}
|
|
342
|
+
],
|
|
343
|
+
|
|
344
|
+
Unknown: []
|
|
345
|
+
};
|
package/LICENSE
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2020, Salesforce.com, Inc.
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
-
|
|
6
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
-
|
|
8
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
-
|
|
10
|
-
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
-
|
|
12
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|