@sugarcube/source-types
v0.1.7
Published
> Utility functions to deal with different types of sources for Sugarcube.
Readme
Source Types for Sugarcube
Utility functions to deal with different types of sources for Sugarcube.
@sugarcube/source-types provides utility functions for the Sugarcube Tools 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, the Sugarcube Discovery Extension and Sugarcube itself.
Contents
Installation
npm install --save @sugarcube/source-typesUsage
import {sourceType} from "@sugarcube/source-types";
sourceType("I'm gibberish"); // undefined
sourceType("https://youtube.com/watch?v=wer23edsa"); // youtube_videoAPI
isTelegramChannel: Determine if a term is a valid Telegram channel.isTwitterTweet: Determine if a term is a valid Twitter tweet.isTwitterFeed: Determine if a term is a valid Twitter feed.isYoutubeVideo: Determine if a term is a valid Youtube video.isYoutubeChannel: Determine if a term is a valid Youtube channel.isHttpUrl: Determine if a term is a valid HTTP url.
parseTelegramChannel: Extract a Telegram channel from a term.parseTweetId: Extract a tweet id from a term.parseTwitterUser: Extract a Twitter user from a term.parseYoutubeVideo: Extract a Youtube video id from a term.parseYoutubeChannel: Extract a Youtube channel id from a term.parseHttpUrl: Parse a term into a valid HTTP url.
normalizeTelegramChannelUrl: Turn a term into a normalized Telegram Channel URL.normalizeTwitterTweetUrl: Turn a term into a normalized Twitter tweet URL.normalizeTwitterUserUrl: Turn a term into a normalized Twitter feed URL.normalizeYoutubeVideoUrl: Turn a term into a normalized Youtube video URL.normalizeYoutubeChannelUrl: Turn a term into a normalized Youtube channel URL.normalizeHttpUrl: Turn a term into a normalized HTTP url.
SourceType
A string literal type containig valid source types.
telegram_channeltwitter_tweettwitter_channelyoutube_videoyoutube_channelhttp_url
sourceType
Detect the type of a source.
sourceType :: (term?: string) -> SourceType | undefinedisTelegramChannel
Check if a term is a valid Telegram channel.
isTelegramChannel :: (term?: string) -> booleanisTwitterTweet
Check if a term is a valid Twitter tweet.
isTwitterTweet :: (term?: string) -> booleanisTwitterFeed
Check if a term is a valid Twitter channel.
isTwitterFeed :: (term?: string) -> booleanisYoutubeVideo
Check if a term is a valid Youtube video.
isYoutubeVideo :: (term?: string) -> booleanisYoutubeChannel
Check if a term is a valid Youtube channel.
isYoutubeChannel :: (term?: string) -> booleanisHttpUrl
Check if a term is a valid HTTP url.
isHttpUrl :: (term?: string) -> booleanparseTelegramChannel
Extract a Telegram channel from a term.
parseTelegramChannel :: (term?: string) -> string | undefinedparseTelegramChannel("https://t.me/s/soscubamedia"); # soscubamedia
parseTelegramChannel("https://t.me/soscubamedia"); # soscubamediaChannel names in the form of @soscubamedia are not valid since they are ambiguous with Twitter user handlers.
parseTweetId
Extract a tweet id from a term.
parseTweetId :: (term?: string) -> string | undefinedparseTwitterUser
Extract a Twitter user name from a term.
parseTwitterUser :: (term?: string) -> string | undefinedparseYoutubeVideo
Extract a Youtube video id from a term.
parseYoutubeVideo :: (term?: string) -> string | undefinedparseYoutubeChannel
Extract a Youtube channel id from a term.
parseYoutubeChannel :: (term?: string) -> string | undefinedparseHttpUrl
Parse a term and return a HTTP url.
parseHttpUrl :: (term?: string) -> string | undefinednormalizeTelegramChannelUrl
Parse a Telegram channel from a term and return a normalized Telegram channel URL.
normalizeTelegramChannelUrl :: (term?: string) -> string | undefinednormalizeTwitterTweetUrl
Parse a Twitter tweet id from a term and return a normalized Twitter tweet URL.
normalizeTwitterTweetUrl :: (term?: string) -> string | undefinednormalizeTwitterUserUrl
Parse a Twitter user name from a term and return a normalized Twitter feed URL.
normalizeTwitterUserUrl :: (term?: string) -> string | undefinednormalizeYoutubeVideoUrl
Parse a Youtube Video id from a term and return a normalized Youtube video URL.
normalizeYoutubeVideoUrl :: (term?: string) -> string | undefinednormalizeYoutubeChannelUrl
Parse a Youtube channel id from a term and return a normalized Youtube channel URL.
normalizeYoutubeChannelUrl :: (term?: string) -> string | undefinednormalizeHttpUrl
Turn a term into a well formed HTTP url.
normalizeHttpUrl :: (term?: string) -> string | undefined