Skip to content

Invalid result from checking parsedTLE against "isTLEObj" #33

Closed
@muitdebos

Description

@muitdebos

In /src/index.d.ts, ParsedTLE is defined as having tle, a two-element array, and optionally a name.

    /**
     * Output of parseTLE().  TLE normalized into a predictable format for fast lookups.
     */
    export interface ParsedTLE {
        /**
         * Satellite name (only extracted from 3-line TLE inputs).
         * @default "Unknown"
         */
        name?: string,
        /** Two-line TLE. */
        tle: [TLELine, TLELine]
    }

However, in /src/parsing.js, the function isTLEObj checks if the parsed TLE object has a name and returns false if it doesn't.

export function isTLEObj(obj) {
	return (
		typeof obj === _DATA_TYPES._OBJECT &&
		obj.name &&
		obj.tle &&
		getType(obj.tle) === _DATA_TYPES._ARRAY &&
		obj.tle.length === 2
	);
}

This is a discrepancy between the two, which became an issue for me when using an unnamed TLE in getGroundTracks. Namely, getGroundTracks parses the TLE using parseTLE(), however because my provided TLE is a 2-line one, it returns an object without name property ({ tle: [..., ...] }) which is a valid TLE according to the type definition but not according to the isTLEObj() checker. Thus getGroundTracks returns an error.

This seems like an easy fix, but not sure what is the desired solution. My suggestion would be to have parseTLE() always return an object with both name and tle properties, and make ParsedTLE type definition have name not as optional but as required. Alternatively I'd suggest to change the isTLEObj check for obj.name. At the moment this also returns false if name is an empty string. However I can't foresee if either of these would create issues for others.

I can open a PR with that fix if desired. For now a workaround would be to write my own ParseTLE that just appends the name property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions