mirror of
https://github.com/betagouv/mon-entreprise
synced 2025-02-09 01:45:03 +00:00
Le but est d'arriver au résultat en un minimum de question. Le moteur pose les questions les plus importantes (qui départagent le plus de status) en premier. Si la question peut aboutir à une absence de status concordant, elle n'est pas posée. Le moteur permet aussi de commencer par n'importe quelle question. Dans le cadre du référencement direct, cela signifie que l'on peut arriver sur la page liability par exemple via une recherche / lien et continuer à partir de ce point d'entrée.
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
/* @flow */
|
|
import { map } from 'ramda'
|
|
|
|
export let capitalise0 = (name: string) => name[0].toUpperCase() + name.slice(1)
|
|
|
|
export let getUrl = () => window.location.href.toString()
|
|
|
|
export let parseDataAttributes = (value: any) =>
|
|
value === 'undefined'
|
|
? undefined
|
|
: value === null
|
|
? null
|
|
: !isNaN(value)
|
|
? +value
|
|
: /* value is a normal string */
|
|
value
|
|
|
|
export let getIframeOption = (optionName: string) => {
|
|
let url = getUrl(),
|
|
hasOption = url.includes(optionName + '=')
|
|
return parseDataAttributes(
|
|
hasOption && url.split(optionName + '=')[1].split('&')[0]
|
|
)
|
|
}
|
|
|
|
// By luck this works as expected for both null and undefined, * but with different branches failing :O *
|
|
export let isFloat = (n: number) => Number(n) === n && n % 1 !== 0
|
|
|
|
export function debounce<ArgType: any>(
|
|
timeout: number,
|
|
fn: ArgType => void
|
|
): ArgType => void {
|
|
let timeoutId
|
|
return (...args) => {
|
|
clearTimeout(timeoutId)
|
|
timeoutId = setTimeout(() => fn(...args), timeout)
|
|
}
|
|
}
|
|
|
|
export function isIE() {
|
|
return (
|
|
navigator.appName == 'Microsoft Internet Explorer' ||
|
|
(navigator.appName == 'Netscape' &&
|
|
new RegExp('Trident/.*rv:([0-9]{1,}[.0-9]{0,})').exec(
|
|
navigator.userAgent
|
|
) != null)
|
|
)
|
|
}
|
|
|
|
export const mapDispatchWithRouter = (actionCreators: Object) => (
|
|
dispatch: (...any) => void,
|
|
ownProps: Object
|
|
) =>
|
|
map(
|
|
actionCreator => (...args) =>
|
|
dispatch(actionCreator(...args, ownProps.router)),
|
|
actionCreators
|
|
)
|