Last active
February 27, 2024 22:52
-
-
Save LuisPaGarcia/fb10d9d837295ee1e1c66271cfb7bc1f to your computer and use it in GitHub Desktop.
isValidDeepLink
This file contains 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
function isValidDeepLink(url) { | |
const regex = /^[a-zA-Z0-9_-]+:\/\/([a-zA-Z0-9\/]+)(\?([a-zA-Z0-9=&]+))?$/; | |
return regex.test(url); | |
} | |
function isValidDeepLink(url) { | |
const regex = /^[a-zA-Z0-9_-]+:\/\/([a-zA-Z0-9\/$(){}_\-.\[\]]+)(\?([a-zA-Z0-9=&$(){}_\-.\[\]]+))?$/; | |
return regex.test(url); | |
} | |
function validarString(str) { | |
const regex = /^\$\{[A-Za-z0-9_]+\.[a-z0-9_]+\}$/; | |
return regex.test(str); | |
} | |
function validarString(str) { | |
const regex = /^\$\{.*\}$/; | |
return regex.test(str); | |
} | |
function validateString(str) { | |
const regex = /^appname:\/\//; | |
return regex.test(str); | |
} | |
// Test examples with variable placeholders | |
console.log(isValidDeepLink("myapp://${VARIABLE_name.subvariable}")); // true | |
console.log(isValidDeepLink("myapp://path/${VARIABLE_name.subvariable}")); // true | |
console.log(isValidDeepLink("myapp://path/${VARIABLE_name.subvariable}?${Variable_name.subvariable2}=${variable_name.subvariable3}")); // true | |
// Test examples with different app names | |
console.log(isValidDeepLink("myapp://path")); // true | |
console.log(isValidDeepLink("anotherApp://path?with=params")); // true | |
console.log(isValidDeepLink("app-name://path?with=params&multiple=params&and=more")); // true | |
console.log(isValidDeepLink("123app://path/can/be/long")); // true | |
console.log(isValidDeepLink("app123://path/can/be/long?with=params")); // true | |
console.log(isValidDeepLink("my_app://path/can/be/long?with=params&multiple=params&and=more")); // true | |
// ================================================ | |
const areEqual = (prevProps, nextProps) => { | |
// Obtén todas las claves de ambos objetos | |
const prevKeys = Object.keys(prevProps); | |
const nextKeys = Object.keys(nextProps); | |
// Si tienen diferente cantidad de claves, son diferentes | |
if (prevKeys.length !== nextKeys.length) { | |
return false; | |
} | |
// Comprueba si cada valor de las propiedades en prevProps es igual al de nextProps | |
for (const key of prevKeys) { | |
if (prevProps[key] !== nextProps[key]) { | |
return false; | |
} | |
} | |
// Si todas las propiedades son iguales, retorna true | |
return true; | |
}; | |
// Uso de React.memo con la función de comparación | |
const MyComponent = React.memo(function MyComponent(props) { | |
// ... lógica del componente | |
}, areEqual); | |
function sortObjectProperties(obj) { | |
// Check if the argument is an object or an array | |
if (typeof obj !== 'object' || obj === null) { | |
return obj; | |
} | |
// If the object is an Array, iterate over its elements | |
if (Array.isArray(obj)) { | |
return obj.map(element => { | |
// Apply sorting to each element if it's an object | |
if (typeof element === 'object' && element !== null) { | |
return sortObjectProperties(element); | |
} | |
return element; | |
}); | |
} | |
// Create a new sorted object for non-array objects | |
const sortedObj = {}; | |
// Sort the keys of the object | |
Object.keys(obj).sort().forEach(key => { | |
// If the value is an object or an array, recursively sort it | |
if (typeof obj[key] === 'object' && obj[key] !== null) { | |
sortedObj[key] = sortObjectProperties(obj[key]); | |
} else { | |
sortedObj[key] = obj[key]; | |
} | |
}); | |
return sortedObj; | |
} | |
// Example usage | |
const myObject = { | |
c: 3, | |
a: [{ d: 4, c: 3 }, { a: 1, b: 2 }], | |
b: "Hello" | |
}; | |
console.log(sortObjectProperties(myObject)); | |
function validarUrl(url) { | |
const regex = /^https:\/\/app\.atlassian\.net\/browse\/DTPZN-\d{4}$/; | |
return regex.test(url); | |
} | |
// Ejemplo de uso | |
const urlValida = "https://app.atlassian.net/browse/DTPZN-1234"; // Cambia esto por la URL que quieras probar | |
const esValida = validarUrl(urlValida); | |
console.log(esValida); // Imprime true si la URL es válida, false si no lo es |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment