Last active
September 13, 2022 12:36
-
-
Save kostasxyz/b539a1e05312258c414e07f7078aa1df to your computer and use it in GitHub Desktop.
Javascript utility functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Build css classnames string. | |
| * | |
| */ | |
| function clx() { | |
| let classes = []; | |
| for (let i = 0; i < arguments.length; i++) { | |
| let arg = arguments[i]; | |
| if (!arg) { | |
| continue; | |
| } | |
| let argType = typeof arg; | |
| if (argType === 'string' || argType === 'number') { | |
| classes.push(arg); | |
| } | |
| else if (Array.isArray(arg) && arg.length) { | |
| let inner = classnames.apply(null, arg); | |
| if (inner) { | |
| classes.push(inner); | |
| } | |
| } | |
| else if (argType === 'object') { | |
| for (let key in arg) { | |
| if (hasOwnProperty.call(arg, key) && arg[key]) { | |
| classes.push(key); | |
| } | |
| } | |
| } | |
| } | |
| return classes.join(' '); | |
| } | |
| export default clx; | |
| /** | |
| * milToTime | |
| * | |
| * @param mils number | |
| */ | |
| export const milToTime = (mils) => new Date(mils).toTimeString().split(' ')[0]; | |
| /** | |
| * Return as array | |
| * | |
| * @param {any} value | |
| * @returns array | |
| */ | |
| export const asArray = value => { | |
| if (!value) return []; | |
| return Array.isArray(value) ? value : [value]; | |
| } | |
| /** | |
| * Consoel.log wrapper | |
| * @param {mixed} data | |
| */ | |
| export const logit = (data, title = null) => { | |
| if(1==1) { | |
| title ? console.log(title, data) : console.log(data); | |
| console.log("---------------------------------------\n"); | |
| } | |
| } | |
| /** | |
| * Slugify a string | |
| * | |
| * @param {string} text | |
| * @return {string} text | |
| */ | |
| export const slug = (text) => { | |
| return text | |
| .toString() | |
| .toLowerCase() | |
| .replace(/\s+/g, '-') | |
| .replace(/[^\w-]+/g, '') | |
| .replace(/--+/g, '-') | |
| .replace(/^-+/, '') | |
| .replace(/-+$/, ''); | |
| }; | |
| /** | |
| * Random int | |
| * | |
| */ | |
| export const randomInt = (min = 111, max = 999) => { | |
| return Math.floor(Math.random() * (max - min) ) + min; | |
| } | |
| /** | |
| * Unique ID | |
| * | |
| */ | |
| export const unid = (seed = 1) => { | |
| return parseInt(Date.now() + '' + randomInt(1000000, 10000000) + '' + seed); | |
| } | |
| /** | |
| * Unique string ID | |
| * | |
| */ | |
| export const rid = (pre = '_', seed = 1) => { | |
| return pre + unid(); | |
| } | |
| /** | |
| * A tiny (228B) utility for constructing className strings conditionally. | |
| * | |
| * @link https://github.com/lukeed/clsx | |
| * @returns string | |
| */ | |
| export function clx() { | |
| const toVal = (mix) => { | |
| var k, y, str=''; | |
| if (typeof mix === 'string' || typeof mix === 'number') { | |
| str += mix; | |
| } else if (typeof mix === 'object') { | |
| if (Array.isArray(mix)) { | |
| for (k=0; k < mix.length; k++) { | |
| if (mix[k]) { | |
| if (y = toVal(mix[k])) { | |
| str && (str += ' '); | |
| str += y; | |
| } | |
| } | |
| } | |
| } else { | |
| for (k in mix) { | |
| if (mix[k]) { | |
| str && (str += ' '); | |
| str += k; | |
| } | |
| } | |
| } | |
| } | |
| return str; | |
| } | |
| let i=0, tmp, x, str = ''; | |
| while (i < arguments.length) { | |
| if (tmp = arguments[i++]) { | |
| if (x = toVal(tmp)) { | |
| str && (str += ' '); | |
| str += x | |
| } | |
| } | |
| } | |
| return str; | |
| } | |
| /** | |
| * Is Nill | |
| * @param {*} data | |
| * @returns | |
| */ | |
| export const isNil = (data) => data === null || data === undefined || (Array.isArray(data) && data.length === 0); | |
| /** | |
| * Random Color | |
| * @returns | |
| */ | |
| export const randomColor = () => '#' + Math.floor(Math.random()*16777215).toString(16); | |
| /** | |
| * getCookie | |
| * @param {string} name | |
| * @returns string | |
| */ | |
| export const getCookie = (name) => { | |
| var nameEQ = name + '=' | |
| var ca = document.cookie.split(';') | |
| for(let i = 0; i < ca.length; i++) { | |
| var c = ca[i] | |
| while (c.charAt(0) === ' ') c = c.substring(1,c.length) | |
| if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length) | |
| } | |
| return null | |
| } | |
| /** | |
| * validateEmail | |
| * @param {string} email | |
| * @returns | |
| */ | |
| export const validateEmail = (email) => { | |
| return String(email) | |
| .toLowerCase() | |
| .match( | |
| // eslint-disable-next-line | |
| /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i | |
| ) | |
| } | |
| /** | |
| * Clone array of objects | |
| * | |
| */ | |
| export const cloneObjArray = (data) => { | |
| Array.isArray(data) && data.length ? data.map(x => ({...x})) : null; | |
| } | |
| /** | |
| * Method for getting query string parameter by name | |
| * @param {string} name | |
| * @returns {string} | |
| */ | |
| export const getQueryParamByName = (name) => { | |
| var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); | |
| return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); | |
| } | |
| /** | |
| * Use Intervention image cache route | |
| * and size templates. | |
| * Updated in .env | |
| * | |
| * @param {string/integer} size | |
| * @param {string} filename | |
| * @returns | |
| */ | |
| export const getImgCache = (filename, size = 'fhd') => { | |
| if(!filename) return null; | |
| return `/${process.env.MIX_IMG_CACHE_ROUTE}/${size}/${filename}`; | |
| } | |
| /** | |
| * Inject a head tag script | |
| * | |
| * @param {string} loadScript | |
| * @returns void | |
| */ | |
| export const loadScript = (url) => { | |
| let index = window.document.getElementsByTagName('script')[0]; | |
| let script = window.document.createElement('script'); | |
| script.src = url; | |
| script.async = true; | |
| script.defer = true; | |
| document.body.appendChild(script); | |
| index.parentNode.insertBefore(script, index); | |
| } | |
| /** | |
| * Inject a head tag script | |
| * | |
| * @param {string} loadScript | |
| * @returns void | |
| */ | |
| export const parseProtocol = (url) => { | |
| const parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url); | |
| if (!parsedURL) { | |
| return false; | |
| } | |
| const [, protocol, fullhost, fullpath] = parsedURL; | |
| return protocol; | |
| } | |
| /** | |
| * patterns | |
| * | |
| */ | |
| export const patterns = { | |
| whitespace: /[ \t\r\n]/, | |
| start_whitespace: /^[ \t\r\n]*/, | |
| end_whitespace: /[ \t\r\n]*$/, | |
| start_newline: /^\r?\n/, | |
| dimensions: /^(?:offset|client)(?:Width|Height)$/, | |
| passwd: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%]).{8,24}$/, | |
| } | |
| /** | |
| * Normalize gr chars | |
| * | |
| */ | |
| export const nGr = (text) => { | |
| return text.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); | |
| } | |
| /** | |
| * Normalize polytonic gr chars | |
| * | |
| */ | |
| export const nPolyGr = (text) => { | |
| return text.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); | |
| } | |
| /** | |
| * Is element in view | |
| * | |
| */ | |
| export const elInView = (el) => { | |
| let rect = el.getBoundingClientRect(); | |
| let elemTop = rect.top; | |
| let elemBottom = rect.bottom; | |
| // Only completely visible elements return true: | |
| let isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight); | |
| // Partially visible elements return true: | |
| //isVisible = elemTop < window.innerHeight && elemBottom >= 0; | |
| return isVisible; | |
| } | |
| /** | |
| * Add a script tag | |
| * | |
| */ | |
| export const loadScript = (url) => { | |
| let index = window.document.getElementsByTagName('script')[0]; | |
| let script = window.document.createElement('script'); | |
| script.src = url; | |
| script.async = true; | |
| script.defer = true; | |
| document.body.appendChild(script); | |
| index.parentNode.insertBefore(script, index); | |
| } | |
| /** | |
| * Smooth scroll to the top of the page | |
| * | |
| */ | |
| export const scrollToTop = () => { | |
| const c = document.documentElement.scrollTop || document.body.scrollTop; | |
| if (c > 0) { | |
| window.requestAnimationFrame(scrollToTop); | |
| window.scrollTo(0, c - c / 8); | |
| } | |
| } | |
| /** | |
| * The browser tab of the page is focused | |
| * | |
| * @return {Boolean} | |
| */ | |
| const isBrowserTabFocused = () => !document.hidden | |
| /** | |
| * Get the scroll position of the current page | |
| * | |
| * @return { Object } | |
| */ | |
| export const getScrollPosition = (el = window) => ({ | |
| x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft, | |
| y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop | |
| }); | |
| /** | |
| * hasClass | |
| * | |
| */ | |
| export const hasClass = (el, className) => el.classList.contains(className); | |
| /** | |
| * Fetch all images within an elemen | |
| * | |
| * @return { Set } | |
| */ | |
| export const getImages = (el, duplicates = false) => { | |
| const images = [...el.getElementsByTagName('img')].map(img => img.getAttribute('src')); | |
| return includeDuplicates ? images : [...new Set(images)]; | |
| }; | |
| /** | |
| * Is device mobile | |
| * | |
| * @return { Boolean } | |
| */ | |
| export const isMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? true : false; | |
| /** | |
| * Get the current url | |
| * | |
| * @return { String } | |
| */ | |
| export const currentUrl = () => window.location.href; | |
| /** | |
| * Toggle a class for an elementge | |
| * | |
| */ | |
| export const toggleClass = (el, className) => el.classList.toggle(className); | |
| /** | |
| * Slugify a string | |
| * | |
| * @param {string} text | |
| * @return {string} text | |
| */ | |
| export const slugify = (text) => { | |
| return text | |
| .toString() | |
| .toLowerCase() | |
| .replace(/\s+/g, '_') | |
| .replace(/[^\w-]+/g, '') | |
| .replace(/--+/g, '_') | |
| .replace(/^-+/, '') | |
| .replace(/-+$/, ''); | |
| }; | |
| /** | |
| * Months | |
| * | |
| * @return {Array} text | |
| */ | |
| export const months = () => { | |
| return [ | |
| {name: 'January', value: 0}, | |
| {name: 'February', value: 1}, | |
| {name: 'March', value: 2}, | |
| {name: 'April', value: 3}, | |
| {name: 'May', value: 4}, | |
| {name: 'June', value: 5}, | |
| {name: 'July', value: 6}, | |
| {name: 'August', value: 7}, | |
| {name: 'September', value: 8}, | |
| {name: 'October', value: 9}, | |
| {name: 'November', value: 10}, | |
| {name: 'December', value: 11}, | |
| ]; | |
| } | |
| /** | |
| * Hex color to rgb | |
| * | |
| * @param {String} hex Hex color | |
| * @return {String} text | |
| */ | |
| export const hexToRgb = (hex) => { | |
| var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
| return result ? | |
| `${parseInt(result[1], 16)},${parseInt(result[2], 16)},${parseInt(result[3], 16)}` | |
| : null; | |
| } | |
| /** | |
| * Does an array have some values of another array | |
| * | |
| * @param {Array} arr1 | |
| * @param {Array} arr2 | |
| * @return {Boolean} | |
| */ | |
| export const containSome = (arr1, arr2) => { | |
| return arr1.some(r => arr2.indexOf(r) >= 0); | |
| } | |
| /** | |
| * Eencode a set of form elements as an object | |
| * | |
| * @param {HTMLFormElement} form The form element | |
| * @return {Object]} | |
| */ | |
| export const formToObject = form => Array.from(new FormData(form)).reduce( | |
| (acc, [key, value]) => ({ | |
| ...acc, | |
| [key]: value | |
| }),{} | |
| ); | |
| /** | |
| * [description] | |
| * @param {[type]} formElements [description] | |
| * @return {[type]} [description] | |
| */ | |
| export const buildFormData = (formElements) => { | |
| const formData = new FormData(); | |
| for (let i = 0; i < formElements.length; i++) { | |
| let input = formElements[i]; | |
| // @todo Remove submit button from form | |
| if(input.id !== 'submit') { | |
| formData.append(input.id, input.value); | |
| } | |
| } | |
| return formData; | |
| } | |
| /** | |
| * Copy a string to the clipboard | |
| * | |
| * @param {String} str | |
| */ | |
| export const copyToClipboard = str => { | |
| const el = document.createElement('textarea'); | |
| el.value = str; | |
| el.setAttribute('readonly', ''); | |
| el.style.position = 'absolute'; | |
| el.style.left = '-9999px'; | |
| document.body.appendChild(el); | |
| const selected = | |
| document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; | |
| el.select(); | |
| document.execCommand('copy'); | |
| document.body.removeChild(el); | |
| if (selected) { | |
| document.getSelection().removeAllRanges(); | |
| document.getSelection().addRange(selected); | |
| } | |
| }; | |
| /** | |
| * Array Chunk | |
| * | |
| * @param {array} array | |
| * @param {number} chunks | |
| * @param {addOrphansToLastGroup} boolean | |
| */ | |
| export const arrayChunk__REFACTORING = (array, chunks, addOrphansToLastGroup) => { | |
| if(!array.length) return []; | |
| addOrphansToLastGroup = addOrphansToLastGroup || true; | |
| chunks = chunks || 5; | |
| var groups = [], i; | |
| var orphans = array.length % chunks; | |
| var popped = null; | |
| if(addOrphansToLastGroup && orphans < Math.ceil(chunks/2)) { | |
| popped = array.splice(-orphans, orphans); | |
| } | |
| for(i = 0; i < array.length; i += chunks) { | |
| groups.push(array.slice(i, i + chunks)); | |
| } | |
| if(popped && popped.length) { | |
| popped.forEach((p, i) => { | |
| groups[groups.length-1].push(p); | |
| }); | |
| } | |
| return groups; | |
| } | |
| /** | |
| * Array Chunk | |
| * | |
| * @param {array} inputArray | |
| * @param {number} chunks | |
| * @param {addOrphansToLastGroup} boolean | |
| */ | |
| export const arrayChunk = (inputArray = [], perChunk) => { | |
| const result = inputArray.reduce((resultArray, item, index) => { | |
| const chunkIndex = Math.floor(index/perChunk) | |
| if(!resultArray[chunkIndex]) { | |
| resultArray[chunkIndex] = []; | |
| } | |
| resultArray[chunkIndex].push(item); | |
| return resultArray; | |
| }, []); | |
| return result; | |
| } | |
| /** | |
| * If the given value is not an array, wrap it in one. | |
| * | |
| * @param {Any} value | |
| * @return {Array} | |
| */ | |
| export const arrayWrap = (value) => { | |
| return Array.isArray(value) ? value : [value] | |
| } | |
| // simpleHash | |
| export const simpleHash = (str) => { | |
| let hash = 0; | |
| if (str.length == 0) { | |
| return hash; | |
| } | |
| for (let i = str.length; i >= 0; i--) { | |
| let char = str.charCodeAt(i); | |
| hash = ((hash<<5)-hash)+char; | |
| hash = hash & hash; // Convert to 32bit integer | |
| } | |
| return hash; | |
| } | |
| // Parse a Link header | |
| // Link:<https://example.org/.meta>; rel=meta | |
| // TODO: simplify! | |
| export const parseLinkHeader = (header) => { | |
| const linkExp = /<[^>]*>\s*(\s*;\s*[^()<>@,;:"/[\]?={} \t]+=(([^()<>@,;:"/[\]?={} \t]+)|("[^"]*")))*(,|$)/g; | |
| const paramExp = /[^()<>@,;:"/[\]?={} \t]+=(([^()<>@,;:"/[\]?={} \t]+)|("[^"]*"))/g; | |
| const linkMatch = header.match(linkExp); | |
| const rels = {}; | |
| for (let i = 0; i < linkMatch.length; i++) { | |
| const linkSplit = linkMatch[i].split('>'); | |
| const href = linkSplit[0].substring(1); | |
| const rel = linkSplit[1]; | |
| const relMatch = rel.match(paramExp); | |
| for (let j = 0; j < relMatch.length; j++) { | |
| const relSplit = relMatch[j].split('='); | |
| const relName = relSplit[1].replace(/["']/g, ''); | |
| rels[relName] = href; | |
| } | |
| } | |
| return rels.next || rels.prev ? rels : null; | |
| } | |
| // getQueryString | |
| export const getQueryString = ( name ) => { | |
| name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | |
| let regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); | |
| let results = regex.exec(location.search); | |
| return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | |
| } | |
| // Has own property wrapper | |
| export const objHas = (obj, path) => { | |
| return obj != null && hasOwnProperty.call(obj, path); | |
| } | |
| // Is a given value an array? | |
| // Delegates to ECMA5's native Array.isArray | |
| export const isArray = Array.isArray || function(obj) { | |
| return toString.call(obj) === '[object Array]'; | |
| }; | |
| // Determine the relative difference (percentage) between 2 values | |
| export const relDiff = (a, b) => { | |
| return 100 * Math.abs( ( a - b ) / ( (a+b)/2 ) ); | |
| }; | |
| /** | |
| * Countries | |
| * | |
| */ | |
| export const countries = [ | |
| {name: 'Afghanistan', value: 'AF'}, | |
| {name: 'Åland Islands', value: 'AX'}, | |
| {name: 'Albania', value: 'AL'}, | |
| {name: 'Algeria', value: 'DZ'}, | |
| {name: 'American Samoa', value: 'AS'}, | |
| {name: 'AndorrA', value: 'AD'}, | |
| {name: 'Angola', value: 'AO'}, | |
| {name: 'Anguilla', value: 'AI'}, | |
| {name: 'Antarctica', value: 'AQ'}, | |
| {name: 'Antigua and Barbuda', value: 'AG'}, | |
| {name: 'Argentina', value: 'AR'}, | |
| {name: 'Armenia', value: 'AM'}, | |
| {name: 'Aruba', value: 'AW'}, | |
| {name: 'Australia', value: 'AU'}, | |
| {name: 'Austria', value: 'AT'}, | |
| {name: 'Azerbaijan', value: 'AZ'}, | |
| {name: 'Bahamas', value: 'BS'}, | |
| {name: 'Bahrain', value: 'BH'}, | |
| {name: 'Bangladesh', value: 'BD'}, | |
| {name: 'Barbados', value: 'BB'}, | |
| {name: 'Belarus', value: 'BY'}, | |
| {name: 'Belgium', value: 'BE'}, | |
| {name: 'Belize', value: 'BZ'}, | |
| {name: 'Benin', value: 'BJ'}, | |
| {name: 'Bermuda', value: 'BM'}, | |
| {name: 'Bhutan', value: 'BT'}, | |
| {name: 'Bolivia', value: 'BO'}, | |
| {name: 'Bosnia and Herzegovina', value: 'BA'}, | |
| {name: 'Botswana', value: 'BW'}, | |
| {name: 'Bouvet Island', value: 'BV'}, | |
| {name: 'Brazil', value: 'BR'}, | |
| {name: 'British Indian Ocean Territory', value: 'IO'}, | |
| {name: 'Brunei Darussalam', value: 'BN'}, | |
| {name: 'Bulgaria', value: 'BG'}, | |
| {name: 'Burkina Faso', value: 'BF'}, | |
| {name: 'Burundi', value: 'BI'}, | |
| {name: 'Cambodia', value: 'KH'}, | |
| {name: 'Cameroon', value: 'CM'}, | |
| {name: 'Canada', value: 'CA'}, | |
| {name: 'Cape Verde', value: 'CV'}, | |
| {name: 'Cayman Islands', value: 'KY'}, | |
| {name: 'Central African Republic', value: 'CF'}, | |
| {name: 'Chad', value: 'TD'}, | |
| {name: 'Chile', value: 'CL'}, | |
| {name: 'China', value: 'CN'}, | |
| {name: 'Christmas Island', value: 'CX'}, | |
| {name: 'Cocos (Keeling) Islands', value: 'CC'}, | |
| {name: 'Colombia', value: 'CO'}, | |
| {name: 'Comoros', value: 'KM'}, | |
| {name: 'Congo', value: 'CG'}, | |
| {name: 'Congo, The Democratic Republic of the', value: 'CD'}, | |
| {name: 'Cook Islands', value: 'CK'}, | |
| {name: 'Costa Rica', value: 'CR'}, | |
| {name: 'Cote D\'Ivoire', value: 'CI'}, | |
| {name: 'Croatia', value: 'HR'}, | |
| {name: 'Cuba', value: 'CU'}, | |
| {name: 'Cyprus', value: 'CY'}, | |
| {name: 'Czech Republic', value: 'CZ'}, | |
| {name: 'Denmark', value: 'DK'}, | |
| {name: 'Djibouti', value: 'DJ'}, | |
| {name: 'Dominica', value: 'DM'}, | |
| {name: 'Dominican Republic', value: 'DO'}, | |
| {name: 'Ecuador', value: 'EC'}, | |
| {name: 'Egypt', value: 'EG'}, | |
| {name: 'El Salvador', value: 'SV'}, | |
| {name: 'Equatorial Guinea', value: 'GQ'}, | |
| {name: 'Eritrea', value: 'ER'}, | |
| {name: 'Estonia', value: 'EE'}, | |
| {name: 'Ethiopia', value: 'ET'}, | |
| {name: 'Falkland Islands (Malvinas)', value: 'FK'}, | |
| {name: 'Faroe Islands', value: 'FO'}, | |
| {name: 'Fiji', value: 'FJ'}, | |
| {name: 'Finland', value: 'FI'}, | |
| {name: 'France', value: 'FR'}, | |
| {name: 'French Guiana', value: 'GF'}, | |
| {name: 'French Polynesia', value: 'PF'}, | |
| {name: 'French Southern Territories', value: 'TF'}, | |
| {name: 'Gabon', value: 'GA'}, | |
| {name: 'Gambia', value: 'GM'}, | |
| {name: 'Georgia', value: 'GE'}, | |
| {name: 'Germany', value: 'DE'}, | |
| {name: 'Ghana', value: 'GH'}, | |
| {name: 'Gibraltar', value: 'GI'}, | |
| {name: 'Greece', value: 'GR'}, | |
| {name: 'Greenland', value: 'GL'}, | |
| {name: 'Grenada', value: 'GD'}, | |
| {name: 'Guadeloupe', value: 'GP'}, | |
| {name: 'Guam', value: 'GU'}, | |
| {name: 'Guatemala', value: 'GT'}, | |
| {name: 'Guernsey', value: 'GG'}, | |
| {name: 'Guinea', value: 'GN'}, | |
| {name: 'Guinea-Bissau', value: 'GW'}, | |
| {name: 'Guyana', value: 'GY'}, | |
| {name: 'Haiti', value: 'HT'}, | |
| {name: 'Heard Island and Mcdonald Islands', value: 'HM'}, | |
| {name: 'Holy See (Vatican City State)', value: 'VA'}, | |
| {name: 'Honduras', value: 'HN'}, | |
| {name: 'Hong Kong', value: 'HK'}, | |
| {name: 'Hungary', value: 'HU'}, | |
| {name: 'Iceland', value: 'IS'}, | |
| {name: 'India', value: 'IN'}, | |
| {name: 'Indonesia', value: 'ID'}, | |
| {name: 'Iran, Islamic Republic Of', value: 'IR'}, | |
| {name: 'Iraq', value: 'IQ'}, | |
| {name: 'Ireland', value: 'IE'}, | |
| {name: 'Isle of Man', value: 'IM'}, | |
| {name: 'Israel', value: 'IL'}, | |
| {name: 'Italy', value: 'IT'}, | |
| {name: 'Jamaica', value: 'JM'}, | |
| {name: 'Japan', value: 'JP'}, | |
| {name: 'Jersey', value: 'JE'}, | |
| {name: 'Jordan', value: 'JO'}, | |
| {name: 'Kazakhstan', value: 'KZ'}, | |
| {name: 'Kenya', value: 'KE'}, | |
| {name: 'Kiribati', value: 'KI'}, | |
| {name: 'Korea, Democratic People\'S Republic of', value: 'KP'}, | |
| {name: 'Korea, Republic of', value: 'KR'}, | |
| {name: 'Kuwait', value: 'KW'}, | |
| {name: 'Kyrgyzstan', value: 'KG'}, | |
| {name: 'Lao People\'S Democratic Republic', value: 'LA'}, | |
| {name: 'Latvia', value: 'LV'}, | |
| {name: 'Lebanon', value: 'LB'}, | |
| {name: 'Lesotho', value: 'LS'}, | |
| {name: 'Liberia', value: 'LR'}, | |
| {name: 'Libyan Arab Jamahiriya', value: 'LY'}, | |
| {name: 'Liechtenstein', value: 'LI'}, | |
| {name: 'Lithuania', value: 'LT'}, | |
| {name: 'Luxembourg', value: 'LU'}, | |
| {name: 'Macao', value: 'MO'}, | |
| {name: 'Macedonia, The Former Yugoslav Republic of', value: 'MK'}, | |
| {name: 'Madagascar', value: 'MG'}, | |
| {name: 'Malawi', value: 'MW'}, | |
| {name: 'Malaysia', value: 'MY'}, | |
| {name: 'Maldives', value: 'MV'}, | |
| {name: 'Mali', value: 'ML'}, | |
| {name: 'Malta', value: 'MT'}, | |
| {name: 'Marshall Islands', value: 'MH'}, | |
| {name: 'Martinique', value: 'MQ'}, | |
| {name: 'Mauritania', value: 'MR'}, | |
| {name: 'Mauritius', value: 'MU'}, | |
| {name: 'Mayotte', value: 'YT'}, | |
| {name: 'Mexico', value: 'MX'}, | |
| {name: 'Micronesia, Federated States of', value: 'FM'}, | |
| {name: 'Moldova, Republic of', value: 'MD'}, | |
| {name: 'Monaco', value: 'MC'}, | |
| {name: 'Mongolia', value: 'MN'}, | |
| {name: 'Montserrat', value: 'MS'}, | |
| {name: 'Morocco', value: 'MA'}, | |
| {name: 'Mozambique', value: 'MZ'}, | |
| {name: 'Myanmar', value: 'MM'}, | |
| {name: 'Namibia', value: 'NA'}, | |
| {name: 'Nauru', value: 'NR'}, | |
| {name: 'Nepal', value: 'NP'}, | |
| {name: 'Netherlands', value: 'NL'}, | |
| {name: 'Netherlands Antilles', value: 'AN'}, | |
| {name: 'New Caledonia', value: 'NC'}, | |
| {name: 'New Zealand', value: 'NZ'}, | |
| {name: 'Nicaragua', value: 'NI'}, | |
| {name: 'Niger', value: 'NE'}, | |
| {name: 'Nigeria', value: 'NG'}, | |
| {name: 'Niue', value: 'NU'}, | |
| {name: 'Norfolk Island', value: 'NF'}, | |
| {name: 'Northern Mariana Islands', value: 'MP'}, | |
| {name: 'Norway', value: 'NO'}, | |
| {name: 'Oman', value: 'OM'}, | |
| {name: 'Pakistan', value: 'PK'}, | |
| {name: 'Palau', value: 'PW'}, | |
| {name: 'Palestinian Territory, Occupied', value: 'PS'}, | |
| {name: 'Panama', value: 'PA'}, | |
| {name: 'Papua New Guinea', value: 'PG'}, | |
| {name: 'Paraguay', value: 'PY'}, | |
| {name: 'Peru', value: 'PE'}, | |
| {name: 'Philippines', value: 'PH'}, | |
| {name: 'Pitcairn', value: 'PN'}, | |
| {name: 'Poland', value: 'PL'}, | |
| {name: 'Portugal', value: 'PT'}, | |
| {name: 'Puerto Rico', value: 'PR'}, | |
| {name: 'Qatar', value: 'QA'}, | |
| {name: 'Reunion', value: 'RE'}, | |
| {name: 'Romania', value: 'RO'}, | |
| {name: 'Russian Federation', value: 'RU'}, | |
| {name: 'RWANDA', value: 'RW'}, | |
| {name: 'Saint Helena', value: 'SH'}, | |
| {name: 'Saint Kitts and Nevis', value: 'KN'}, | |
| {name: 'Saint Lucia', value: 'LC'}, | |
| {name: 'Saint Pierre and Miquelon', value: 'PM'}, | |
| {name: 'Saint Vincent and the Grenadines', value: 'VC'}, | |
| {name: 'Samoa', value: 'WS'}, | |
| {name: 'San Marino', value: 'SM'}, | |
| {name: 'Sao Tome and Principe', value: 'ST'}, | |
| {name: 'Saudi Arabia', value: 'SA'}, | |
| {name: 'Senegal', value: 'SN'}, | |
| {name: 'Serbia and Montenegro', value: 'CS'}, | |
| {name: 'Seychelles', value: 'SC'}, | |
| {name: 'Sierra Leone', value: 'SL'}, | |
| {name: 'Singapore', value: 'SG'}, | |
| {name: 'Slovakia', value: 'SK'}, | |
| {name: 'Slovenia', value: 'SI'}, | |
| {name: 'Solomon Islands', value: 'SB'}, | |
| {name: 'Somalia', value: 'SO'}, | |
| {name: 'South Africa', value: 'ZA'}, | |
| {name: 'South Georgia and the South Sandwich Islands', value: 'GS'}, | |
| {name: 'Spain', value: 'ES'}, | |
| {name: 'Sri Lanka', value: 'LK'}, | |
| {name: 'Sudan', value: 'SD'}, | |
| {name: 'Suriname', value: 'SR'}, | |
| {name: 'Svalbard and Jan Mayen', value: 'SJ'}, | |
| {name: 'Swaziland', value: 'SZ'}, | |
| {name: 'Sweden', value: 'SE'}, | |
| {name: 'Switzerland', value: 'CH'}, | |
| {name: 'Syrian Arab Republic', value: 'SY'}, | |
| {name: 'Taiwan, Province of China', value: 'TW'}, | |
| {name: 'Tajikistan', value: 'TJ'}, | |
| {name: 'Tanzania, United Republic of', value: 'TZ'}, | |
| {name: 'Thailand', value: 'TH'}, | |
| {name: 'Timor-Leste', value: 'TL'}, | |
| {name: 'Togo', value: 'TG'}, | |
| {name: 'Tokelau', value: 'TK'}, | |
| {name: 'Tonga', value: 'TO'}, | |
| {name: 'Trinidad and Tobago', value: 'TT'}, | |
| {name: 'Tunisia', value: 'TN'}, | |
| {name: 'Turkey', value: 'TR'}, | |
| {name: 'Turkmenistan', value: 'TM'}, | |
| {name: 'Turks and Caicos Islands', value: 'TC'}, | |
| {name: 'Tuvalu', value: 'TV'}, | |
| {name: 'Uganda', value: 'UG'}, | |
| {name: 'Ukraine', value: 'UA'}, | |
| {name: 'United Arab Emirates', value: 'AE'}, | |
| {name: 'United Kingdom', value: 'UK'}, | |
| {name: 'United States', value: 'US'}, | |
| {name: 'United States Minor Outlying Islands', value: 'UM'}, | |
| {name: 'Uruguay', value: 'UY'}, | |
| {name: 'Uzbekistan', value: 'UZ'}, | |
| {name: 'Vanuatu', value: 'VU'}, | |
| {name: 'Venezuela', value: 'VE'}, | |
| {name: 'Viet Nam', value: 'VN'}, | |
| {name: 'Virgin Islands, British', value: 'VG'}, | |
| {name: 'Virgin Islands, U.S.', value: 'VI'}, | |
| {name: 'Wallis and Futuna', value: 'WF'}, | |
| {name: 'Western Sahara', value: 'EH'}, | |
| {name: 'Yemen', value: 'YE'}, | |
| {name: 'Zambia', value: 'ZM'}, | |
| {name: 'Zimbabwe', value: 'ZW'} | |
| ]; | |
| /** | |
| * | |
| * @param {*} str1 | |
| * @param {*} str2 | |
| * @returns | |
| */ | |
| export const compareStr = (str1, str2) => { | |
| return String(str1).trim().toLowerCase() === String(str2).trim().toLowerCase() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment