Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gpx-for-runners

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gpx-for-runners - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

58

lib/gpx.js

@@ -96,3 +96,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

/**
* Object of all trackpointns in the gpx DOM.
* Object of all trackpoints in the gpx DOM.
* @member GPX#trkpts

@@ -103,9 +103,9 @@ */

/**
* All trackpointns as an Array
* @member GPX#trackpointns
* All trackpoints as an Array
* @member GPX#trackpoints
*/
this.trackpointns = this.createJsonFromGpxDom();
this.trackpoints = this.createJsonFromGpxDom();
if (this.trackpointns.length === 0) {
throw new Error('This file has no trackpointns (trkpt)');
if (this.trackpoints.length === 0) {
throw new Error('This file has no trackpoints (trkpt)');
}

@@ -131,6 +131,6 @@ }

value: function createJsonFromGpxDom() {
var trackpointns = [];
var trackpoints = [];
for (var trkpt = 0; trkpt < this.trkpts.length; trkpt++) {
trackpointns.push({
trackpoints.push({
lon: parseFloat(this.trkpts[trkpt].getAttribute('lon')),

@@ -143,3 +143,3 @@ lat: parseFloat(this.trkpts[trkpt].getAttribute('lat')),

return trackpointns;
return trackpoints;
}

@@ -164,4 +164,4 @@

value: function duration() {
var start = new Date(this.trackpointns[0].time),
end = new Date(this.trackpointns[this.trackpointns.length - 1].time),
var start = new Date(this.trackpoints[0].time),
end = new Date(this.trackpoints[this.trackpoints.length - 1].time),
timeDiff = Math.abs(end.getTime() - start.getTime()),

@@ -230,6 +230,16 @@ total = this.millisecondsToTime(timeDiff);

/**
* Returns elevation of the run
* @return {object} elevation (time, dist, elevation), max, min, loss, gain
* @typedef Elevation
* @type Object
* @property {object} elevation The minutes part of the pace time.
* @property {number} max The max elevation of the route.
* @property {number} min The min elevation of the route.
* @property {number} gain Elevation gained during run.
* @property {number} loss Elevation lost during run.
*/
/**
* Returns elevation info of the run
* @return {Elevation} The Elevation information object
*/
}, {

@@ -242,11 +252,11 @@ key: 'elevation',

loss = 0,
startTime = new Date(this.trackpointns[0].time).getTime(),
startTime = new Date(this.trackpoints[0].time).getTime(),
dist = 0;
for (var i = 0; i < this.trackpointns.length - 1; i++) {
var diff = this.trackpointns[i + 1].elevation - this.trackpointns[i].elevation,
time = new Date(this.trackpointns[i + 1].time).getTime(),
for (var i = 0; i < this.trackpoints.length - 1; i++) {
var diff = this.trackpoints[i + 1].elevation - this.trackpoints[i].elevation,
time = new Date(this.trackpoints[i + 1].time).getTime(),
timeDiff = Math.abs(time - startTime);
dist += this.calcDistanceBetweenPoints(this.trackpointns[i], this.trackpointns[i + 1]);
dist += this.calcDistanceBetweenPoints(this.trackpoints[i], this.trackpoints[i + 1]);

@@ -261,4 +271,4 @@ if (diff < 0) {

eleForMinMax.push(this.trackpointns[i].elevation);
richElevation.push({ elevation: this.trackpointns[i].elevation, time: this.millisecondsToTime(timeDiff), dist: dist });
eleForMinMax.push(this.trackpoints[i].elevation);
richElevation.push({ elevation: this.trackpoints[i].elevation, time: this.millisecondsToTime(timeDiff), dist: dist });
}

@@ -285,4 +295,4 @@

for (var i = 0; i < this.trackpointns.length - 1; i++) {
distanceInKm += this.calcDistanceBetweenPoints(this.trackpointns[i], this.trackpointns[i + 1]);
for (var i = 0; i < this.trackpoints.length - 1; i++) {
distanceInKm += this.calcDistanceBetweenPoints(this.trackpoints[i], this.trackpoints[i + 1]);
}

@@ -295,4 +305,4 @@

* Returns distance betwene points
* @param {node} wp1 DOM node from gpx content
* @param {node} wp2 DOM node from gpx content
* @param {TrackPoint} wp1 Object with trackpoint info
* @param {TrackPoint} wp2 Object with trackpoint info
* @return {number} distance Distance between the points.

@@ -299,0 +309,0 @@ */

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("gpx",[],e):"object"==typeof exports?exports.gpx=e():t.gpx=e()}(this,function(){return function(t){function e(a){if(n[a])return n[a].exports;var i=n[a]={exports:{},id:a,loaded:!1};return t[a].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}();Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(e){if(n(this,t),this.gpxContent=e,this.xmlDoc=(new DOMParser).parseFromString(this.gpxContent,"application/xml"),this.trkpts=this.xmlDoc.querySelectorAll("trkpt"),this.trackpointns=this.createJsonFromGpxDom(),0===this.trackpointns.length)throw new Error("This file has no trackpointns (trkpt)")}return a(t,[{key:"createJsonFromGpxDom",value:function(){for(var t=[],e=0;e<this.trkpts.length;e++)t.push({lon:parseFloat(this.trkpts[e].getAttribute("lon")),lat:parseFloat(this.trkpts[e].getAttribute("lat")),elevation:parseFloat(this.trkpts[e].querySelector("ele").textContent),time:this.trkpts[e].querySelector("time").textContent});return t}},{key:"duration",value:function(){var t=new Date(this.trackpointns[0].time),e=new Date(this.trackpointns[this.trackpointns.length-1].time),n=Math.abs(e.getTime()-t.getTime()),a=this.millisecondsToTime(n);return{start:t,end:e,totalMS:n,total:a}}},{key:"millisecondsToTime",value:function(t){var e=parseInt(t/1e3%60,10),n=parseInt(t/6e4%60,10),a=parseInt(t/36e5%24,10),i=parseInt(t/864e5,10),o=parseInt(24*i,10);return a+=o,a=10>a?"0"+a:a,n=10>n?"0"+n:n,e=10>e?"0"+e:e,"00"===a?n+":"+e:a+":"+n+":"+e}},{key:"pace",value:function(){var t=arguments.length<=0||void 0===arguments[0]?this.duration().totalMS:arguments[0],e=arguments.length<=1||void 0===arguments[1]?this.distance():arguments[1],n=new Date(t/e).getUTCMinutes(),a=new Date(t/e).getUTCSeconds();return{minutes:10>n?"0"+n:n,seconds:10>a?"0"+a:a}}},{key:"elevation",value:function(){for(var t=[],e=[],n=0,a=0,i=new Date(this.trackpointns[0].time).getTime(),o=0,r=0;r<this.trackpointns.length-1;r++){var s=this.trackpointns[r+1].elevation-this.trackpointns[r].elevation,l=new Date(this.trackpointns[r+1].time).getTime(),c=Math.abs(l-i);o+=this.calcDistanceBetweenPoints(this.trackpointns[r],this.trackpointns[r+1]),0>s&&(a+=s),s>0&&(n+=s),t.push(this.trackpointns[r].elevation),e.push({elevation:this.trackpointns[r].elevation,time:this.millisecondsToTime(c),dist:o})}return{elevation:e,max:Math.max.apply(null,t),min:Math.min.apply(null,t),loss:a,gain:n}}},{key:"distance",value:function(){for(var t=0,e=0;e<this.trackpointns.length-1;e++)t+=this.calcDistanceBetweenPoints(this.trackpointns[e],this.trackpointns[e+1]);return t}},{key:"calcDistanceBetweenPoints",value:function(t,e){var n={lat:t.lat*(Math.PI/180),lon:t.lon*(Math.PI/180),alt:t.elevation/1e3},a={lat:e.lat*(Math.PI/180),lon:e.lon*(Math.PI/180),alt:e.elevation/1e3},i=2*Math.asin(Math.sqrt(Math.pow(Math.sin((n.lat-a.lat)/2),2)+Math.cos(n.lat)*Math.cos(a.lat)*Math.pow(Math.sin((n.lon-a.lon)/2),2))),o=6366*i,r=Math.sqrt(Math.pow(o,2)+Math.pow(a.alt-n.alt,2));return r}}]),t}();e["default"]=i,t.exports=e["default"]}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("gpx",[],e):"object"==typeof exports?exports.gpx=e():t.gpx=e()}(this,function(){return function(t){function e(a){if(n[a])return n[a].exports;var i=n[a]={exports:{},id:a,loaded:!1};return t[a].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}();Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(e){if(n(this,t),this.gpxContent=e,this.xmlDoc=(new DOMParser).parseFromString(this.gpxContent,"application/xml"),this.trkpts=this.xmlDoc.querySelectorAll("trkpt"),this.trackpoints=this.createJsonFromGpxDom(),0===this.trackpoints.length)throw new Error("This file has no trackpoints (trkpt)")}return a(t,[{key:"createJsonFromGpxDom",value:function(){for(var t=[],e=0;e<this.trkpts.length;e++)t.push({lon:parseFloat(this.trkpts[e].getAttribute("lon")),lat:parseFloat(this.trkpts[e].getAttribute("lat")),elevation:parseFloat(this.trkpts[e].querySelector("ele").textContent),time:this.trkpts[e].querySelector("time").textContent});return t}},{key:"duration",value:function(){var t=new Date(this.trackpoints[0].time),e=new Date(this.trackpoints[this.trackpoints.length-1].time),n=Math.abs(e.getTime()-t.getTime()),a=this.millisecondsToTime(n);return{start:t,end:e,totalMS:n,total:a}}},{key:"millisecondsToTime",value:function(t){var e=parseInt(t/1e3%60,10),n=parseInt(t/6e4%60,10),a=parseInt(t/36e5%24,10),i=parseInt(t/864e5,10),o=parseInt(24*i,10);return a+=o,a=10>a?"0"+a:a,n=10>n?"0"+n:n,e=10>e?"0"+e:e,"00"===a?n+":"+e:a+":"+n+":"+e}},{key:"pace",value:function(){var t=arguments.length<=0||void 0===arguments[0]?this.duration().totalMS:arguments[0],e=arguments.length<=1||void 0===arguments[1]?this.distance():arguments[1],n=new Date(t/e).getUTCMinutes(),a=new Date(t/e).getUTCSeconds();return{minutes:10>n?"0"+n:n,seconds:10>a?"0"+a:a}}},{key:"elevation",value:function(){for(var t=[],e=[],n=0,a=0,i=new Date(this.trackpoints[0].time).getTime(),o=0,r=0;r<this.trackpoints.length-1;r++){var s=this.trackpoints[r+1].elevation-this.trackpoints[r].elevation,l=new Date(this.trackpoints[r+1].time).getTime(),c=Math.abs(l-i);o+=this.calcDistanceBetweenPoints(this.trackpoints[r],this.trackpoints[r+1]),0>s&&(a+=s),s>0&&(n+=s),t.push(this.trackpoints[r].elevation),e.push({elevation:this.trackpoints[r].elevation,time:this.millisecondsToTime(c),dist:o})}return{elevation:e,max:Math.max.apply(null,t),min:Math.min.apply(null,t),loss:a,gain:n}}},{key:"distance",value:function(){for(var t=0,e=0;e<this.trackpoints.length-1;e++)t+=this.calcDistanceBetweenPoints(this.trackpoints[e],this.trackpoints[e+1]);return t}},{key:"calcDistanceBetweenPoints",value:function(t,e){var n={lat:t.lat*(Math.PI/180),lon:t.lon*(Math.PI/180),alt:t.elevation/1e3},a={lat:e.lat*(Math.PI/180),lon:e.lon*(Math.PI/180),alt:e.elevation/1e3},i=2*Math.asin(Math.sqrt(Math.pow(Math.sin((n.lat-a.lat)/2),2)+Math.cos(n.lat)*Math.cos(a.lat)*Math.pow(Math.sin((n.lon-a.lon)/2),2))),o=6366*i,r=Math.sqrt(Math.pow(o,2)+Math.pow(a.alt-n.alt,2));return r}}]),t}();e["default"]=i,t.exports=e["default"]}])});
//# sourceMappingURL=gpx.min.js.map
{
"name": "gpx-for-runners",
"version": "1.0.0",
"version": "1.0.1",
"description": "A GPX file parser for runners.",

@@ -5,0 +5,0 @@ "main": "lib/gpx.min.js",

@@ -26,3 +26,3 @@ /**

/**
* Object of all trackpointns in the gpx DOM.
* Object of all trackpoints in the gpx DOM.
* @member GPX#trkpts

@@ -33,9 +33,9 @@ */

/**
* All trackpointns as an Array
* @member GPX#trackpointns
* All trackpoints as an Array
* @member GPX#trackpoints
*/
this.trackpointns = this.createJsonFromGpxDom();
this.trackpoints = this.createJsonFromGpxDom();
if( this.trackpointns.length === 0 ){
throw new Error( 'This file has no trackpointns (trkpt)' );
if( this.trackpoints.length === 0 ){
throw new Error( 'This file has no trackpoints (trkpt)' );
}

@@ -58,6 +58,6 @@ }

createJsonFromGpxDom(){
let trackpointns = [];
let trackpoints = [];
for( let trkpt = 0; trkpt < this.trkpts.length; trkpt++ ){
trackpointns.push( {
trackpoints.push( {
lon: parseFloat( this.trkpts[ trkpt ].getAttribute( 'lon' ) ),

@@ -70,3 +70,3 @@ lat: parseFloat( this.trkpts[ trkpt ].getAttribute( 'lat' ) ),

return trackpointns;
return trackpoints;
}

@@ -88,4 +88,4 @@

duration(){
let start = new Date( this.trackpointns[ 0 ].time ),
end = new Date( this.trackpointns[ this.trackpointns.length - 1 ].time ),
let start = new Date( this.trackpoints[ 0 ].time ),
end = new Date( this.trackpoints[ this.trackpoints.length - 1 ].time ),
timeDiff = Math.abs( end.getTime() - start.getTime() ),

@@ -162,11 +162,11 @@ total = this.millisecondsToTime( timeDiff );

gain = 0, loss = 0,
startTime = new Date( this.trackpointns[ 0 ].time ).getTime(),
startTime = new Date( this.trackpoints[ 0 ].time ).getTime(),
dist = 0;
for( let i = 0; i < this.trackpointns.length - 1; i++ ){
let diff = this.trackpointns[ i + 1 ].elevation - this.trackpointns[ i ].elevation,
time = new Date( this.trackpointns[ i + 1 ].time ).getTime(),
for( let i = 0; i < this.trackpoints.length - 1; i++ ){
let diff = this.trackpoints[ i + 1 ].elevation - this.trackpoints[ i ].elevation,
time = new Date( this.trackpoints[ i + 1 ].time ).getTime(),
timeDiff = Math.abs( time - startTime );
dist += this.calcDistanceBetweenPoints( this.trackpointns[ i ], this.trackpointns[ i + 1 ] );
dist += this.calcDistanceBetweenPoints( this.trackpoints[ i ], this.trackpoints[ i + 1 ] );

@@ -181,4 +181,4 @@ if( diff < 0 ){

eleForMinMax.push( this.trackpointns[ i ].elevation );
richElevation.push( { elevation: this.trackpointns[ i ].elevation, time: this.millisecondsToTime( timeDiff ), dist: dist } );
eleForMinMax.push( this.trackpoints[ i ].elevation );
richElevation.push( { elevation: this.trackpoints[ i ].elevation, time: this.millisecondsToTime( timeDiff ), dist: dist } );
}

@@ -202,4 +202,4 @@

for( let i = 0; i < this.trackpointns.length - 1; i++ ){
distanceInKm += this.calcDistanceBetweenPoints( this.trackpointns[ i ], this.trackpointns[ i + 1 ] );
for( let i = 0; i < this.trackpoints.length - 1; i++ ){
distanceInKm += this.calcDistanceBetweenPoints( this.trackpoints[ i ], this.trackpoints[ i + 1 ] );
}

@@ -206,0 +206,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc