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
import * as fs from 'fs'; | |
import * as os from 'os'; | |
import * as path from 'path'; | |
interface NetrcEntry { | |
machine: string; | |
login: string; | |
password: string; | |
account?: string; | |
} |
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
$cat ~/.netrc | |
machine api.usecloudstate.io | |
login me@example.com | |
password c4cd94da15ea0544802c2cfd5ec4ead324327111 | |
machine github.com | |
login me@example.com | |
password c2224da15ea0544802c2cfd5ec4ead324327430 |
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
const successNoContent = [ | |
(data: string) => data.length === 0, | |
() => 204, | |
]; | |
const successWithContent = [ | |
(data: string) => data.length > 0, | |
() => 200 | |
]; |
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
import { encaseP, node, encase, map, chain } from "fluture"; | |
const readFileF = filePath => node(done => fs.readFile(filePath, "utf8", done)); | |
const fetchF = url => encaseP(url => fetch(url)); | |
const jsonParseF = encase(jsonString => JSON.parse(jsonString)); | |
const getPackageDownloads = (npmPackageName, onSuccess, onFailure) => { | |
readFileF("package.json") |
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
const storeLanguageCode = tryCatch({ | |
tryer: (languageCode) => { | |
window.localStorage.setItem("LANG_CODE", languageCode); | |
return true; | |
}, | |
catcher: (languageCode, errorMessage) => { | |
logger.log(`${errorMessage} <-- happened while storing ${languageCode}`); | |
return false; | |
} | |
}); |
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
export function tryCatch<Props, Result>({ | |
tryer, | |
catcher | |
}: { | |
tryer: (props: Props) => Result; | |
catcher: (props: Props, message: string) => Result; | |
}) { | |
return (props: Props) => { | |
try { | |
return tryer(props); |
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
export function tryCatch({ | |
tryer, | |
catcher | |
}) { | |
return (props) => { | |
try { | |
return tryer(props); | |
} catch (e) { | |
return catcher(props, e.message); | |
} |
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 setUserLanguageCode(selectedLanguage) { | |
const languageCode = getLanguageCode(selectedLanguage); | |
let storedSuccessfully; | |
try { | |
window.localStorage.setItem("LANG_CODE", languageCode); | |
storedSuccessfully = true; | |
} catch (e) { | |
storedSuccessfully = false; |
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
export const conditionally = <Props, Result>(options: { | |
if: (props: Props) => any; | |
then: (props: Props) => Result | Result; | |
else: (props: Props) => Result | Result; | |
}) => (props: Props) => { | |
return options.if(props) ? options.then(props) : options.else(props); | |
}; |
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
export const conditionally = (config) => (props) => { | |
return config.if(props) ? | |
config.then(props) : config.else(props); | |
}; |
NewerOlder