Skip to content

Commit

Permalink
Make formatting similar to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Nov 20, 2024
1 parent 819d3bf commit f33ca2f
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 56 deletions.
31 changes: 31 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 1,31 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"trailingCommas": "es5"
}
}
}
10 changes: 5 additions & 5 deletions lib/gpx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 58,7 @@ function getRoute(ns: NS, node: Element): Feature<LineString> | undefined {
properties: Object.assign(
{ _gpxType: "rte" },
extractProperties(ns, node),
getLineStyle(get1(node, "extensions")),
getLineStyle(get1(node, "extensions"))
),
geometry: {
type: "LineString",
Expand All @@ -69,7 69,7 @@ function getRoute(ns: NS, node: Element): Feature<LineString> | undefined {

function getTrack(
ns: NS,
node: Element,
node: Element
): Feature<LineString | MultiLineString> | null {
const segments = $(node, "trkseg");
const track = [];
Expand Down Expand Up @@ -98,7 98,7 @@ function getTrack(
times: multi ? times : times[0],
},
}
: {},
: {}
);

for (const line of extractedLines) {
Expand All @@ -113,7 113,7 @@ function getTrack(
if (multi) {
if (!props[name]) {
props[name] = extractedLines.map((line) =>
new Array(line.line.length).fill(null),
new Array(line.line.length).fill(null)
);
}
props[name][i] = val;
Expand Down Expand Up @@ -145,7 145,7 @@ function getTrack(
function getPoint(ns: NS, node: Element): Feature<Point> | null {
const properties: Feature["properties"] = Object.assign(
extractProperties(ns, node),
getMulti(node, ["sym"]),
getMulti(node, ["sym"])
);
const pair = coordPair(node);
if (!pair) return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/gpx/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ export function getLineStyle(node: Element | null) {
$num(lineStyle, "width", (width) => {
// GPX width is in mm, convert to px with 96 px per inch
return { "stroke-width": (width * 96) / 25.4 };
}),
})
);
return val;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/gpx/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 21,8 @@ export function extractProperties(ns: NS, node: Element) {
properties.links = links.map((link) =>
Object.assign(
{ href: link.getAttribute("href") },
getMulti(link, ["text", "type"]),
),
getMulti(link, ["text", "type"])
)
);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,7 @@ describe("toGeoJSON", () => {
expect(
tj.kmlWithFolders(dom, {
skipNullGeometry: true,
}),
})
).toMatchSnapshot();
}
});
Expand All @@ -42,17 42,17 @@ describe("mini cases", () => {
expect(
tj.kml(parse(path.join(d, "null_geometry.kml")), {
skipNullGeometry: true,
}).features,
}).features
).toHaveLength(0);
expect(
tj.kml(parse(path.join(d, "null_geometry.kml")), {
skipNullGeometry: false,
}).features,
}).features
).toHaveLength(1);
});
it("folder nesting", () => {
expect(
tj.kmlWithFolders(parse(path.join(d, "inline_style_mini.kml"))),
tj.kmlWithFolders(parse(path.join(d, "inline_style_mini.kml")))
).toMatchInlineSnapshot(`
{
"children": [
Expand Down
8 changes: 4 additions & 4 deletions lib/kml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 178,7 @@ export function kmlWithFolders(
node: Document,
options: KMLOptions = {
skipNullGeometry: false,
},
}
): Root {
const styleMap = buildStyleMap(node);
const schema = buildSchema(node);
Expand All @@ -192,7 192,7 @@ export function kmlWithFolders(
function traverse(
node: Document | ChildNode | Element,
pointer: TreeContainer,
options: KMLOptions,
options: KMLOptions
) {
if (isElement(node)) {
switch (node.tagName) {
Expand Down Expand Up @@ -242,7 242,7 @@ export function* kmlGen(
node: Document,
options: KMLOptions = {
skipNullGeometry: false,
},
}
): Generator<F> {
const styleMap = buildStyleMap(node);
const schema = buildSchema(node);
Expand Down Expand Up @@ -270,7 270,7 @@ export function kml(
node: Document,
options: KMLOptions = {
skipNullGeometry: false,
},
}
): FeatureCollection<Geometry | null> {
return {
type: "FeatureCollection",
Expand Down
8 changes: 4 additions & 4 deletions lib/kml/extractStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 29,8 @@ describe("extractStyle", () => {
<BalloonStyle>
<displayMode>hide</displayMode>
</BalloonStyle>
</Style>`),
),
</Style>`)
)
).toMatchInlineSnapshot(`
{
"fill": "#ffee58",
Expand Down Expand Up @@ -68,8 68,8 @@ describe("extractStyle", () => {
<BalloonStyle>
<text><![CDATA[<h3>$[name]</h3>]]></text>
</BalloonStyle>
</Style>`),
),
</Style>`)
)
).toMatchInlineSnapshot(`
{
"icon": "https://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png",
Expand Down
10 changes: 5 additions & 5 deletions lib/kml/extractStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 40,7 @@ export function extractIcon(node: Element) {
};
return {};
}),
extractIconHref(iconStyle),
extractIconHref(iconStyle)
);
});
}
Expand All @@ -49,7 49,7 @@ export function extractLabel(node: Element) {
return get(node, "LabelStyle", (labelStyle) => {
return Object.assign(
getColor(labelStyle, "label"),
numericProperty(labelStyle, "scale", "label-scale"),
numericProperty(labelStyle, "scale", "label-scale")
);
});
}
Expand All @@ -58,7 58,7 @@ export function extractLine(node: Element) {
return get(node, "LineStyle", (lineStyle) => {
return Object.assign(
getColor(lineStyle, "stroke"),
numericProperty(lineStyle, "width", "stroke-width"),
numericProperty(lineStyle, "width", "stroke-width")
);
});
}
Expand All @@ -73,7 73,7 @@ export function extractPoly(node: Element) {
}),
val1(polyStyle, "outline", (outline) => {
if (outline === "0") return { "stroke-opacity": 0 };
}),
})
);
});
}
Expand All @@ -84,6 84,6 @@ export function extractStyle(node: Element) {
extractPoly(node),
extractLine(node),
extractLabel(node),
extractIcon(node),
extractIcon(node)
);
}
4 changes: 2 additions & 2 deletions lib/kml/geometry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,7 @@ describe("fixRing", () => {
[1, 2],
[3, 4],
[5, 6],
]),
])
).toEqual([
[1, 2],
[3, 4],
Expand All @@ -47,7 47,7 @@ describe("fixRing", () => {
[3, 4],
[5, 6],
[1, 2],
]),
])
).toEqual([
[1, 2],
[3, 4],
Expand Down
2 changes: 1 addition & 1 deletion lib/kml/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,7 @@ export function coord(value: string): Position[] {
}

function gxCoords(
node: Element,
node: Element
): { geometry: Point | LineString; times: string[] } | null {
let elems = $(node, "coord");
if (elems.length === 0) {
Expand Down
6 changes: 3 additions & 3 deletions lib/kml/ground_overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 40,7 @@ const DEGREES_TO_RADIANS = Math.PI / 180;
function rotateBox(
bbox: BBox,
coordinates: Polygon["coordinates"],
rotation: number,
rotation: number
): Polygon["coordinates"] {
const center = [(bbox[0] bbox[2]) / 2, (bbox[1] bbox[3]) / 2];

Expand Down Expand Up @@ -105,7 105,7 @@ export function getGroundOverlay(
node: Element,
styleMap: StyleMap,
schema: Schema,
options: KMLOptions,
options: KMLOptions
): Feature<Polygon | null> | null {
const box = getGroundOverlayBox(node);

Expand Down Expand Up @@ -138,7 138,7 @@ export function getGroundOverlay(
extractIconHref(node),
extractExtendedData(node, schema),
extractTimeSpan(node),
extractTimeStamp(node),
extractTimeStamp(node)
),
};

Expand Down
4 changes: 2 additions & 2 deletions lib/kml/placemark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,7 @@ export function getPlacemark(
node: Element,
styleMap: StyleMap,
schema: Schema,
options: KMLOptions,
options: KMLOptions
): Feature<Geometry | null> | null {
const { coordTimes, geometries } = getGeometry(node);

Expand Down Expand Up @@ -61,7 61,7 @@ export function getPlacemark(
times: coordTimes.length === 1 ? coordTimes[0] : coordTimes,
},
}
: {},
: {}
),
};

Expand Down
2 changes: 1 addition & 1 deletion lib/kml/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 28,7 @@ export function extractExtendedData(node: Element, schema: Schema) {
return get(node, "ExtendedData", (extendedData, properties) => {
for (const data of $(extendedData, "Data")) {
properties[data.getAttribute("name") || ""] = nodeVal(
get1(data, "value"),
get1(data, "value")
);
}
for (const simpleData of $(extendedData, "SimpleData")) {
Expand Down
12 changes: 6 additions & 6 deletions lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,7 @@ export function normalizeId(id: string) {
export function $ns(
element: Element | Document,
tagName: string,
ns: string,
ns: string
): Element[] {
return Array.from(element.getElementsByTagNameNS(ns, tagName));
}
Expand All @@ -37,7 37,7 @@ export function nodeVal(node: Element | null) {
export function get1(
node: Element,
tagName: string,
callback?: (elem: Element) => unknown,
callback?: (elem: Element) => unknown
) {
const n = node.getElementsByTagName(tagName);
const result = n.length ? n[0] : null;
Expand All @@ -48,7 48,7 @@ export function get1(
export function get(
node: Element | null,
tagName: string,
callback?: (elem: Element, properties: P) => P,
callback?: (elem: Element, properties: P) => P
) {
const properties: Feature["properties"] = {};
if (!node) return properties;
Expand All @@ -63,7 63,7 @@ export function get(
export function val1(
node: Element,
tagName: string,
callback: (val: string) => P | void,
callback: (val: string) => P | void
): P {
const val = nodeVal(get1(node, tagName));
if (val && callback) return callback(val) || {};
Expand All @@ -73,7 73,7 @@ export function val1(
export function $num(
node: Element,
tagName: string,
callback: (val: number) => Feature["properties"],
callback: (val: number) => Feature["properties"]
) {
const val = parseFloat(nodeVal(get1(node, tagName)));
if (isNaN(val)) return undefined;
Expand All @@ -84,7 84,7 @@ export function $num(
export function num1(
node: Element,
tagName: string,
callback?: (val: number) => unknown,
callback?: (val: number) => unknown
) {
const val = parseFloat(nodeVal(get1(node, tagName)));
if (isNaN(val)) return undefined;
Expand Down
6 changes: 3 additions & 3 deletions lib/tcx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 113,7 @@ function getLap(node: Element): Feature | null {
Object.fromEntries(getProperties(node, LAP_ATTRIBUTES)),
get(node, "Name", (nameElement) => {
return { name: nodeVal(nameElement) };
}),
})
);

for (const segment of segments) {
Expand All @@ -135,7 135,7 @@ function getLap(node: Element): Feature | null {
} else {
if (!properties[property]) {
properties[property] = track.map((track) =>
Array(track.length).fill(null),
Array(track.length).fill(null)
);
}
properties[property][i] = extendedProperties[property];
Expand All @@ -156,7 156,7 @@ function getLap(node: Element): Feature | null {
? {
heart: track.length === 1 ? heartRates[0] : heartRates,
}
: {},
: {}
);
}

Expand Down
Loading

0 comments on commit f33ca2f

Please sign in to comment.