Skip to content

Commit

Permalink
feat: cacheItTTL & initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed Nov 9, 2020
1 parent c30d210 commit 4d764d0
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 86 deletions.
1 change: 1 addition & 0 deletions src/cacheIt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@ export function cacheIt(obj: any, options?: CacheItOptions): any {

}


export default cacheIt;
13 changes: 13 additions & 0 deletions src/cacheItTTL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import cacheIt, { CachedClass, CachedFunction, CachedObject, CacheItOptions } from './cacheIt';
import { TTLCacheProvider } from './cacheProvider';
import { Class, GeneralFunction } from './types';

export function cacheItTTL<T extends GeneralFunction>(obj: T, options?: CacheItOptions): CachedFunction<T>
export function cacheItTTL<T>(obj: Class<T>, options?: CacheItOptions): CachedClass<T>
export function cacheItTTL<T extends object>(obj: T, options?: CacheItOptions): CachedObject<T>
export function cacheItTTL(obj: any, options?: CacheItOptions): any
export function cacheItTTL(obj: any, options: any = {}) {
const opt: CacheItOptions = Object.assign({}, { provider: TTLCacheProvider }, options);
return cacheIt(obj, opt);
}

2 changes: 1 addition & 1 deletion src/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* // => true
* ```
*/
function eq(value: any, other: any): boolean {
export function eq(value: any, other: any): boolean {
return value === other || (value !== value && other !== other);
}

Expand Down
162 changes: 82 additions & 80 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { at } from './at';
import { attempt } from './attempt';
import { bind } from './bind';
import { cacheIt } from './cacheIt';
import { cacheItTTL } from './cacheItTTL';
import { cacheProvider } from './cacheProvider';
import { capitalize } from './capitalize';
import { ceil } from './ceil';
Expand All @@ -17,22 +18,22 @@ import { clone } from './clone';
import { cloneDeep } from './cloneDeep';
import { concat } from './concat';
import { concurrency } from './concurrency';
import cond from './cond';
import conforms from './conforms';
import conformsTo from './conformsTo';
import constant from './constant';
import countBy from './countBy';
import curry from './curry';
import { cond } from './cond';
import { conforms } from './conforms';
import { conformsTo } from './conformsTo';
import { constant } from './constant';
import { countBy } from './countBy';
import { curry } from './curry';
import { debounce } from './debounce';
import defaultTo from './defaultTo';
import { defaultTo } from './defaultTo';
import { delay } from './delay';
import differenceBy from './differenceBy';
import divide from './divide';
import { differenceBy } from './differenceBy';
import { divide } from './divide';
import { each } from './each';
import eq from './eq';
import escapeRegExp from './escapeRegExp';
import { eq } from './eq';
import { escapeRegExp } from './escapeRegExp';
import { every } from './every';
import everyValue from './everyValue';
import { everyValue } from './everyValue';
import { fallback } from './fallback';
import { filter } from './filter';
import { filterObject } from './filterObject';
Expand All @@ -42,31 +43,32 @@ import { flatMap } from './flatMap';
import { flatMapDeep } from './flatMapDeep';
import { flatten } from './flatten';
import { flattenDeep } from './flattenDeep';
import flip from './flip';
import { flip } from './flip';
import { forEach } from './forEach';
import forOwn from './forOwn';
import forOwnRight from './forOwnRight';
import fromEntries from './fromEntries';
import functions from './functions';
import { forOwn } from './forOwn';
import { forOwnRight } from './forOwnRight';
import { fromEntries } from './fromEntries';
import { functions } from './functions';
import { get } from './get';
import groupBy from './groupBy';
import { groupBy } from './groupBy';
import { has } from './has';
import { head } from './head';
import includes from './includes';
import intersection from './intersection';
import intersectionBy from './intersectionBy';
import intersectionWith from './intersectionWith';
import invert from './invert';
import invertBy from './invertBy';
import invoke from './invoke';
import invokeMap from './invokeMap';
import { includes } from './includes';
import initial from './initial';
import { intersection } from './intersection';
import { intersectionBy } from './intersectionBy';
import { intersectionWith } from './intersectionWith';
import { invert } from './invert';
import { invertBy } from './invertBy';
import { invoke } from './invoke';
import { invokeMap } from './invokeMap';
import { isArguments } from './isArguments';
import { isArray } from './isArray';
import { isArrayLike } from './isArrayLike';
import { isDate } from './isDate';
import { isEmpty } from './isEmpty';
import { isEqual } from './isEqual';
import isEqualWith from './isEqualWith';
import { isEqualWith } from './isEqualWith';
import { isError } from './isError';
import { isFunction } from './isFunction';
import { isInstance } from './isInstance';
Expand All @@ -77,92 +79,92 @@ import { isObject } from './isObject';
import { isString } from './isString';
import { isSubClass } from './isSubClass';
import { join } from './join';
import keys from './keys';
import { keys } from './keys';
import { last } from './last';
import { lastIndexOf } from './lastIndexOf';
import { logic } from './logic';
import { lowerCase } from './lowerCase';
import { lt } from './lt';
import { map } from './map';
import mapKeys from './mapKeys';
import mapValues from './mapValues';
import matchesProperty from './matchesProperty';
import max from './max';
import maxBy from './maxBy';
import mean from './mean';
import meanBy from './meanBy';
import { mapKeys } from './mapKeys';
import { mapValues } from './mapValues';
import { matchesProperty } from './matchesProperty';
import { max } from './max';
import { maxBy } from './maxBy';
import { mean } from './mean';
import { meanBy } from './meanBy';
import { memoize } from './memoize';
import { merge } from './merge';
import mergeWith from './mergeWith';
import method from './method';
import methodOf from './methodOf';
import min from './min';
import minBy from './minBy';
import over from './over';
import overArgs from './overArgs';
import overEvery from './overEvery';
import overSome from './overSome';
import pad from './pad';
import padEnd from './padEnd';
import padStart from './padStart';
import { mergeWith } from './mergeWith';
import { method } from './method';
import { methodOf } from './methodOf';
import { min } from './min';
import { minBy } from './minBy';
import { over } from './over';
import { overArgs } from './overArgs';
import { overEvery } from './overEvery';
import { overSome } from './overSome';
import { pad } from './pad';
import { padEnd } from './padEnd';
import { padStart } from './padStart';
import { partial } from './partial';
import { pick } from './pick';
import { pickBy } from './pickBy';
import pull from './pull';
import pullAll from './pullAll';
import pullAllWith from './pullAllWith';
import pullAt from './pullAt';
import { pull } from './pull';
import { pullAll } from './pullAll';
import { pullAllWith } from './pullAllWith';
import { pullAt } from './pullAt';
import { random } from './random';
import { range } from './range';
import { reduce } from './reduce';
import reject from './reject';
import remove from './remove';
import { reject } from './reject';
import { remove } from './remove';
import { repeat } from './repeat';
import replace from './replace';
import retry from './retry';
import { replace } from './replace';
import { retry } from './retry';
import { series } from './series';
import { set } from './set';
import { size } from './size';
import { sleep } from './sleep';
import slice from './slice';
import { slice } from './slice';
import { some } from './some';
import someValues from './someValue';
import sortedIndex from './sortedIndex';
import sortedIndexBy from './sortedIndexBy';
import sortedIndexOf from './sortedIndexOf';
import sortedLastIndex from './sortedLastIndex';
import sortedLastIndexBy from './sortedLastIndexBy';
import sortedLastIndexOf from './sortedLastIndexOf';
import sortedUniq from './sortedUniq';
import sortedUniqBy from './sortedUniqBy';
import { someValues } from './someValue';
import { sortedIndex } from './sortedIndex';
import { sortedIndexBy } from './sortedIndexBy';
import { sortedIndexOf } from './sortedIndexOf';
import { sortedLastIndex } from './sortedLastIndex';
import { sortedLastIndexBy } from './sortedLastIndexBy';
import { sortedLastIndexOf } from './sortedLastIndexOf';
import { sortedUniq } from './sortedUniq';
import { sortedUniqBy } from './sortedUniqBy';
import { split } from './split';
import { closest, distance } from './string';
import { sum } from './sum';
import { sumBy } from './sumBy';
import { take } from './take';
import takeRight from './takeRight';
import throttle from './throttle';
import { takeRight } from './takeRight';
import { throttle } from './throttle';
import { createTimeoutPromise, TimeoutError } from './timeout';
import times from './times';
import toArray from './toArray';
import toNumber from './toNumber';
import toUpper from './toUpper';
import trim from './trim';
import { times } from './times';
import { toArray } from './toArray';
import { toNumber } from './toNumber';
import { toUpper } from './toUpper';
import { trim } from './trim';
import { trimEnd } from './trimEnd';
import { trimPrefix } from './trimPrefix';
import { trimStart } from './trimStart';
import { trimSuffix } from './trimSuffix';
import { unionBy } from './unionBy';
import { uniq } from './uniq';
import uniqBy from './uniqBy';
import uniqueId from './uniqueId';
import uniqWith from './uniqWith';
import { uniqBy } from './uniqBy';
import { uniqueId } from './uniqueId';
import { uniqWith } from './uniqWith';
import { unset } from './unset';
import unWrap from './unWrap';
import { unWrap } from './unWrap';
import { update } from './update';
import { values } from './values';
import words from './words';
import wrap from './wrap';
import { words } from './words';
import { wrap } from './wrap';


export * from './types';
Expand Down Expand Up @@ -196,7 +198,7 @@ export {
wrap, unWrap, createTimeoutPromise, TimeoutError,
retry, concurrency, fallback, logic, isSubClass,
cacheIt, cacheProvider, distance, closest, isInstance,
values, chunk
values, chunk, cacheItTTL, initial
};


Expand Down Expand Up @@ -230,7 +232,7 @@ export default {
wrap, unWrap, createTimeoutPromise, TimeoutError,
retry, concurrency, fallback, logic, isSubClass,
cacheIt, cacheProvider, distance, closest, isInstance,
values, chunk
values, chunk, cacheItTTL, initial

};

10 changes: 6 additions & 4 deletions src/initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import slice from './slice';
/**
* Gets all but the last element of `array`.
*
* @since 0.1.0
* @since 5.18.0
* @category Array
* @param {Array} array The array to query.
* @returns {Array} Returns the slice of `array`.
* @param array The array to query.
* @returns Returns the slice of `array`.
* @example
*
* ```ts
* initial([1, 2, 3])
* // => [1, 2]
* ```
*/
function initial(array) {
export function initial<T = any>(array: Array<T>): Array<T> {
const length = array == null ? 0 : array.length;
return length ? slice(array, 0, -1) : [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import isArrayLike from './isArrayLike';
* // => ['0', '1']
* ```
*/
function keys(object: any): string[] {
export function keys(object: any): string[] {
return isArrayLike(object)
? arrayLikeKeys(object)
: Object.keys(Object(object));
Expand Down

0 comments on commit 4d764d0

Please sign in to comment.