node-libpng
Version:
Unofficial bindings for node to libpng.
42 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isXY = exports.xy = void 0;
/**
* Creates a new set of 2D coordinates.
*
* @param x The x part of the coordinates.
* @param y The y part of the coordinates.
*
* @return The new coordinates as an array which provides getters for `x` and `y`.
*/
function xy(x, y) {
const coordinates = [x, y];
Object.defineProperty(coordinates, "x", { get() { return this[0]; } });
Object.defineProperty(coordinates, "y", { get() { return this[1]; } });
return coordinates;
}
exports.xy = xy;
/**
* Checks if the given parameter is a set of 2D coordinates.
*
* @param coordinates Parameter to check.
*
* @return `true` if the given parameter was a set of coordinates and `false` otherwise.
*/
function isXY(coordinates) {
if (typeof coordinates !== "object" || !Array.isArray(coordinates)) {
return false;
}
if (coordinates.length !== 2) {
return false;
}
if (typeof coordinates.x !== "number") {
return false;
}
if (typeof coordinates.y !== "number") {
return false;
}
return true;
}
exports.isXY = isXY;
//# sourceMappingURL=xy.js.map