{"id":16628888,"url":"https://github.com/critocrito/sugarcube-source-types","last_synced_at":"2026-04-25T07:34:54.086Z","repository":{"id":40757066,"uuid":"280231326","full_name":"critocrito/sugarcube-source-types","owner":"critocrito","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-05T06:15:10.000Z","size":1011,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T19:36:28.961Z","etag":null,"topics":["data","data-investigation"],"latest_commit_sha":null,"homepage":"https://sugarcubetools.net","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/critocrito.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-16T18:42:39.000Z","updated_at":"2021-08-17T15:22:50.000Z","dependencies_parsed_at":"2025-03-11T16:41:57.448Z","dependency_job_id":null,"html_url":"https://github.com/critocrito/sugarcube-source-types","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/critocrito/sugarcube-source-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fsugarcube-source-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fsugarcube-source-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fsugarcube-source-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fsugarcube-source-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/critocrito","download_url":"https://codeload.github.com/critocrito/sugarcube-source-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fsugarcube-source-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32254697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T04:23:17.126Z","status":"ssl_error","status_checked_at":"2026-04-25T04:21:53.360Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["data","data-investigation"],"created_at":"2024-10-12T04:37:57.412Z","updated_at":"2026-04-25T07:34:54.046Z","avatar_url":"https://github.com/critocrito.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Source Types for Sugarcube\n\n\u003e Utility functions to deal with different types of sources for Sugarcube.\n\n\u003cdiv align=\"center\"\u003e\n\n![CI Status](https://img.shields.io/github/workflow/status/critocrito/sugarcube-source-types/CI?style=flat-square)\n[![Code Coverage](https://codecov.io/gh/critocrito/sugarcube-source-types/branch/master/graph/badge.svg)](https://codecov.io/gh/critocrito/sugarcube-source-types)\n![GitHub](https://img.shields.io/github/license/critocrito/sugarcube-source-types?color=blue\u0026style=flat-square)\n\n\u003c/div\u003e\n\n---\n\n`@sugarcube/source-types` provides utility functions for the [Sugarcube Tools](https://sugarcubetools.net) distribution. The utility functions can parse, normalize and verify terms in respect to the type of the source. This packages is used across various parts of the Sugarcube distribution, such as [Ncube](https://github.com/critocrito/ncube), the [Sugarcube Discovery Extension](https://github.com/critocrito/sugarcube-discovery) and [Sugarcube](https://github.com/critocrito/sugarcube) itself.\n\n## Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install --save @sugarcube/source-types\n```\n\n## Usage\n\n```javascript\nimport {sourceType} from \"@sugarcube/source-types\";\n\nsourceType(\"I'm gibberish\"); // undefined\nsourceType(\"https://youtube.com/watch?v=wer23edsa\"); // youtube_video\n```\n\n## API\n\n\u003cdetails\u003e\u003csummary\u003eMap source type for a term\u003c/summary\u003e\n\n- [`SourceType`: Valid types of sources.](#sourcetype-1)\n- [`sourceType`: Determine source type for any term.](#sourcetype-2)\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSource type predicates\u003c/summary\u003e\n\n- [`isTelegramChannel`: Determine if a term is a valid Telegram channel.](#istelegramchannel)\n- [`isTwitterTweet`: Determine if a term is a valid Twitter tweet.](#istwittertweet)\n- [`isTwitterFeed`: Determine if a term is a valid Twitter feed.](#istwitterfeed)\n- [`isYoutubeVideo`: Determine if a term is a valid Youtube video.](#isyoutubevideo)\n- [`isYoutubeChannel`: Determine if a term is a valid Youtube channel.](#isyoutubechannel)\n- [`isHttpUrl`: Determine if a term is a valid HTTP url.](#ishttpurl)\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSource type parsers\u003c/summary\u003e\n\n- [`parseTelegramChannel`: Extract a Telegram channel from a term.](#parsetelegramchannel)\n- [`parseTweetId`: Extract a tweet id from a term.](#parsetweetid)\n- [`parseTwitterUser`: Extract a Twitter user from a term.](#parsetwitteruser)\n- [`parseYoutubeVideo`: Extract a Youtube video id from a term.](#parseyoutubevideo)\n- [`parseYoutubeChannel`: Extract a Youtube channel id from a term.](#parseyoutubechannel)\n- [`parseHttpUrl`: Parse a term into a valid HTTP url.](#parsehttpurl)\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eNormalize terms\u003c/summary\u003e\n\n- [`normalizeTelegramChannelUrl`: Turn a term into a normalized Telegram Channel\n  URL.](#normalizetelegramchannelurl)\n- [`normalizeTwitterTweetUrl`: Turn a term into a normalized Twitter tweet URL.](#normalizetwittertweeturl)\n- [`normalizeTwitterUserUrl`: Turn a term into a normalized Twitter feed URL.](#normalizetwitteruserurl)\n- [`normalizeYoutubeVideoUrl`: Turn a term into a normalized Youtube video URL.](#normalizeyoutubevideourl)\n- [`normalizeYoutubeChannelUrl`: Turn a term into a normalized Youtube channel URL.](#normalizeyoutubechannelurl)\n- [`normalizeHttpUrl`: Turn a term into a normalized HTTP url.](#normalizehttpurl)\n\n\u003c/details\u003e\n\n### `SourceType`\n\nA string literal type containig valid source types.\n\n- `telegram_channel`\n- `twitter_tweet`\n- `twitter_channel`\n- `youtube_video`\n- `youtube_channel`\n- `http_url`\n\n### `sourceType`\n\nDetect the type of a source.\n\n```\nsourceType :: (term?: string) -\u003e SourceType | undefined\n```\n\n### `isTelegramChannel`\n\nCheck if a term is a valid Telegram channel.\n\n```\nisTelegramChannel :: (term?: string) -\u003e boolean\n```\n\n### `isTwitterTweet`\n\nCheck if a term is a valid Twitter tweet.\n\n```\nisTwitterTweet :: (term?: string) -\u003e boolean\n```\n\n### `isTwitterFeed`\n\nCheck if a term is a valid Twitter channel.\n\n```\nisTwitterFeed :: (term?: string) -\u003e boolean\n```\n\n### `isYoutubeVideo`\n\nCheck if a term is a valid Youtube video.\n\n```\nisYoutubeVideo :: (term?: string) -\u003e boolean\n```\n\n### `isYoutubeChannel`\n\nCheck if a term is a valid Youtube channel.\n\n```\nisYoutubeChannel :: (term?: string) -\u003e boolean\n```\n\n### `isHttpUrl`\n\nCheck if a term is a valid HTTP url.\n\n```\nisHttpUrl :: (term?: string) -\u003e boolean\n```\n\n### `parseTelegramChannel`\n\nExtract a Telegram channel from a term.\n\n```\nparseTelegramChannel :: (term?: string) -\u003e string | undefined\n```\n\n```javascript\nparseTelegramChannel(\"https://t.me/s/soscubamedia\"); # soscubamedia\nparseTelegramChannel(\"https://t.me/soscubamedia\"); # soscubamedia\n```\n\nChannel names in the form of `@soscubamedia` are not valid since they are ambiguous with Twitter user handlers.\n\n### `parseTweetId`\n\nExtract a tweet id from a term.\n\n```\nparseTweetId :: (term?: string) -\u003e string | undefined\n```\n\n### `parseTwitterUser`\n\nExtract a Twitter user name from a term.\n\n```\nparseTwitterUser :: (term?: string) -\u003e string | undefined\n```\n\n### `parseYoutubeVideo`\n\nExtract a Youtube video id from a term.\n\n```\nparseYoutubeVideo :: (term?: string) -\u003e string | undefined\n```\n\n### `parseYoutubeChannel`\n\nExtract a Youtube channel id from a term.\n\n```\nparseYoutubeChannel :: (term?: string) -\u003e string | undefined\n```\n\n### `parseHttpUrl`\n\nParse a term and return a HTTP url.\n\n```\nparseHttpUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeTelegramChannelUrl`\n\nParse a Telegram channel from a term and return a normalized Telegram channel URL.\n\n```\nnormalizeTelegramChannelUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeTwitterTweetUrl`\n\nParse a Twitter tweet id from a term and return a normalized Twitter tweet URL.\n\n```\nnormalizeTwitterTweetUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeTwitterUserUrl`\n\nParse a Twitter user name from a term and return a normalized Twitter feed URL.\n\n```\nnormalizeTwitterUserUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeYoutubeVideoUrl`\n\nParse a Youtube Video id from a term and return a normalized Youtube video URL.\n\n```\nnormalizeYoutubeVideoUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeYoutubeChannelUrl`\n\nParse a Youtube channel id from a term and return a normalized Youtube channel URL.\n\n```\nnormalizeYoutubeChannelUrl :: (term?: string) -\u003e string | undefined\n```\n\n### `normalizeHttpUrl`\n\nTurn a term into a well formed HTTP url.\n\n```\nnormalizeHttpUrl :: (term?: string) -\u003e string | undefined\n```\n\n## License\n\n[GPL 3.0 licensed](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcritocrito%2Fsugarcube-source-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcritocrito%2Fsugarcube-source-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcritocrito%2Fsugarcube-source-types/lists"}