@idfkit/core 0.0.1
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/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/collection.d.ts +48 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +100 -0
- package/dist/collection.js.map +1 -0
- package/dist/document.d.ts +100 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +0 -0
- package/dist/document.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +25 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +25 -0
- package/dist/internal.js.map +1 -0
- package/dist/node.d.ts +40 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +70 -0
- package/dist/node.js.map +1 -0
- package/dist/object.d.ts +114 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +224 -0
- package/dist/object.js.map +1 -0
- package/dist/parse/epjson.d.ts +16 -0
- package/dist/parse/epjson.d.ts.map +1 -0
- package/dist/parse/epjson.js +91 -0
- package/dist/parse/epjson.js.map +1 -0
- package/dist/parse/idf.d.ts +44 -0
- package/dist/parse/idf.d.ts.map +1 -0
- package/dist/parse/idf.js +170 -0
- package/dist/parse/idf.js.map +1 -0
- package/dist/parse/lexer.d.ts +37 -0
- package/dist/parse/lexer.d.ts.map +1 -0
- package/dist/parse/lexer.js +105 -0
- package/dist/parse/lexer.js.map +1 -0
- package/dist/references.d.ts +56 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +147 -0
- package/dist/references.js.map +1 -0
- package/dist/shape.d.ts +54 -0
- package/dist/shape.d.ts.map +1 -0
- package/dist/shape.js +114 -0
- package/dist/shape.js.map +1 -0
- package/dist/typemap.d.ts +43 -0
- package/dist/typemap.d.ts.map +1 -0
- package/dist/typemap.js +18 -0
- package/dist/typemap.js.map +1 -0
- package/dist/types/v26-1.d.ts +65896 -0
- package/dist/types/v26-1.d.ts.map +1 -0
- package/dist/types/v26-1.js +5 -0
- package/dist/types/v26-1.js.map +1 -0
- package/dist/types/v9-4.d.ts +61414 -0
- package/dist/types/v9-4.d.ts.map +1 -0
- package/dist/types/v9-4.js +5 -0
- package/dist/types/v9-4.js.map +1 -0
- package/dist/versions.d.ts +17 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +34 -0
- package/dist/versions.js.map +1 -0
- package/dist/write/epjson.d.ts +15 -0
- package/dist/write/epjson.d.ts.map +1 -0
- package/dist/write/epjson.js +10 -0
- package/dist/write/epjson.js.map +1 -0
- package/dist/write/idf.d.ts +47 -0
- package/dist/write/idf.d.ts.map +1 -0
- package/dist/write/idf.js +149 -0
- package/dist/write/idf.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v9-4.js","sourceRoot":"","sources":["../../src/types/v9-4.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4DAA4D;AAI5D,oDAAoD;AACpD,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Numeric sort key. Plain string sort puts 8.9.0 after 22.1.0. */
|
|
2
|
+
export declare function versionKey(version: string): number;
|
|
3
|
+
/** Compare two version strings. */
|
|
4
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
5
|
+
/**
|
|
6
|
+
* Pick the bundled schema version to use for a version read from a file.
|
|
7
|
+
*
|
|
8
|
+
* IDF files write `Version, 9.0;` while schemas are keyed `9.0.1`, so an exact
|
|
9
|
+
* match often fails on the patch component. Matching on major.minor first is
|
|
10
|
+
* what makes "support every version" actually work against real files rather
|
|
11
|
+
* than only against files whose patch number happens to line up.
|
|
12
|
+
*
|
|
13
|
+
* Returns undefined rather than guessing when there is no match at all;
|
|
14
|
+
* silently loading the wrong schema would mis-map every positional field.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveVersion(detected: string, available: readonly string[]): string | undefined;
|
|
17
|
+
//# sourceMappingURL=versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED,mCAAmC;AACnC,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAYjG"}
|
package/dist/versions.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Numeric sort key. Plain string sort puts 8.9.0 after 22.1.0. */
|
|
2
|
+
export function versionKey(version) {
|
|
3
|
+
const [major = 0, minor = 0, patch = 0] = version.split('.').map(Number);
|
|
4
|
+
return major * 1_000_000 + minor * 1_000 + patch;
|
|
5
|
+
}
|
|
6
|
+
/** Compare two version strings. */
|
|
7
|
+
export function compareVersions(a, b) {
|
|
8
|
+
return versionKey(a) - versionKey(b);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Pick the bundled schema version to use for a version read from a file.
|
|
12
|
+
*
|
|
13
|
+
* IDF files write `Version, 9.0;` while schemas are keyed `9.0.1`, so an exact
|
|
14
|
+
* match often fails on the patch component. Matching on major.minor first is
|
|
15
|
+
* what makes "support every version" actually work against real files rather
|
|
16
|
+
* than only against files whose patch number happens to line up.
|
|
17
|
+
*
|
|
18
|
+
* Returns undefined rather than guessing when there is no match at all;
|
|
19
|
+
* silently loading the wrong schema would mis-map every positional field.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveVersion(detected, available) {
|
|
22
|
+
if (available.includes(detected))
|
|
23
|
+
return detected;
|
|
24
|
+
const [major, minor] = detected.split('.').map(Number);
|
|
25
|
+
const sameMinor = available.filter((candidate) => {
|
|
26
|
+
const [cMajor, cMinor] = candidate.split('.').map(Number);
|
|
27
|
+
return cMajor === major && cMinor === minor;
|
|
28
|
+
});
|
|
29
|
+
if (sameMinor.length > 0) {
|
|
30
|
+
return sameMinor.sort(compareVersions).at(-1);
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.js","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzE,OAAO,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AACnD,CAAC;AAED,mCAAmC;AACnC,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,SAA4B;IAC3E,IAAI,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAElD,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1D,OAAO,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,KAAK,CAAC;IAC9C,CAAC,CAAC,CAAC;IACH,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IDFDocument } from '../document.js';
|
|
2
|
+
import type { AnyTypeMap } from '../typemap.js';
|
|
3
|
+
import type { EpJson } from '../parse/epjson.js';
|
|
4
|
+
export interface WriteEpJsonOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Indent width. `0` emits compact JSON.
|
|
7
|
+
* @defaultValue 2
|
|
8
|
+
*/
|
|
9
|
+
indent?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Serialize a document to epJSON text. */
|
|
12
|
+
export declare function writeEpJson<M extends AnyTypeMap>(document: IDFDocument<M>, options?: WriteEpJsonOptions): string;
|
|
13
|
+
/** Serialize a document to a plain epJSON object. */
|
|
14
|
+
export declare function toEpJson<M extends AnyTypeMap>(document: IDFDocument<M>): EpJson;
|
|
15
|
+
//# sourceMappingURL=epjson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epjson.d.ts","sourceRoot":"","sources":["../../src/write/epjson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,2CAA2C;AAC3C,wBAAgB,WAAW,CAAC,CAAC,SAAS,UAAU,EAC9C,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,EACxB,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAGR;AAED,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Serialize a document to epJSON text. */
|
|
2
|
+
export function writeEpJson(document, options = {}) {
|
|
3
|
+
const indent = options.indent ?? 2;
|
|
4
|
+
return JSON.stringify(document.toJSON(), null, indent);
|
|
5
|
+
}
|
|
6
|
+
/** Serialize a document to a plain epJSON object. */
|
|
7
|
+
export function toEpJson(document) {
|
|
8
|
+
return document.toJSON();
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=epjson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epjson.js","sourceRoot":"","sources":["../../src/write/epjson.ts"],"names":[],"mappings":"AAYA,2CAA2C;AAC3C,MAAM,UAAU,WAAW,CACzB,QAAwB,EACxB,UAA8B,EAAE;IAEhC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,QAAQ,CAAuB,QAAwB;IACrE,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { IDFDocument } from '../document.js';
|
|
2
|
+
import type { AnyTypeMap } from '../typemap.js';
|
|
3
|
+
import type { IdfObject } from '../object.js';
|
|
4
|
+
export interface WriteIdfOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Emit `!- Field Name` comments after each field.
|
|
7
|
+
* @defaultValue true
|
|
8
|
+
*/
|
|
9
|
+
comments?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Column the field-name comments are aligned to.
|
|
12
|
+
* @defaultValue 30
|
|
13
|
+
*/
|
|
14
|
+
commentColumn?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Indent for field lines.
|
|
17
|
+
* @defaultValue ' '
|
|
18
|
+
*/
|
|
19
|
+
indent?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Write `Version` first regardless of insertion order. EnergyPlus does not
|
|
22
|
+
* require it, but every tool in the ecosystem expects it and diffs are
|
|
23
|
+
* cleaner when it is stable.
|
|
24
|
+
* @defaultValue true
|
|
25
|
+
*/
|
|
26
|
+
versionFirst?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serialize a document to IDF text.
|
|
30
|
+
*
|
|
31
|
+
* One caveat worth stating plainly: this does not round-trip formatting.
|
|
32
|
+
* `3.0` in the input comes back as `3`, because JavaScript has a single number
|
|
33
|
+
* type and the distinction is lost the moment the value is parsed. The models
|
|
34
|
+
* are semantically identical and EnergyPlus reads both, but a textual diff of
|
|
35
|
+
* input against output will show those fields. Preserving the original text
|
|
36
|
+
* needs a concrete syntax tree, which the Python library has and this does not
|
|
37
|
+
* yet.
|
|
38
|
+
*/
|
|
39
|
+
export declare function writeIdf<M extends AnyTypeMap>(document: IDFDocument<M>, options?: WriteIdfOptions): string;
|
|
40
|
+
export interface ObjectWriteOptions {
|
|
41
|
+
comments: boolean;
|
|
42
|
+
commentColumn: number;
|
|
43
|
+
indent: string;
|
|
44
|
+
}
|
|
45
|
+
/** Serialize one object. */
|
|
46
|
+
export declare function writeObject(obj: IdfObject, options: ObjectWriteOptions): string;
|
|
47
|
+
//# sourceMappingURL=idf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idf.d.ts","sourceRoot":"","sources":["../../src/write/idf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,UAAU,EAC3C,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,EACxB,OAAO,GAAE,eAAoB,GAC5B,MAAM,CAwBR;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4BAA4B;AAC5B,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAkD/E"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a document to IDF text.
|
|
3
|
+
*
|
|
4
|
+
* One caveat worth stating plainly: this does not round-trip formatting.
|
|
5
|
+
* `3.0` in the input comes back as `3`, because JavaScript has a single number
|
|
6
|
+
* type and the distinction is lost the moment the value is parsed. The models
|
|
7
|
+
* are semantically identical and EnergyPlus reads both, but a textual diff of
|
|
8
|
+
* input against output will show those fields. Preserving the original text
|
|
9
|
+
* needs a concrete syntax tree, which the Python library has and this does not
|
|
10
|
+
* yet.
|
|
11
|
+
*/
|
|
12
|
+
export function writeIdf(document, options = {}) {
|
|
13
|
+
const comments = options.comments ?? true;
|
|
14
|
+
const commentColumn = options.commentColumn ?? 30;
|
|
15
|
+
const indent = options.indent ?? ' ';
|
|
16
|
+
const versionFirst = options.versionFirst ?? true;
|
|
17
|
+
const parts = [];
|
|
18
|
+
const types = document.types();
|
|
19
|
+
if (versionFirst && types.includes('Version')) {
|
|
20
|
+
types.splice(types.indexOf('Version'), 1);
|
|
21
|
+
types.unshift('Version');
|
|
22
|
+
}
|
|
23
|
+
for (const typeName of types) {
|
|
24
|
+
const collection = document.all(typeName);
|
|
25
|
+
if (collection.size === 0)
|
|
26
|
+
continue;
|
|
27
|
+
for (const obj of collection) {
|
|
28
|
+
parts.push(writeObject(obj, { comments, commentColumn, indent }));
|
|
29
|
+
}
|
|
30
|
+
parts.push('');
|
|
31
|
+
}
|
|
32
|
+
return parts.join('\n');
|
|
33
|
+
}
|
|
34
|
+
/** Serialize one object. */
|
|
35
|
+
export function writeObject(obj, options) {
|
|
36
|
+
const definition = obj.schema;
|
|
37
|
+
const cells = [];
|
|
38
|
+
if (obj.isNamed) {
|
|
39
|
+
cells.push({ value: obj.name, label: 'Name' });
|
|
40
|
+
}
|
|
41
|
+
const extensible = definition.x;
|
|
42
|
+
const groups = extensible === undefined ? [] : obj.extensible;
|
|
43
|
+
const fixed = definition.f.filter((f) => f !== 'name');
|
|
44
|
+
// Trailing empty fields are normally dropped, since EnergyPlus defaults them
|
|
45
|
+
// and a run of bare commas is noise. But IDF is positional: if extensible
|
|
46
|
+
// groups follow, every fixed slot must be emitted or the groups land one
|
|
47
|
+
// field early and each value is read into the wrong slot on the way back in.
|
|
48
|
+
const lastFixed = groups.length > 0 ? fixed.length - 1 : lastSetIndex(obj, fixed);
|
|
49
|
+
for (let i = 0; i <= lastFixed; i += 1) {
|
|
50
|
+
const field = fixed[i];
|
|
51
|
+
cells.push({ value: formatValue(definition, field, obj.get(field)), label: humanize(field) });
|
|
52
|
+
}
|
|
53
|
+
if (extensible !== undefined) {
|
|
54
|
+
for (const group of groups) {
|
|
55
|
+
for (const field of extensible.fields) {
|
|
56
|
+
cells.push({
|
|
57
|
+
value: formatScalar(extensible.p[field]?.t, group[field]),
|
|
58
|
+
label: humanize(field),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const lines = [`${obj.typeName},`];
|
|
64
|
+
if (cells.length === 0) {
|
|
65
|
+
return `${obj.typeName};\n`;
|
|
66
|
+
}
|
|
67
|
+
cells.forEach((cell, index) => {
|
|
68
|
+
const terminator = index === cells.length - 1 ? ';' : ',';
|
|
69
|
+
const body = `${options.indent}${cell.value}${terminator}`;
|
|
70
|
+
if (!options.comments) {
|
|
71
|
+
lines.push(body);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const padding = ' '.repeat(Math.max(1, options.commentColumn - body.length));
|
|
75
|
+
lines.push(`${body}${padding}!- ${cell.label}`);
|
|
76
|
+
});
|
|
77
|
+
return `${lines.join('\n')}\n`;
|
|
78
|
+
}
|
|
79
|
+
function lastSetIndex(obj, fields) {
|
|
80
|
+
for (let i = fields.length - 1; i >= 0; i -= 1) {
|
|
81
|
+
if (obj.get(fields[i]) !== undefined)
|
|
82
|
+
return i;
|
|
83
|
+
}
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
function formatValue(definition, field, value) {
|
|
87
|
+
return formatScalar(definition.p[field]?.t, value);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Render one value as IDF text.
|
|
91
|
+
*
|
|
92
|
+
* The `kind === 'n'` branch is the fix for JavaScript having a single number
|
|
93
|
+
* type: `3` and `3.0` are the same value at runtime, so without consulting the
|
|
94
|
+
* schema every real-valued field would be written as a bare integer.
|
|
95
|
+
*/
|
|
96
|
+
function formatScalar(kind, value) {
|
|
97
|
+
if (value === undefined || Array.isArray(value))
|
|
98
|
+
return '';
|
|
99
|
+
if (typeof value === 'string')
|
|
100
|
+
return value;
|
|
101
|
+
if (kind === 'i')
|
|
102
|
+
return String(Math.trunc(value));
|
|
103
|
+
if (Number.isInteger(value)) {
|
|
104
|
+
return kind === 'n' ? `${value}.0` : String(value);
|
|
105
|
+
}
|
|
106
|
+
return String(value);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Minor words EnergyPlus leaves lowercase in its own field comments, as in
|
|
110
|
+
* `Direction of Relative North` and `Number of Timesteps per Hour`.
|
|
111
|
+
*/
|
|
112
|
+
const MINOR_WORDS = new Set([
|
|
113
|
+
'a',
|
|
114
|
+
'an',
|
|
115
|
+
'and',
|
|
116
|
+
'at',
|
|
117
|
+
'by',
|
|
118
|
+
'for',
|
|
119
|
+
'from',
|
|
120
|
+
'in',
|
|
121
|
+
'of',
|
|
122
|
+
'on',
|
|
123
|
+
'or',
|
|
124
|
+
'per',
|
|
125
|
+
'the',
|
|
126
|
+
'to',
|
|
127
|
+
'with',
|
|
128
|
+
]);
|
|
129
|
+
/**
|
|
130
|
+
* `outside_boundary_condition` -> `Outside Boundary Condition`.
|
|
131
|
+
*
|
|
132
|
+
* The exact IDD field labels live in the schema's `field_info`, which the slim
|
|
133
|
+
* bundle drops because it is documentation weight on the parse path. Deriving
|
|
134
|
+
* the label from the epJSON key recovers it almost exactly; the comments are
|
|
135
|
+
* cosmetic and EnergyPlus ignores them entirely.
|
|
136
|
+
*/
|
|
137
|
+
function humanize(field) {
|
|
138
|
+
return field
|
|
139
|
+
.split('_')
|
|
140
|
+
.map((word, index) => {
|
|
141
|
+
if (word.length === 0)
|
|
142
|
+
return word;
|
|
143
|
+
if (index > 0 && MINOR_WORDS.has(word))
|
|
144
|
+
return word;
|
|
145
|
+
return word[0].toUpperCase() + word.slice(1);
|
|
146
|
+
})
|
|
147
|
+
.join(' ');
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=idf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idf.js","sourceRoot":"","sources":["../../src/write/idf.ts"],"names":[],"mappings":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GAOG;AACH,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,IAAI,KAAK,GAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACpD,OAAO,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idfkit/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Fast EnergyPlus IDF and epJSON parsing and manipulation for JavaScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Samuel Letellier-Duchesne <developers@idfkit.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/idfkit/idfkit-js.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://js.idfkit.com/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/idfkit/idfkit-js/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"energyplus",
|
|
19
|
+
"idf",
|
|
20
|
+
"epjson",
|
|
21
|
+
"building-energy",
|
|
22
|
+
"simulation"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./node": {
|
|
30
|
+
"types": "./dist/node.d.ts",
|
|
31
|
+
"default": "./dist/node.js"
|
|
32
|
+
},
|
|
33
|
+
"./types/*": {
|
|
34
|
+
"types": "./dist/types/*.d.ts",
|
|
35
|
+
"default": "./dist/types/*.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@idfkit/schemas": "0.0.1"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc --build",
|
|
53
|
+
"codegen": "node scripts/emit-types.mjs"
|
|
54
|
+
}
|
|
55
|
+
}
|