{"id":15801128,"url":"https://github.com/erikwittern/is-base-url","last_synced_at":"2025-03-31T21:33:42.706Z","repository":{"id":57276984,"uuid":"63361558","full_name":"ErikWittern/is-base-url","owner":"ErikWittern","description":"A small tool to check whether a given URL is likely to be a base url of a web API","archived":false,"fork":false,"pushed_at":"2016-10-31T19:41:55.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T01:30:53.565Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ErikWittern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-14T18:51:39.000Z","updated_at":"2016-10-31T19:41:57.000Z","dependencies_parsed_at":"2022-08-25T04:11:50.529Z","dependency_job_id":null,"html_url":"https://github.com/ErikWittern/is-base-url","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fis-base-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fis-base-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fis-base-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErikWittern%2Fis-base-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ErikWittern","download_url":"https://codeload.github.com/ErikWittern/is-base-url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246544203,"owners_count":20794465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-05T01:20:30.767Z","updated_at":"2025-03-31T21:33:42.680Z","avatar_url":"https://github.com/ErikWittern.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# is-base-url\n\nA small tool to check whether a given URL is likely to be a base url of a web API. `is-base-url` takes as input a URL string and returns a `score` for how likely it is a base URL. To do so, `is-base-url` considers lexical features of the given URL that either support or discourage the classification as a base URL.\n\n## Usage\n\nInstall via:\n\n    npm i is-base-url\n\nUse it via:\n\n```javascript\nvar isBaseUrl = require('is-base-url')\n\nvar result = isBaseUrl('http://api.twitter.com/v1')\n/**\n *  result will look like this:\n *  {\n *   score: 1,\n *   features: {\n *     positive: {\n *       containsApiSubstring: true,\n *       containsVersionSubstring: true,\n *       endsWithVersionSubstring: true,\n *       endsWithNumber: true },\n *     negative: {\n *       hasQueryString: false,\n *       hasFragment: false,\n *       containsNonApiSubstring: false,\n *       overTwoPaths: false,\n *       endsWithFileExtension: false,\n *       containsBracket: false,\n *       isHomepage: false\n *     }\n *   }\n * }\n */\n```\n\nThe `score` is a value ranging from -1 to 1. The more positive features are `true`, the higher the score. Reversely, the more negative features are `true`, the lower score. Thus, the higher the value, the more like the given URL is a base URL.\n\n`isBaseUrl` will return `undefined` if 1) the given variable is not a string or 2) if the given string is not a valid URL.\n\n### Features\n\n`isBaseUrl` considers positive and negative features.\n\n#### Positive\n\n- `containsApiSubstring`: true if the given URL contains the substring `api`.\n- `containsVersionSubstring`: true if the given URL contains a substring indicating a version number, e.g. `v1`, `v.1.2`.\n- `endsWithVersionSubstring`: true if the given URL ends with a version number.\n- `endsWithNumber`: true if the given URL ends with a number.\n\n#### Negative\n\n- `hasQueryString`: true if the given URL has a query string (following an `?`).\n- `hasFragment`: true if the given URL has a fragment (following an `#`).\n- `containsNonApiSubstring`: true if the given URL contains a string not associated with a base URL, e.g., `schema`, `w3`.\n- `overTwoPath`: true if the given URL has over 2 path components.\n- `endsWithFileExtension`: true if the given URL ends with a file extension, e.g., `.json`, `.html`. This feature considers the URL substring before the query string or fragment, if present.\n- `containsBracket`: true if the given URL contains a bracket, e.g., `{`, `\u003e`.\n- `isHomepage`: true if the given URL is equal to the homepage of that domain, e.g., `http://www.rottentomatoes.com`.\n\n### Options\n\nIf you want, you can pass an options object to `isBaseUrl` to customize its behavior:\n\n    var result = isBaseUrl('http://api.twitter.com/v1', {\n      ...options...\n    })\n\nIf you don't set an option, its default value will be used. The following options are available:\n\n- `checkUrlValid` (default: `true`) - Determines whether the given URL is checked for validity. If the check is performed and an invalid URL is provided, `isBaseUrl` will return `undefined`.\n- `weights` (default: all features have weight `1`) - Allows to assign custom weights to specific features. For example, to make `endsWithFileExtension` more important, do: \n\n      var result = isBaseUrl('http://api.twitter.com/v1', {\n        weights: {\n          negative: {\n            endsWithFileExtension: 3\n          }\n        }\n      })\n\n  Note: passing weights will result in the score not necessarily ranging from -1 to 1 anymore.\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikwittern%2Fis-base-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikwittern%2Fis-base-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikwittern%2Fis-base-url/lists"}