Skip to content

Instantly share code, notes, and snippets.

View stwilz's full-sized avatar

Steve Wilcox stwilz

  • Colossal Digital Pty Ltd
  • Sydney, Australia
  • X @stwilz
View GitHub Profile
@stwilz
stwilz / curryMapGetters.js
Created July 25, 2019 04:27
A curry utility for passing additional arguments to `mapGetters`.
import { mapGetters } from "vuex";
const curryMapGetters = args => (namespace, getters) =>
Object.entries(mapGetters(namespace, getters)).reduce(
(acc, [getter, fn]) => ({
...acc,
[getter]: state =>
fn.call(state)(...(Array.isArray(args) ? args : [args]))
}),
{}
@stwilz
stwilz / SetStateIn.js
Created February 6, 2019 01:15
Set nested properties in React without destructuring
import set from 'lodash/set';
import React from 'react';
export default class extends React.Component {
setStateIn = (path, value, fn) =>
this.setState(state => set(state, path, value), fn);
render = () => <div />;
}
const dateStringtoObj = string => {
const [date, time, timezone] = string.split(/T|\+/g);
const [hours, minutes, seconds] = time.split(/:/g);
return {
date,
time,
timezone,
hours: parseInt(hours, 10),
minutes: parseInt(minutes, 10),
seconds: parseInt(seconds, 10),
const createUrl = (path, params = {}) =>
`${Object.keys(params).reduce(
(url, key) => url.replace(`:${key}`, params[key]),
path,
)}`;
export default class JSUtils {
regExpWithEscape (string) {
return new RegExp(string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'))
}
}
class CordovaMock {
constructor() {
this.platformId = 'ios';
this.platformVersion = '4.3.1';
this.plugins = {
};
this.version = '4.3.1';
}
require(id){}