A function library.
npm install @letea/functions
- checkIsArray
- checkIsArrayEmpty
- getDuplicateValuesFromArray
- getIntersectionArray
- getNextIndexInArray
- getRandomIndexInArray
- getRandomValueInArray
- getReverseArray
- getShuffleArray
- getSortedArray
- getTrulyArray
- getUniqueArray
- getUniqueValuesFromArray
- checkIsEmailValid
- checkIsMobileNumberValid
- checkIsString
- getRandomString
- getSimpleChinese
- getStringify
- getStringWithSpaceBetweenHalfAndFullWidth
- getTraditionalChinese
- getHoursFromMinutes
- getHoursFromSeconds
- getMillisecondsFromSeconds
- getMinutesFromHours
- getMinutesFromSeconds
- getSecondsFromHours
- getSecondsFromMilliseconds
- getSecondsFromMinutes
- checkIsAbsoluteURL
- getCurrentURL
- getDropboxRawFileURL
- getGoogleCloudStorageFile
- getParametersFromURL
- getSearchFromParameters
- getShareToFacebookLink
- getShareToLineLink
- getURLWithoutParameters
- getURLWithoutTrackingParameters
- checkIsAndroid
- checkIsChrome
- checkIsDesktop
- checkIsEdge
- checkIsFirefox
- checkIsInAppBrowserByFacebook
- checkIsInAppBrowserByLine
- checkIsInternetExplorer
- checkIsiOS
- checkIsiPad
- checkIsiPhone
- checkIsMac
- checkIsMobile
- checkIsSafari
- checkIsSamsungBrowser
- checkIsWindows
- getAndroidVersion
- getiOSVersion
Check data type is an array or not.
value; // required, any type is accepted.
import checkIsArray from "@letea/function/checkIsArray";
checkIsArray([1, 2, 3]);
// true
checkIsArray("abc");
// false
Check the array is empty or not.
array = []; // required
import checkIsArrayEmpty from "@letea/function/checkIsArrayEmpty";
checkIsArrayEmpty([]);
// true
checkIsArrayEmpty([1, 2, 3]);
// false
Get an array with duplicate values from the original array.
array = []; // required
import getDuplicateValuesFromArray from "@letea/function/getDuplicateValuesFromArray";
const array = [1, 2, 3, 2, 3, 4, 5];
getDuplicateValuesFromArray(array);
// [2, 3]
Get an intersection array.
arguments = {
array1: [], // required
array2: [], // required
};
import getIntersectionArray from "@letea/function/getIntersectionArray";
getIntersectionArray({
array1: ["a", "b", "c"],
array2: ["b", "c", "d", "e", "f"],
});
// ["b", "c"]
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 = {
array: [], // required
index: 0, // optional
isLoop: false, // optional
};
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
Get a random index from the array.
array = []; // required
import getRandomIndexInArray from "@letea/function/getRandomIndexInArray";
const array = ["a", "b", "c", "d", "e"];
getRandomIndexInArray(array);
Get a random value from the array.
array = []; // required
import getRandomValueInArray from "@letea/function/getRandomValueInArray";
const array = [1, 2, 3, 4, 5];
getRandomValueInArray(array);
Get an array with reversed.
array = []; // required
import getReverseArray from "@letea/function/getReverseArray";
const array = [1, 2, 3, 4, 5];
getReverseArray(array);
// [5, 4, 3, 2 ,1]
Get an array with shuffled.
array = []; // required
import getShuffleArray from "@letea/function/getShuffleArray";
const array = [1, 2, 3, 4, 5];
getShuffleArray(array);
// [5, 3, 2, 1, 4]...
Get a sorted array.
array = []; // required
import getSortedArray from "@letea/function/getSortedArray";
const array = [5, 3, 2, 1, 4];
getSortedArray(array);
// [1, 2, 3, 4, 5]
Get an array with true values.
array = []; // required
import getTrulyArray from "@letea/function/getTrulyArray";
const array = [0, "test", "", NaN, 9, true, undefined, false, Infinity, {}, []];
getTrulyArray(array);
// ["test", 9, true, Infinity, {}, []]
- Infinity is a true value.
Get a unique array.
array = []; // required
import getUniqueArray from "@letea/function/getUniqueArray";
getUniqueArray([1, 2, 3, "a", "b", 2, "c", "a"]);
// [1, 2, 3, "a", "b", "c"]
Get an array with unique values from the original array.
array = []; // required
import getUniqueValuesFromArray from "@letea/function/getUniqueValuesFromArray";
const array = [1, 2, 3, 2, 3, 4, 5];
getUniqueValuesFromArray(array);
// [1, 4, 5]
Check an environment is a browser or not by window and document.
import checkIsBrowser from "@letea/function/checkIsBrowser";
// Browser
checkIsBrowser();
// true
// Node.js
checkIsBrowser();
// false
Facebook's InAppBrowser has a bug: window size is not correct before the window loaded. So we need to check is loaded or not.
import checkIsInAppBrowserByFacebookNotLoaded from "@letea/function/checkIsInAppBrowserByFacebookNotLoaded";
checkIsInAppBrowserByFacebookNotLoaded();
// true
- Only work on browsers.
Check the browser is supports canvas or not.
import checkIsCanvasSupported from "@letea/function/checkIsCanvasSupported";
checkIsCanvasSupported();
// true
- Only work on browsers.
Check data type is function or not.
value; // required, any type is accepted.
import checkIsFunction from "@letea/function/checkIsFunction";
checkIsFunction(() => {});
// true
checkIsFunction(function () {});
// true
checkIsFunction("function");
// false
Check the browser is supports local storage or not.
import checkIsLocalStorageSupported from "@letea/function/checkIsLocalStorageSupported";
checkIsLocalStorageSupported();
// true
- Only work on browsers.
Check the number is an integer or not.
value; // required, any type is accepted.
import checkIsInteger from "@letea/function/checkIsInteger";
checkIsInteger(1);
// true
checkIsInteger(1.5);
// false
Check data type is number or not.
value; // required, any type is accepted.
import checkIsNumber from "@letea/function/checkIsNumber";
checkIsNumber(123);
// true;
checkIsNumber("abc");
// false
checkIsNumber(NaN);
// false
checkIsNumber(Infinity);
// false
Get a float number with fixed option.
arguments = {
number: 0, // required.
fixed: 0, // optional.
};
import getFixedNumber from "@letea/function/getFixedNumber";
getFixedNumber({
number: 3.1415926535,
fixed: 5,
});
// 3.14159
Get a random number.
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.
};
import getRandomNumber from "@letea/function/getRandomNumber";
getRandomNumber({
maxNumber: 10,
});
// 6
getRandomNumber({
maxNumber: 10,
minNumber: 0,
isFloat: true,
});
// 3.5476
Check data type is an object or not.
value; // required, any type is accepted.
import checkIsObject from "@letea/function/checkIsObject";
checkIsObject({ a: 123 });
// true;
checkIsObject([1, 2, 3]);
// false
checkIsObject("abc");
// false
Check the object is empty or not.
object = {}; // required
import checkIsObjectEmpty from "@letea/function/checkIsObjectEmpty";
checkIsObjectEmpty({});
// true
checkIsObjectEmpty({ a: 1 });
// false
Get the value from an object, including multiple levels.
arguments = {
object: {}, // required
keys: "", // required
};
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
Check email format is valid or not.
email = ""; // required
import checkIsEmailValid from "@letea/function/checkIsEmailValid";
checkIsEmailValid("geon@ihateregex.io");
checkIsEmailValid("test@gmail.com");
checkIsEmailValid("mail@test.org");
checkIsEmailValid("mail@testing.com");
// true
checkIsEmailValid();
checkIsEmailValid("hello@");
checkIsEmailValid("@test");
checkIsEmailValid("email@gmail");
checkIsEmailValid("theproblem@");
// false
Check mobile number format is valid or not.
mobileNumber = ""; // required
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
Check data type is a string or not.
value; // required, any type is accepted.
import checkIsString from "@letea/function/checkIsString";
checkIsString("abc");
// true
checkIsString(123);
// false
checkIsString({ a: 1 });
// false
Get a random string.
length = 3; // optional
import getRandomString from "@letea/function/getRandomString";
getRandomString();
// "ZI4"
getRandomString(5);
// "j0C4N"
Transform Traditional Chinese into Simple Chinese.
value = ""; // required
import getSimpleChinese from "@letea/function/getSimpleChinese";
getSimpleChinese("繁體字、簡體字");
// "繁体字、简体字"
Transform any data into a string.
value; // required, any type is accepted.
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]"
Get a string with space between half and full with characters.
text = ""; // required
import getStringWithSpaceBetweenHalfAndFullWidth from "@letea/function/getStringWithSpaceBetweenHalfAndFullWidth";
getStringWithSpaceBetweenHalfAndFullWidth("我是很busy,因為我很多things要do");
// "我是很 busy,因為我很多 things 要 do"
Transform Simple Chinese into Traditional Chinese.
value = ""; // required
import getTraditionalChinese from "@letea/function/getTraditionalChinese";
getTraditionalChinese("繁体字、简体字");
// "繁體字、簡體字"
Minutes to hours.
minutes = 0; // required
import getHoursFromMinutes from "@letea/function/getHoursFromMinutes";
getHoursFromMinutes(60);
// 1
Seconds to hours.
seconds = 0; // required
import getHoursFromSeconds from "@letea/function/getHoursFromSeconds";
getHoursFromSeconds(3600);
// 1
Seconds to milliseconds
seconds = 0; // required
import getMillisecondsFromSeconds from "@letea/function/getMillisecondsFromSeconds";
getMillisecondsFromSeconds(1);
// 1000
Hours to minutes.
hours = 0; // required
import getMinutesFromHours from "@letea/function/getMinutesFromHours";
getMinutesFromHours(1);
// 60
Seconds to minutes.
seconds = 0; // required
import getMinutesFromSeconds from "@letea/function/getMinutesFromSeconds";
getMinutesFromSeconds(60);
// 1
Hours to seconds.
hours = 0; // required
import getSecondsFromHours from "@letea/function/getSecondsFromHours";
getSecondsFromHours(1);
// 3600
Milliseconds to seconds.
milliseconds = 0; // required
import getSecondsFromMilliseconds from "@letea/function/getSecondsFromMilliseconds";
getSecondsFromMilliseconds(1000);
// 1
Minutes to Seconds.
minutes = 0; // required
import getSecondsFromMinutes from "@letea/function/getSecondsFromMinutes";
getSecondsFromMinutes(1);
// 60
Check the URL is absolute or not.
url = ""; // required
import checkIsAbsoluteURL from "@letea/function/checkIsAbsoluteURL";
checkIsAbsoluteURL("https://google.com");
// true
checkIsAbsoluteURL("ftp://www.myserver.net");
// true
checkIsAbsoluteURL("/foo/bar");
// false
Get current site's URL. For now can get URL without search or trim tracking parameters(Google & Facebook).
arguments = {
hasSearch: true, // optional.
trimTracking: false, // optional, if hasSearch is true then trimTracking will do nothing.
};
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
- Only work on browsers.
Get a file URL that can be linked from Dropbox directly.
filePath = ""; // required, the format is "id/filename"
import getDropboxRawFileURL from "@letea/function/getDropboxRawFileURL";
getDropboxRawFileURL("0xp0v2cm3asbk0h/sample.jpg");
// https://www.dropbox.com/s/0xp0v2cm3asbk0h/sample.jpg?raw=1
Get a file URL that can be linked from Google Cloud Storage.
filePath = ""; // required, the format is "project/filename"
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
- Public bucket only
Transform URL's search into an object.
url = ""; // required
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/");
// {}
Transform an object into a search for a URL.
parameters = {}; // required
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({});
// ""
Get a link that can direct to the Facebook Share Page.
url = ""; // optional, if empty, it's will using location.href.
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"
- Only work on browsers.
Get a link that can direct to the Line Share Page.
arguments = {
url: "", // optional, if empty, it's will using location.href.
message: "", // optional
};
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"
- Only work on browsers.
Trim URL's search.
url = ""; // required
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/
To filter URL's search(Tracking Parameters), including Google, Facebook for now.
url = ""; // required
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"
Check is Android by the window.navigator.userAgent
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
- Only work on browsers.
Check is Chrome by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Desktop Device by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Edge by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Firefox by the window.navigator.userAgent.
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
- Only work on browsers.
Check is InAppBrowser by Facebook using window.navigator.userAgent.
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
- Only work on browsers.
Check is InAppBrowser by Line using window.navigator.userAgent.
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
- Only work on browsers.
Check is Internet Explorer by the window.navigator.userAgent
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
- Only work on browsers.
Check is iOS by the window.navigator.userAgent.
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
- Only work on browsers.
Check is iPad by the window.navigator.userAgent.
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
- Only work on browsers.
Check is iPhone by the window.navigator.userAgent.
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
- Only work on browsers.
Check is macOS by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Mobile Device by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Safari by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Samsung Browser by the window.navigator.userAgent.
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
- Only work on browsers.
Check is Windows by the window.navigator.userAgent.
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
- Only work on browsers.
Get Android Version from the window.navigator.userAgent. If the userAgent is not iOS or not found, it will return "".
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();
// ""
- Only work on browsers.
Get iOS Version from window.navigator.userAgent. If the userAgent is not iOS or not found, it will return "".
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();
// ""
- Only work on browsers.
Get video type for video & source tag.
src = ""; // required
import getVideoType from "@letea/function/getVideoType";
getVideoType("https://example.com/file/video.mp4");
// "video/mp4"
Check the browser is supports the clipboard or not.
import checkIsClipboardSupported from "@letea/function/checkIsClipboardSupported";
// When Browser support clipboard
checkIsClipboardSupported();
// true
// When Browser is not support clipboard
checkIsClipboardSupported();
// false
- Only work on browsers.
Check the browser is fullscreen or not.
import checkIsFullscreen from "@letea/function/checkIsFullscreen";
// When Fullscreen
checkIsFullscreen();
// true
// When Normal
checkIsFullscreen();
// false
- Only work on browsers.
Check Window is focused or not.
import checkIsWindowFocused from "@letea/function/checkIsWindowFocused";
checkIsWindowFocused();
// true (when window has focus actually.)
- Only work on browsers.
Check Window is loaded or not.
import checkIsWindowLoaded from "@letea/function/checkIsWindowLoaded";
checkIsWindowLoaded();
// true
- Only work on browsers.