View rules4.js
const validationRules = { | |
notificationsClientId: [ | |
[ | |
dep("getsNotifications", R.equals(true), isType("String")), | |
"If getsNotifications is true, notificationsClientId is required as a string" | |
] | |
] | |
} |
View rules3.js
const optionalTypeRule = type => [ | |
unlessNil(isType(type)), | |
(val, field) => `if ${field} is set, it must be a ${type}` | |
]; | |
const validationRules = { | |
appDescription: [optionalTypeRule('String')] | |
} |
View spec-normalize.js
const normalize = (spec, input) => | |
Object.keys(spec).reduce( | |
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc), | |
{} | |
); |
View spec-normalize
const normalize = (spec, input) => | |
Object.keys(spec).reduce( | |
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc), | |
{} | |
); |
View rules2.js
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], |
View rules1.js
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']] | |
} |
View ramda-concatMany.js
const concatMany = unapply(unnest) | |
concatMany([1,2,3], [4,5,6], [7,8,9]) | |
// -> [1, 2, 3, 4, 5, 6, 7, 8, 9] |
View ramda-updateKeys.js
// 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 } |
View oneSignal.js
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", |
View redux-free.js
// 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