Skip to content

Commit

Permalink
add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeanAsad committed Oct 26, 2023
1 parent c0e3e93 commit 7d0b34e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { parseUrl, addHttpPrefix } from './utils/url.js'
import { isBrowserContext } from './utils/runtime.js'

const MAX_NODE_WEIGHT = 100
/**
* @typedef {import('./types.js').Node} Node
*/

export class Saturn {
static nodesListKey = 'saturn-nodes'
Expand Down Expand Up @@ -488,6 +491,12 @@ export class Saturn {
}
}

/**
* Sorts nodes based on normalized distance and weights. Distance is prioritized for sorting.
*
* @param {Node[]} nodes
* @returns {Node[]}
*/
_sortNodes (nodes) {
// Determine the maximum distance for normalization
const maxDistance = Math.max(...nodes.map(node => node.distance))
Expand Down
14 changes: 14 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/**
* @module types */

/**
*
* @typedef {object} Node
* @property {string} ip
* @property {number} weight
* @property {number} distance
* @property {string} url
*/

export {}
7 changes: 1 addition & 6 deletions test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
process.env.TESTING = 'true'

/**
*
* @typedef {object} Node
* @property {string} ip
* @property {number} weight
* @property {number} distance
* @property {string} url
* @typedef {import('../src/types.js').Node} Node
*/

/**
Expand Down

0 comments on commit 7d0b34e

Please sign in to comment.