@letea/functions
v2.7.3
Published
A function library.
Downloads
5
Readme
Functions
A function library.
Install
npm install @letea/functions
Contents
Array
- checkIsArray
- checkIsArrayEmpty
- getDuplicateValuesFromArray
- getIntersectionArray
- getNextIndexInArray
- getRandomIndexInArray
- getRandomValueInArray
- getReverseArray
- getShuffleArray
- getSortedArray
- getTrulyArray
- getUniqueArray
- getUniqueValuesFromArray
Browser
Canvas
Function
LocalStorage
Number
Object
String
- checkIsEmailValid
- checkIsMobileNumberValid
- checkIsString
- getRandomString
- getSimpleChinese
- getStringify
- getStringWithSpaceBetweenHalfAndFullWidth
- getTraditionalChinese
Time
- getHoursFromMinutes
- getHoursFromSeconds
- getMillisecondsFromSeconds
- getMinutesFromHours
- getMinutesFromSeconds
- getSecondsFromHours
- getSecondsFromMilliseconds
- getSecondsFromMinutes
URL
- checkIsAbsoluteURL
- getCurrentURL
- getDropboxRawFileURL
- getGoogleCloudStorageFile
- getParametersFromURL
- getSearchFromParameters
- getShareToFacebookLink
- getShareToLineLink
- getURLWithoutParameters
- getURLWithoutTrackingParameters
User-Agent
- checkIsAndroid
- checkIsChrome
- checkIsDesktop
- checkIsEdge
- checkIsFirefox
- checkIsInAppBrowserByFacebook
- checkIsInAppBrowserByLine
- checkIsInternetExplorer
- checkIsiOS
- checkIsiPad
- checkIsiPhone
- checkIsMac
- checkIsMobile
- checkIsSafari
- checkIsSamsungBrowser
- checkIsWindows
- getAndroidVersion
- getiOSVersion
Video
Window
Array
checkIsArray
Check data type is an array or not.
arguments
value; // required, any type is accepted.
usage
import checkIsArray from "@letea/function/checkIsArray";
checkIsArray([1, 2, 3]);
// true
checkIsArray("abc");
// false
checkIsArrayEmpty
Check the array is empty or not.
arguments
array = []; // required
usage
import checkIsArrayEmpty from "@letea/function/checkIsArrayEmpty";
checkIsArrayEmpty([]);
// true
checkIsArrayEmpty([1, 2, 3]);
// false
getDuplicateValuesFromArray
Get an array with duplicate values from the original array.
arguments
array = []; // required
usage
import getDuplicateValuesFromArray from "@letea/function/getDuplicateValuesFromArray";
const array = [1, 2, 3, 2, 3, 4, 5];
getDuplicateValuesFromArray(array);
// [2, 3]
getIntersectionArray
Get an intersection array.
arguments
arguments = {
array1: [], // required
array2: [], // required
};
usage
import getIntersectionArray from "@letea/function/getIntersectionArray";
getIntersectionArray({
array1: ["a", "b", "c"],
array2: ["b", "c", "d", "e", "f"],
});
// ["b", "c"]
references
getNextIndexInArray
Set an array and index to get the next index. Using isLoop to get the first index if the index of input is the last one.
arguments
arguments = {
array: [], // required
index: 0, // optional
isLoop: false, // optional
};
usage
import getNextIndexInArray from "@letea/function/getNextIndexInArray";
const array = ["a", "b", "c", "d", "e"];
getNextIndexInArray({
array,
index: 2,
});
// 3
getNextIndexInArray({
array,
index: 4,
});
// -1
getNextIndexInArray({
array,
index: 4,
isLoop: true,
});
// 0
getRandomIndexInArray
Get a random index from the array.
arguments
array = []; // required
usage
import getRandomIndexInArray from "@letea/function/getRandomIndexInArray";
const array = ["a", "b", "c", "d", "e"];
getRandomIndexInArray(array);
getRandomValueInArray
Get a random value from the array.
arguments
array = []; // required
usage
import getRandomValueInArray from "@letea/function/getRandomValueInArray";
const array = [1, 2, 3, 4, 5];
getRandomValueInArray(array);
getReverseArray
Get an array with reversed.
arguments
array = []; // required
usage
import getReverseArray from "@letea/function/getReverseArray";
const array = [1, 2, 3, 4, 5];
getReverseArray(array);
// [5, 4, 3, 2 ,1]
getShuffleArray
Get an array with shuffled.
arguments
array = []; // required
usage
import getShuffleArray from "@letea/function/getShuffleArray";
const array = [1, 2, 3, 4, 5];
getShuffleArray(array);
// [5, 3, 2, 1, 4]...
getSortedArray
Get a sorted array.
arguments
array = []; // required
usage
import getSortedArray from "@letea/function/getSortedArray";
const array = [5, 3, 2, 1, 4];
getSortedArray(array);
// [1, 2, 3, 4, 5]
getTrulyArray
Get an array with true values.
arguments
array = []; // required
usage
import getTrulyArray from "@letea/function/getTrulyArray";
const array = [0, "test", "", NaN, 9, true, undefined, false, Infinity, {}, []];
getTrulyArray(array);
// ["test", 9, true, Infinity, {}, []]
notes
- Infinity is a true value.
references
getUniqueArray
Get a unique array.
arguments
array = []; // required
usage
import getUniqueArray from "@letea/function/getUniqueArray";
getUniqueArray([1, 2, 3, "a", "b", 2, "c", "a"]);
// [1, 2, 3, "a", "b", "c"]
references
getUniqueValuesFromArray
Get an array with unique values from the original array.
arguments
array = []; // required
usage
import getUniqueValuesFromArray from "@letea/function/getUniqueValuesFromArray";
const array = [1, 2, 3, 2, 3, 4, 5];
getUniqueValuesFromArray(array);
// [1, 4, 5]
Browser
checkIsBrowser
Check an environment is a browser or not by window and document.
usage
import checkIsBrowser from "@letea/function/checkIsBrowser";
// Browser
checkIsBrowser();
// true
// Node.js
checkIsBrowser();
// false
references
checkIsInAppBrowserByFacebookNotLoaded
Facebook's InAppBrowser has a bug: window size is not correct before the window loaded. So we need to check is loaded or not.
usage
import checkIsInAppBrowserByFacebookNotLoaded from "@letea/function/checkIsInAppBrowserByFacebookNotLoaded";
checkIsInAppBrowserByFacebookNotLoaded();
// true
notes
- Only work on browsers.
Canvas
checkIsCanvasSupported
Check the browser is supports canvas or not.
usage
import checkIsCanvasSupported from "@letea/function/checkIsCanvasSupported";
checkIsCanvasSupported();
// true
notes
- Only work on browsers.
Function
checkIsFunction
Check data type is function or not.
arguments
value; // required, any type is accepted.
usage
import checkIsFunction from "@letea/function/checkIsFunction";
checkIsFunction(() => {});
// true
checkIsFunction(function () {});
// true
checkIsFunction("function");
// false
LocalStorage
checkIsLocalStorageSupported
Check the browser is supports local storage or not.
usage
import checkIsLocalStorageSupported from "@letea/function/checkIsLocalStorageSupported";
checkIsLocalStorageSupported();
// true
notes
- Only work on browsers.
Number
checkIsInteger
Check the number is an integer or not.
arguments
value; // required, any type is accepted.
usage
import checkIsInteger from "@letea/function/checkIsInteger";
checkIsInteger(1);
// true
checkIsInteger(1.5);
// false
checkIsNumber
Check data type is number or not.
arguments
value; // required, any type is accepted.
usage
import checkIsNumber from "@letea/function/checkIsNumber";
checkIsNumber(123);
// true;
checkIsNumber("abc");
// false
checkIsNumber(NaN);
// false
checkIsNumber(Infinity);
// false
getFloatNumber
Get a float number with fixed option.
arguments
arguments = {
number: 0, // required.
fixed: 0, // optional.
};
usage
import getFloatNumber from "@letea/function/getFloatNumber";
getFloatNumber({
number: 3.1415926535,
fixed: 5,
});
// 3.14159
getRandomNumber
Get a random number.
arguments
arguments = {
maxNumber: 0, // required, it should be greater than minNumber.
minNumber: 0, // optional.
isFloat: false, // optional, if is true, it will return a float number.
};
usage
import getRandomNumber from "@letea/function/getRandomNumber";
getRandomNumber({
maxNumber: 10,
});
// 6
getRandomNumber({
maxNumber: 10,
minNumber: 0,
isFloat: true,
});
// 3.5476
Object
checkIsObject
Check data type is an object or not.
arguments
value; // required, any type is accepted.
usage
import checkIsObject from "@letea/function/checkIsObject";
checkIsObject({ a: 123 });
// true;
checkIsObject([1, 2, 3]);
// false
checkIsObject("abc");
// false
checkIsObjectEmpty
Check the object is empty or not.
arguments
object = {}; // required
usage
import checkIsObjectEmpty from "@letea/function/checkIsObjectEmpty";
checkIsObjectEmpty({});
// true
checkIsObjectEmpty({ a: 1 });
// false
getObjectValue
Get the value from an object, including multiple levels.
arguments
arguments = {
object: {}, // required
keys: "", // required
};
usage
import getObjectValue from "@letea/function/getObjectValue";
const example = {
a: 1,
b: {
c: 2,
d: [3, { e: 4 }],
},
};
getObjectValue({
object: example,
keys: "a",
});
// 1
getObjectValue({
object: example,
keys: "b.c",
});
// 2
getObjectValue({
object: example,
keys: "b.d[0]",
});
// 3
getObjectValue({
object: example,
keys: "b.d[1].e",
});
// 4
getObjectValue({
object: example,
keys: "b.d[1].e.f",
});
// undefined
String
checkIsEmailValid
Check email format is valid or not.
arguments
email = ""; // required
usage
import checkIsEmailValid from "@letea/function/checkIsEmailValid";
checkIsEmailValid("[email protected]");
checkIsEmailValid("[email protected]");
checkIsEmailValid("[email protected]");
checkIsEmailValid("[email protected]");
// true
checkIsEmailValid();
checkIsEmailValid("hello@");
checkIsEmailValid("@test");
checkIsEmailValid("email@gmail");
checkIsEmailValid("theproblem@");
// false
references
checkIsMobileNumberValid
Check mobile number format is valid or not.
arguments
mobileNumber = ""; // required
usage
import checkIsMobileNumberValid from "@letea/function/checkIsMobileNumberValid";
checkIsMobileNumberValid("0912345678");
checkIsMobileNumberValid("0912-345-678");
checkIsMobileNumberValid("+8860912345678");
checkIsMobileNumberValid("+886912345678");
checkIsMobileNumberValid("+886912-345-678");
// true
checkIsMobileNumberValid();
checkIsMobileNumberValid("09");
checkIsMobileNumberValid("091234567");
checkIsMobileNumberValid("0912-345");
checkIsMobileNumberValid("09123-45-678");
checkIsMobileNumberValid("0912345-678");
checkIsMobileNumberValid("0912-345678");
checkIsMobileNumberValid("+88609");
checkIsMobileNumberValid("+886091234567");
checkIsMobileNumberValid("+8860912-34567");
// false
checkIsString
Check data type is a string or not.
arguments
value; // required, any type is accepted.
usage
import checkIsString from "@letea/function/checkIsString";
checkIsString("abc");
// true
checkIsString(123);
// false
checkIsString({ a: 1 });
// false
getRandomString
Get a random string.
arguments
length = 3; // optional
usage
import getRandomString from "@letea/function/getRandomString";
getRandomString();
// "ZI4"
getRandomString(5);
// "j0C4N"
getSimpleChinese
Transform Traditional Chinese into Simple Chinese.
arguments
value = ""; // required
usage
import getSimpleChinese from "@letea/function/getSimpleChinese";
getSimpleChinese("繁體字、簡體字");
// "繁体字、简体字"
references
getStringify
Transform any data into a string.
arguments
value; // required, any type is accepted.
usage
import getStringify from "@letea/function/getStringify";
getStringify(123);
// "123"
getStringify({ a: 123, b: undefined, c: Infinity, d: NaN });
// "{a:123, b:undefined, c:Infinity, d:NaN}"
getStringify([123, 234, undefined, Infinity, NaN]);
// "[123, 234, undefined, Infinity, NaN]"
getStringWithSpaceBetweenHalfAndFullWidth
Get a string with space between half and full with characters.
arguments
text = ""; // required
usage
import getStringWithSpaceBetweenHalfAndFullWidth from "@letea/function/getStringWithSpaceBetweenHalfAndFullWidth";
getStringWithSpaceBetweenHalfAndFullWidth("我是很busy,因為我很多things要do");
// "我是很 busy,因為我很多 things 要 do"
references
getTraditionalChinese
Transform Simple Chinese into Traditional Chinese.
arguments
value = ""; // required
usage
import getTraditionalChinese from "@letea/function/getTraditionalChinese";
getTraditionalChinese("繁体字、简体字");
// "繁體字、簡體字"
references
Time
getHoursFromMinutes
Minutes to hours.
arguments
minutes = 0; // required
usage
import getHoursFromMinutes from "@letea/function/getHoursFromMinutes";
getHoursFromMinutes(60);
// 1
getHoursFromSeconds
Seconds to hours.
arguments
seconds = 0; // required
usage
import getHoursFromSeconds from "@letea/function/getHoursFromSeconds";
getHoursFromSeconds(3600);
// 1
getMillisecondsFromSeconds
Seconds to milliseconds
arguments
seconds = 0; // required
usage
import getMillisecondsFromSeconds from "@letea/function/getMillisecondsFromSeconds";
getMillisecondsFromSeconds(1);
// 1000
getMinutesFromHours
Hours to minutes.
arguments
hours = 0; // required
usage
import getMinutesFromHours from "@letea/function/getMinutesFromHours";
getMinutesFromHours(1);
// 60
getMinutesFromSeconds
Seconds to minutes.
arguments
seconds = 0; // required
usage
import getMinutesFromSeconds from "@letea/function/getMinutesFromSeconds";
getMinutesFromSeconds(60);
// 1
getSecondsFromHours
Hours to seconds.
arguments
hours = 0; // required
usage
import getSecondsFromHours from "@letea/function/getSecondsFromHours";
getSecondsFromHours(1);
// 3600
getSecondsFromMilliseconds
Milliseconds to seconds.
arguments
milliseconds = 0; // required
usage
import getSecondsFromMilliseconds from "@letea/function/getSecondsFromMilliseconds";
getSecondsFromMilliseconds(1000);
// 1
getSecondsFromMinutes
Minutes to Seconds.
arguments
minutes = 0; // required
usage
import getSecondsFromMinutes from "@letea/function/getSecondsFromMinutes";
getSecondsFromMinutes(1);
// 60
URL
checkIsAbsoluteURL
Check the URL is absolute or not.
arguments
url = ""; // required
usage
import checkIsAbsoluteURL from "@letea/function/checkIsAbsoluteURL";
checkIsAbsoluteURL("https://google.com");
// true
checkIsAbsoluteURL("ftp://www.myserver.net");
// true
checkIsAbsoluteURL("/foo/bar");
// false
references
getCurrentURL
Get current site's URL. For now can get URL without search or trim tracking parameters(Google & Facebook).
arguments
arguments = {
hasSearch: true, // optional.
trimTracking: false, // optional, if hasSearch is true then trimTracking will do nothing.
};
usage
import getCurrentURL from "@letea/function/getCurrentURL";
// if window.location.href is "https://google.com/tw/?a=%E5%80%BC&utm_source=value&utm_medium=value&utm_campaign=value&utm_term=value&utm_content=value&ad_id=value&adset_id=value&campaign_id=value&ad_name=value&adset_name=value&campaign_name=value&placement=value&site_source_name=value"
getCurrentURL();
// "https://google.com/tw/?a=%E5%80%BC&utm_source=value&utm_medium=value&utm_campaign=value&utm_term=value&utm_content=value&ad_id=value&adset_id=value&campaign_id=value&ad_name=value&adset_name=value&campaign_name=value&placement=value&site_source_name=value"
getCurrentURL({
hasSearch: false,
});
// "https://google.com/tw/"
getCurrentURL({
trimTracking: true,
});
// https://google.com/tw/?a=%E5%80%BC
notes
- Only work on browsers.
getDropboxRawFileURL
Get a file URL that can be linked from Dropbox directly.
arguments
filePath = ""; // required, the format is "id/filename"
usage
import getDropboxRawFileURL from "@letea/function/getDropboxRawFileURL";
getDropboxRawFileURL("0xp0v2cm3asbk0h/sample.jpg");
// https://www.dropbox.com/s/0xp0v2cm3asbk0h/sample.jpg?raw=1
references
getGoogleCloudStorageFile
Get a file URL that can be linked from Google Cloud Storage.
arguments
filePath = ""; // required, the format is "project/filename"
usage
import getGoogleCloudStorageFile from "@letea/function/getGoogleCloudStorageFile";
getGoogleCloudStorageFile("storybook.letea.me/issue-img-webp.jpg");
// https://storage.googleapis.com/storybook.letea.me/issue-img-webp.jpg
notes
- Public bucket only
getParametersFromURL
Transform URL's search into an object.
arguments
url = ""; // required
usage
import getParametersFromURL from "@letea/function/getParametersFromURL";
getParametersFromURL("http://example.com/?a=1");
// { a: 1 }
getParametersFromURL("http://example.com/?a=1&b=2&c=3");
// { a: 1, b: 2, c: 3 }
getParametersFromURL("?a=1");
// { a: 1 }
getParametersFromURL("?a=1&b=2&c=3");
// { a: 1, b: 2, c: 3 }
getParametersFromURL("?a=%E5%80%BC");
// { a: "值" }
getParametersFromURL("http://example.com/");
// {}
getSearchFromParameters
Transform an object into a search for a URL.
arguments
parameters = {}; // required
usage
import getSearchFromParameters from "@letea/function/getSearchFromParameters";
getSearchFromParameters({ a: 1 });
// "?a=1"
getSearchFromParameters({ a: 1, b: 2, c: 3 });
// "?a=1&b=2&c=3"
getSearchFromParameters({ a: 1 });
// "?a=1"
getSearchFromParameters({ a: 1, b: 2, c: 3 });
// "?a=1&b=2&c=3"
getSearchFromParameters({ a: "值" });
// "?a=%E5%80%BC"
getSearchFromParameters({});
// ""
getShareToFacebookLink
Get a link that can direct to the Facebook Share Page.
arguments
url = ""; // optional, if empty, it's will using location.href.
usage
import getShareToFacebookLink from "@letea/function/getShareToFacebookLink";
getShareToFacebookLink();
// "https://www.facebook.com/sharer/sharer.php?u={location.href}"
getShareToFacebookLink("https://google.com");
// "https://www.facebook.com/sharer/sharer.php?u=https://google.com"
notes
- Only work on browsers.
references
getShareToLineLink
Get a link that can direct to the Line Share Page.
arguments
arguments = {
url: "", // optional, if empty, it's will using location.href.
message: "", // optional
};
usage
import getShareToLineLink from "@letea/function/getShareToLineLink";
getShareToLineLink();
// "http://line.naver.jp/R/msg/text/?%0D%0A{location.href}"
getShareToLineLink({ url: "https://google.com", message: "OK Google" });
// "http://line.naver.jp/R/msg/text/?OK%20Google%0D%0Ahttps://google.com"
notes
- Only work on browsers.
references
getURLWithoutParameters
Trim URL's search.
arguments
url = ""; // required
usage
import getURLWithoutParameters from "@letea/function/getURLWithoutParameters";
getURLWithoutParameters("http://example.com/?a=1");
// http://example.com/
getURLWithoutParameters("http://example.com/?a=1&b=2&c=3");
// http://example.com/
getURLWithoutParameters("http://example.com/?a=%E5%80%BC");
// http://example.com/
getURLWithoutParameters("http://example.com/");
// http://example.com/
getURLWithoutTrackingParameters
To filter URL's search(Tracking Parameters), including Google, Facebook for now.
arguments
url = ""; // required
usage
import getURLWithoutTrackingParameters from "@letea/function/getURLWithoutTrackingParameters";
getURLWithoutTrackingParameters(
"http://google.com/?utm_source=value&utm_medium=value&utm_campaign=value&utm_term=value&utm_content=value"
);
// "http://google.com/"
getURLWithoutTrackingParameters(
"http://facebook.com/?ad_id=value&adset_id=value&campaign_id=value&ad_name=value&adset_name=value&campaign_name=value&placement=value&site_source_name=value&fclid=value"
);
// "http://facebook.com/"
getURLWithoutTrackingParameters(
"http://google.com/?a=123&utm_source=value&utm_medium=value&utm_campaign=value&utm_term=value&utm_content=value&gclid=value"
);
// "http://google.com/?a=123"
references
User-Agent
checkIsAndroid
Check is Android by the window.navigator.userAgent
usage
import checkIsAndroid from "@letea/function/checkIsAndroid";
// Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
checkIsAndroid();
// true
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
checkIsAndroid();
// false
notes
- Only work on browsers.
checkIsChrome
Check is Chrome by the window.navigator.userAgent.
usage
import checkIsChrome from "@letea/function/checkIsChrome";
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
checkIsChrome();
// true
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0
checkIsChrome();
// false
notes
- Only work on browsers.
checkIsDesktop
Check is Desktop Device by the window.navigator.userAgent.
usage
import checkIsDesktop from "@letea/function/checkIsDesktop";
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
checkIsDesktop();
// true
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
checkIsDesktop();
// true
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1
checkIsDesktop();
// false
notes
- Only work on browsers.
checkIsEdge
Check is Edge by the window.navigator.userAgent.
usage
import checkIsEdge from "@letea/function/checkIsEdge";
// Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 EdgiOS/44.11.15 Mobile/15E148 Safari/605.1.15
checkIsEdge();
// true
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0
checkIsEdge();
// false
notes
- Only work on browsers.
checkIsFirefox
Check is Firefox by the window.navigator.userAgent.
usage
import checkIsFirefox from "@letea/function/checkIsFirefox";
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0
checkIsFirefox();
// true
// Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 EdgiOS/44.11.15 Mobile/15E148 Safari/605.1.15
checkIsFirefox();
// false
notes
- Only work on browsers.
checkIsInAppBrowserByFacebook
Check is InAppBrowser by Facebook using window.navigator.userAgent.
usage
import checkIsInAppBrowserByFacebook from "@letea/function/checkIsInAppBrowserByFacebook";
// Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/79.0.3945.136 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/255.0.0.33.121;]
checkIsInAppBrowserByFacebook();
// true
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari Line/10.0.2
checkIsInAppBrowserByFacebook();
// false
notes
- Only work on browsers.
checkIsInAppBrowserByLine
Check is InAppBrowser by Line using window.navigator.userAgent.
usage
import checkIsInAppBrowserByLine from "@letea/function/checkIsInAppBrowserByLine";
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari Line/10.0.2
checkIsInAppBrowserByLine();
// true
// Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/79.0.3945.136 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/255.0.0.33.121;]
checkIsInAppBrowserByLine();
// false
notes
- Only work on browsers.
checkIsInternetExplorer
Check is Internet Explorer by the window.navigator.userAgent
usage
import checkIsInternetExplorer from "@letea/function/checkIsInternetExplorer";
// Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko
checkIsInternetExplorer();
// true
// Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)
checkIsInternetExplorer();
// true
// Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)
checkIsInternetExplorer();
// true
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
checkIsInternetExplorer();
// false
notes
- Only work on browsers.
checkIsiOS
Check is iOS by the window.navigator.userAgent.
usage
import checkIsiOS from "@letea/function/checkIsiOS";
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
checkIsiOS();
// true
// Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1
checkIsiOS();
// true
// Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
checkIsiOS();
// false
notes
- Only work on browsers.
checkIsiPad
Check is iPad by the window.navigator.userAgent.
usage
import checkIsiPad from "@letea/function/checkIsiPad";
// Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1
checkIsiPad();
// true
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
checkIsiPad();
// false
notes
- Only work on browsers.
checkIsiPhone
Check is iPhone by the window.navigator.userAgent.
usage
import checkIsiPhone from "@letea/function/checkIsiPhone";
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
checkIsiPhone();
// true
// Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1
checkIsiPhone();
// false
notes
- Only work on browsers.
checkIsMac
Check is macOS by the window.navigator.userAgent.
usage
import checkIsMac from "@letea/function/checkIsMac";
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
checkIsMac();
// true
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48
checkIsMac();
// false
notes
- Only work on browsers.
checkIsMobile
Check is Mobile Device by the window.navigator.userAgent.
usage
import checkIsMobile from "@letea/function/checkIsMobile";
// Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
checkIsMobile();
// true
// Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
checkIsMobile();
// true
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
checkIsMobile();
// false
notes
- Only work on browsers.
checkIsSafari
Check is Safari by the window.navigator.userAgent.
usage
import checkIsSafari from "@letea/function/checkIsSafari";
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
checkIsSafari();
// true
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48
checkIsSafari();
// false
notes
- Only work on browsers.
checkIsSamsungBrowser
Check is Samsung Browser by the window.navigator.userAgent.
usage
import checkIsSamsungBrowser from "@letea/function/checkIsSamsungBrowser";
// Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-N9750) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/10.2 Chrome/71.0.3578.99 Mobile Safari/537.36
checkIsSamsugnBrowser();
// true
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48
checkIsSamsugnBrowser();
// false
notes
- Only work on browsers.
checkIsWindows
Check is Windows by the window.navigator.userAgent.
usage
import checkIsWindows from "@letea/function/checkIsWindows";
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48
checkIsWindows();
// true
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
checkIsWindows();
// false
notes
- Only work on browsers.
getAndroidVersion
Get Android Version from the window.navigator.userAgent. If the userAgent is not iOS or not found, it will return "".
usage
import getAndroidVersion from "@letea/function/getAndroidVersion";
// User-Agent: Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
getAndroidVersion();
// "8.0.0"
// User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
getAndroidVersion();
// ""
notes
- Only work on browsers.
getiOSVersion
Get iOS Version from window.navigator.userAgent. If the userAgent is not iOS or not found, it will return "".
usage
import getiOSVersion from "@letea/function/getiOSVersion";
// User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/79.0.3945.73 Mobile/15E148 Safari/604.1
getiOSVersion();
// "13.3"
// User-Agent: Mozilla/5.0 (Linux; Android 8.0.0; HTC_M10h) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
getiOSVersion();
// ""
notes
- Only work on browsers.
Video
getVideoType
Get video type for video & source tag.
arguments
src = ""; // required
usage
import getVideoType from "@letea/function/getVideoType";
getVideoType("https://example.com/file/video.mp4");
// "video/mp4"
Window
checkIsClipboardSupported
Check the browser is supports the clipboard or not.
usage
import checkIsClipboardSupported from "@letea/function/checkIsClipboardSupported";
// When Browser support clipboard
checkIsClipboardSupported();
// true
// When Browser is not support clipboard
checkIsClipboardSupported();
// false
notes
- Only work on browsers.
references
checkIsFullscreen
Check the browser is fullscreen or not.
usage
import checkIsFullscreen from "@letea/function/checkIsFullscreen";
// When Fullscreen
checkIsFullscreen();
// true
// When Normal
checkIsFullscreen();
// false
notes
- Only work on browsers.
checkIsWindowFocused
Check Window is focused or not.
usage
import checkIsWindowFocused from "@letea/function/checkIsWindowFocused";
checkIsWindowFocused();
// true (when window has focus actually.)
notes
- Only work on browsers.
references
checkIsWindowLoaded
Check Window is loaded or not.
usage
import checkIsWindowLoaded from "@letea/function/checkIsWindowLoaded";
checkIsWindowLoaded();
// true
notes
- Only work on browsers.