@slim-lang/core 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/README.md +666 -0
- package/package.json +55 -0
- package/packages/slim/.spm +7 -0
- package/packages/slim/converters/main.slim +106 -0
- package/packages/slim/helpers/array.slim +25 -0
- package/packages/slim/helpers/path.slim +3 -0
- package/packages/slim/helpers/request.slim +102 -0
- package/packages/slim/helpers/string.slim +27 -0
- package/packages/slim/main.slim +42 -0
- package/packages/slim/parse/main.slim +25 -0
- package/packages/slim/server/main.slim +423 -0
- package/packages/slim/time/main.slim +66 -0
- package/packages/slim/types/common.slim +6 -0
- package/packages/slim/types/formats.slim +23 -0
- package/packages/slim/types/hash.slim +6 -0
- package/packages/slim/types/mails.slim +3 -0
- package/packages/slim/types/numerical.slim +9 -0
- package/packages/slim/types/time.slim +3 -0
- package/run-dev-slim.js +133 -0
- package/run-slim.js +20 -0
- package/src/bin/api/github_auth.js +89 -0
- package/src/bin/api/github_get.js +139 -0
- package/src/bin/api/github_req.js +455 -0
- package/src/bin/api/lock.js +37 -0
- package/src/bin/api/spm.js +103 -0
- package/src/bin/api/storage.js +30 -0
- package/src/bin/cli.js +404 -0
- package/src/bin/config.default.json +5 -0
- package/src/bin/helpers.js +147 -0
- package/src/bin/parsers/spm.js +174 -0
- package/src/bin/spm.js +519 -0
- package/src/checker.js +926 -0
- package/src/compile.js +230 -0
- package/src/external/classErrors.js +202 -0
- package/src/external/client.js +38 -0
- package/src/external/core.js +861 -0
- package/src/external/defaults.js +25 -0
- package/src/external/helpers.js +541 -0
- package/src/external/slim-globals.d.ts +65 -0
- package/src/external/types.js +38 -0
- package/src/format.js +81 -0
- package/src/handlers/errorHandler.js +43 -0
- package/src/handlers/parser/components.js +250 -0
- package/src/handlers/parserHandler.js +793 -0
- package/src/jsdoc.js +273 -0
- package/src/lexer.js +174 -0
- package/src/modulePaths.js +74 -0
- package/src/parser.js +818 -0
- package/src/repl.js +32 -0
- package/src/sourcemap.js +0 -0
- package/src/test-runner.js +62 -0
- package/src/transform.js +765 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
use { SymbolInstance, AnyArray } from @slim/types/common
|
|
2
|
+
use { TimeStamp } from @slim/types/time
|
|
3
|
+
use { JSONString } from @slim/types/formats
|
|
4
|
+
|
|
5
|
+
export func int(value: string | int): int {
|
|
6
|
+
if (kindof value == "int") return value
|
|
7
|
+
|
|
8
|
+
const result = Number(value)
|
|
9
|
+
|
|
10
|
+
if (!Number.isInteger(result)) {
|
|
11
|
+
throw new TypeError(`Cannot convert "${value}" to int`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export func float(value: string | float | int): number {
|
|
18
|
+
if (type(value) == "float") return value
|
|
19
|
+
|
|
20
|
+
const result = Number(value)
|
|
21
|
+
|
|
22
|
+
if (Number.isNaN(result)) {
|
|
23
|
+
throw new TypeError(`Cannot convert "${value}" to float`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export func number(value: string | float | int): number {
|
|
30
|
+
if (typeof value == "number") return value
|
|
31
|
+
|
|
32
|
+
const result = Number(value)
|
|
33
|
+
|
|
34
|
+
if (Number.isNaN(result)) {
|
|
35
|
+
throw new TypeError(`Cannot convert "${value}" to number`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export func string(value: any): string {
|
|
42
|
+
return String(value)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export func bool(value: int | float | string | bool): bool {
|
|
46
|
+
if (typeof value == "boolean") return value
|
|
47
|
+
|
|
48
|
+
if (typeof value == "number") {
|
|
49
|
+
return value != 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof value == "string") {
|
|
53
|
+
const str = value.trim().toLowerCase()
|
|
54
|
+
|
|
55
|
+
if (str == "true" || str == "1") return true
|
|
56
|
+
if (str == "false" || str == "0") return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return Boolean(value)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export func bigint(value: number): number {
|
|
63
|
+
try {
|
|
64
|
+
return BigInt(value)
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new TypeError(`Cannot convert "${value}" to bigint`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export func symbol(value: any): SymbolInstance {
|
|
72
|
+
return Symbol(String(value))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export func array(value: any): AnyArray {
|
|
76
|
+
if (Array.isArray(value)) return value
|
|
77
|
+
|
|
78
|
+
return [value]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export func date(value: TimeStamp): any {
|
|
82
|
+
const result = new Date(value)
|
|
83
|
+
|
|
84
|
+
if (Number.isNaN(result.getTime())) {
|
|
85
|
+
throw new TypeError(`Cannot convert "${value}" to date`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export func json(value: AnyArray | string | number | object): object {
|
|
92
|
+
if (typeof value == "string") {
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(value)
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new TypeError("Invalid JSON")
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return JSON.parse(JSON.stringify(value))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export func jsonstr(value: AnyArray | string | number | object): JSONString {
|
|
105
|
+
return JSON.stringify(value)
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
use { AnyArray } from @slim/types/common
|
|
2
|
+
|
|
3
|
+
const oldSort = Array.prototype.sort;
|
|
4
|
+
|
|
5
|
+
Array.prototype.sort = function (compareFn) {
|
|
6
|
+
if (compareFn) return oldSort.call(this, compareFn);
|
|
7
|
+
|
|
8
|
+
if (this.every(v => typeof v === "number")) {
|
|
9
|
+
return oldSort.call(this, (a, b) => a - b);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return oldSort.call(this);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
func range(min: int, max: int): AnyArray {
|
|
16
|
+
const res = []
|
|
17
|
+
for (let i = min; i <= max; i++) {
|
|
18
|
+
res.push(i)
|
|
19
|
+
}
|
|
20
|
+
return res
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
range
|
|
25
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export class RequestHelper {
|
|
2
|
+
constructor(options: object = {}) {
|
|
3
|
+
this.baseURL = options.baseURL || ""
|
|
4
|
+
this.headers = options.headers || {}
|
|
5
|
+
this.timeout = options.timeout || 10000
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async request(url, options = {}) {
|
|
9
|
+
const controller = new AbortController()
|
|
10
|
+
|
|
11
|
+
const timeout = setTimeout(() => {
|
|
12
|
+
controller.abort()
|
|
13
|
+
}, this.timeout)
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(this.baseURL + url, {
|
|
17
|
+
...options,
|
|
18
|
+
headers: {
|
|
19
|
+
...this.headers,
|
|
20
|
+
...options.headers
|
|
21
|
+
},
|
|
22
|
+
signal: controller.signal
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
clearTimeout(timeout)
|
|
26
|
+
|
|
27
|
+
const type = response.headers.get("content-type") || ""
|
|
28
|
+
|
|
29
|
+
let data
|
|
30
|
+
|
|
31
|
+
if (type.includes("application/json")) {
|
|
32
|
+
data = await response.json()
|
|
33
|
+
} else if (type.includes("text/")) {
|
|
34
|
+
data = await response.text()
|
|
35
|
+
} else {
|
|
36
|
+
data = await response.blob()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw {
|
|
41
|
+
status: response.status,
|
|
42
|
+
statusText: response.statusText,
|
|
43
|
+
data
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return data
|
|
48
|
+
} finally {
|
|
49
|
+
clearTimeout(timeout)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get(url, options = {}) {
|
|
54
|
+
return this.request(url, {
|
|
55
|
+
...options,
|
|
56
|
+
method: "GET"
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
post(url, body, options = {}) {
|
|
61
|
+
return this.request(url, {
|
|
62
|
+
...options,
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
...options.headers
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body)
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
put(url, body, options = {}) {
|
|
73
|
+
return this.request(url, {
|
|
74
|
+
...options,
|
|
75
|
+
method: "PUT",
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
...options.headers
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify(body)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
patch(url, body, options = {}) {
|
|
85
|
+
return this.request(url, {
|
|
86
|
+
...options,
|
|
87
|
+
method: "PATCH",
|
|
88
|
+
headers: {
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
...options.headers
|
|
91
|
+
},
|
|
92
|
+
body: JSON.stringify(body)
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
delete(url, options = {}) {
|
|
97
|
+
return this.request(url, {
|
|
98
|
+
...options,
|
|
99
|
+
method: "DELETE"
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
use * as crypto from "node:crypto"
|
|
2
|
+
use { SHA256, QuickHash } from @slim/types/hash
|
|
3
|
+
|
|
4
|
+
export default const StringHelper: object = {
|
|
5
|
+
len(str: string): int {
|
|
6
|
+
if(kindof str == "string") return str.length
|
|
7
|
+
},
|
|
8
|
+
truncate(str: string, maxLength: int): string {
|
|
9
|
+
if (str.length > maxLength) {
|
|
10
|
+
return str.slice(0, maxLength) + '...';
|
|
11
|
+
}
|
|
12
|
+
return str;
|
|
13
|
+
},
|
|
14
|
+
hash(str: string): SHA256 {
|
|
15
|
+
return crypto.createHash("sha256").update(str).digest("hex")
|
|
16
|
+
},
|
|
17
|
+
quickHash(str: string): QuickHash {
|
|
18
|
+
let hash = 0;
|
|
19
|
+
for (let i = 0; i < str.length; i++) {
|
|
20
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
21
|
+
hash |= 0;
|
|
22
|
+
}
|
|
23
|
+
return hash;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lock StringHelper;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
use { readFile } from 'fs/promises';
|
|
2
|
+
use { join } from 'path';
|
|
3
|
+
|
|
4
|
+
use { SemVer } from @slim/types/formats
|
|
5
|
+
|
|
6
|
+
export struct Slim {
|
|
7
|
+
version?: SemVer | undefined = undefined
|
|
8
|
+
rootDir?: string = undefined
|
|
9
|
+
workDir?: string = undefined
|
|
10
|
+
}
|
|
11
|
+
export struct SlimConfig {
|
|
12
|
+
workDir: string | undefined = undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async func getPackageData(): object {
|
|
16
|
+
try {
|
|
17
|
+
const filePath = join(process.cwd(), 'package.json');
|
|
18
|
+
const fileContent = await readFile(filePath, 'utf-8');
|
|
19
|
+
|
|
20
|
+
const packageData = JSON.parse(fileContent);
|
|
21
|
+
return Slim.new({ version: packageData.version, rootDir: process.cwd(), workDir: packageData.main })
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return Slim.new({})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async func getConfigData(): object {
|
|
28
|
+
try {
|
|
29
|
+
const filePath = join(process.cwd(), 'slimconfig.json');
|
|
30
|
+
const fileContent = await readFile(filePath, 'utf-8');
|
|
31
|
+
|
|
32
|
+
const packageData = JSON.parse(fileContent);
|
|
33
|
+
return SlimConfig.new({ workDir: packageData.main })
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return SlimConfig.new({})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async func getVersion(): SemVer {
|
|
40
|
+
const pkg = await getPackageData()
|
|
41
|
+
return pkg.version
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
use fs from "node:fs/promises"
|
|
2
|
+
use path from "node:path"
|
|
3
|
+
|
|
4
|
+
export class ReadError extends Error {}
|
|
5
|
+
|
|
6
|
+
export async func parseJSON(fpath: string): object {
|
|
7
|
+
try {
|
|
8
|
+
const filePath: string = path.join(fpath);
|
|
9
|
+
const data: string = await fs.readFile(filePath, 'utf8');
|
|
10
|
+
|
|
11
|
+
return JSON.parse(data)
|
|
12
|
+
} catch (err) {
|
|
13
|
+
throw new ReadError(err)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async func parseText(fpath: string): string {
|
|
17
|
+
try {
|
|
18
|
+
const filePath: string = path.join(fpath);
|
|
19
|
+
const data: string = await fs.readFile(filePath, 'utf8');
|
|
20
|
+
|
|
21
|
+
return data
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw new ReadError(err)
|
|
24
|
+
}
|
|
25
|
+
}
|