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 validationRules = { | |
notificationsClientId: [ | |
[ | |
dep("getsNotifications", R.equals(true), isType("String")), | |
"If getsNotifications is true, notificationsClientId is required as a 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
const optionalTypeRule = type => [ | |
unlessNil(isType(type)), | |
(val, field) => `if ${field} is set, it must be a ${type}` | |
]; | |
const validationRules = { | |
appDescription: [optionalTypeRule('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
const normalize = (spec, input) => | |
Object.keys(spec).reduce( | |
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc), | |
{} | |
); |
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 normalize = (spec, input) => | |
Object.keys(spec).reduce( | |
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc), | |
{} | |
); |
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 typeMessage = (type, field) => `${field} has to be a ${type}`; | |
const typeRule = type => [ | |
isType(type), | |
(val, field) => typeMessage(type, field) | |
]; | |
const isString = typeRule("String"); | |
const isNumber = typeRule("Number") | |
const rules = { | |
version: [isNumber], |
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 isType = R.curry((type, value) => R.type(value) === type); | |
const rules = { | |
version: [[isType('Number')], 'Version must be a number'], | |
build: [[isType('Number')], 'Build must be a number'], | |
appName: [[isType('String'), 'appName must be a 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
const concatMany = unapply(unnest) | |
concatMany([1,2,3], [4,5,6], [7,8,9]) | |
// -> [1, 2, 3, 4, 5, 6, 7, 8, 9] |
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
// updateKeys :: (String -> String) -> Object -> Object | |
const updateKeys = f => | |
R.compose(R.fromPairs, R.map(R.over(R.lensIndex(0), f)), R.toPairs); | |
// updateKeysWithMap :: Object -> Object -> Object | |
const updateKeysWithMap = map => updateKeys(k => map[k] || k); | |
// example: | |
updateKeysWithMap({ oldKey: "newKey" })({ oldKey: 2 }); // -> { newKey: 2 } |
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
sendNotification = function(data) { | |
var headers = { | |
"Content-Type": "application/json; charset=utf-8", | |
Authorization: "Basic NzkwODdjM2YtODMxNi00ODMyLTgwMWEtZTVkOTcyMzg4ZWRi" | |
}; | |
var options = { | |
host: "onesignal.com", | |
port: 443, | |
path: "/api/v1/notifications", |
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
// This goes after https://gist.github.com/DrBoolean/3f5ac08a5bf1c4673757 | |
const setNameActionCretor = name => ({ type: "SET_NAME", payload: { name } }); | |
const setName = localStorage | |
.chain(ls => safeProp("user", ls)) | |
.chain(u => safeProp("name", u)) | |
.map(n => n.toUpperCase()) | |
.chain(printLn) | |
.map(m => m.toLowerCase()) |
NewerOlder