Skip to content

Instantly share code, notes, and snippets.

@Evanion
Evanion / exclude-null.ts
Created April 25, 2024 09:51
Excludes `null`, in an object, and replaces it with `undefined` in a way that TypeScript understands it.
type ExcludeNull<T> = {
[K in keyof T]-?: null extends T[K] ? Exclude<T[K], null> : T[K];
};
/**
* Filters out any `null` values and makes them `undefined`.
* It also filters out the type of the object so the TS parser understands it.
* @param obj Object containing null types
* @returns
*/
@Evanion
Evanion / README.md
Last active April 24, 2024 15:18
Rex - Redux like state manager based on rxjs and immer

@evanion/rex

Rex is a Redux-like state management library that is reactive and immutable out of the box. It's just a tiny wrapper lib on top of RxJS and immer.

Creating a store

To create a new store you call the createStore function with a reducer and its initial state.

There is no need to supply a default case in your reducer, and the reducer shouldn't return anything.

@Evanion
Evanion / fetch.hook.ts
Created November 7, 2022 12:23
useFetch hook for react.
import { DependencyList, useEffect, useReducer, useState } from "react";
interface State<T> {
data: T | null;
error: unknown | null;
loading: boolean;
loaded: boolean;
}
type Action<T> =
@Evanion
Evanion / feature.context.ts
Created May 31, 2022 22:01
WIP: A React feature toggle system.
import { createContext } from 'react';
import { ActionProps, FeatureConfig, FeatureState } from './feature.types';
const dispatch = <Feature extends string | number>(
value: ActionProps<Feature>
) => {};
export const createFeatureContext = <Feature extends string | number>(
features: FeatureState<Feature>,
config: FeatureConfig
@Evanion
Evanion / example.ts
Created August 30, 2021 11:07
Luhn mod N algorithm
const rawToken = "v83dtres";
const checksum = Luhn.generate(rawToken);
const testToken = `${rawToken}${checksum}`;
const isValid = Luhn.validate(testToken);
@Evanion
Evanion / README.md
Last active September 10, 2019 06:47
React-native form hook
@Evanion
Evanion / Intent.ts
Created August 19, 2019 12:50
StringEnum for Typescript
import StringEnum from './StringEnum';
export const Intent = StringEnum(['success', 'warning', 'error', 'info']);
export type Intent = keyof typeof Intent;
/**
* This allows you to declare an enum that can be used a both a type and value, while still allowing the user to use plain strings.
* The option to use plain strings is good when you are developing a library that might be used in a none TS project.
* example
````
const Message = (intent:Intent) => (message: string) => {
@Evanion
Evanion / grid-push-pull.less
Last active October 26, 2021 08:57
Responsive push/pull for uikit
/* Small */
@media (max-width: @breakpoint-small-max) {
[class*='uk-push-small-'],
[class*='uk-pull-small-'] { position: relative; }
/*
* Push
*/
@Evanion
Evanion / AuthService.js
Created November 6, 2014 08:45
Integrate Facebook in Iionic
(function() {
'use strict';
var module = angular.module('api.auth', [
'angular-data.DS',
'ngCordova'
]);
module.constant('AUTH_EVENTS', {
loginSuccess: 'auth-login-success',
@Evanion
Evanion / datepicker.html
Created October 29, 2014 14:30
uk-datepicker in angular
<div class="uk-form-icon">
<i class="uk-icon-calendar"></i>
<input type="text" class="uk-width-1-1" ng-model="item.classified.meta.applyBy" data-uk-datepicker="{format:'DD.MM.YYYY'}" placeholder="{{ 'CLASSIFIED_CREATE_JOB_META_APPLYBY_DATE' | translate }}" />
</div>