woonplan-packages-redishelper 2.0.0 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +0,0 @@
1
- import { JsonStringifiedMap } from "../types";
2
-
3
- const isJSON = ( str:any ) => {
4
- if( typeof str == 'number' ) return false
5
- try{
6
- JSON.parse( str )
7
- }catch( error ){
8
- return false;
9
- }
10
- return true;
11
- }
12
-
13
- interface ObjectToOmitFrom{
14
- [index: string]: any;
15
- }
16
-
17
-
18
- const omit = ( objectToOmitFrom:ObjectToOmitFrom, keys:(keyof ObjectToOmitFrom)[]) =>
19
- Object.keys( objectToOmitFrom )
20
- .filter( key => keys.indexOf( key ) == -1 )
21
- .reduce( (struct:object,key) =>
22
- Object.assign( struct, {[key]:objectToOmitFrom[key]} ) ,
23
- {}
24
- )
25
-
26
-
27
-
28
- const mapJsonReplacer = ( _key:any, value:Map<any,any> | any ) => {
29
- if(value instanceof Map) {
30
- return {
31
- dataType: 'Map',
32
- value: Array.from(value.entries()), // or with spread: value: [...value]
33
- } as JsonStringifiedMap
34
- } else {
35
- return value;
36
- }
37
- }
38
-
39
- const mapJsonReviver = ( _key:any, value:JsonStringifiedMap | any ) => {
40
- if(typeof value === 'object' && value !== null) {
41
- if (value.dataType === 'Map') {
42
- return new Map(value.value);
43
- }
44
- }
45
- return value;
46
- }
47
-
48
- const stringifyMap = ( map:Map<any,any> ):string=> JSON.stringify( map, exports.mapJsonReplacer)
49
- const parseMap = ( json:string ):Map<any,any> => JSON.parse( json, exports.mapJsonReviver)
50
- const capitalizeFirstLetter = (string:string) => string.charAt(0).toUpperCase() + string.slice(1)
51
-
52
- export { isJSON, omit, mapJsonReviver, stringifyMap, parseMap, mapJsonReplacer, capitalizeFirstLetter }
package/src/types.ts DELETED
@@ -1,49 +0,0 @@
1
-
2
- export interface JsonStringifiedMap{
3
- dataType : 'Map',
4
- value : any[]
5
- }
6
-
7
- export interface RedisMessage{
8
- [index: string]: any;
9
- }
10
- export interface Struct{
11
- [index: string]: any;
12
- }
13
-
14
- export interface RedisConfig{
15
- REDISURL: string | number | undefined;
16
- }
17
-
18
- export interface RedisStreamEntry{
19
- id : string
20
- message:RedisMessage
21
- }
22
-
23
- export type StreamMessage = [
24
- string, StreamMessageParameters
25
- ]
26
-
27
- export type StreamMessageParameters = string[]
28
- export type StreamResponse = [
29
- string, StreamMessage[]
30
- ]
31
-
32
- export interface DecypheredParameters{
33
- [index:string] : string
34
- }
35
-
36
- export interface DecypheredMessage{
37
- id : string
38
- parameters : DecypheredParameters
39
- }
40
-
41
- export interface DecypheredResponse{
42
- stream : string,
43
- messages : DecypheredMessage[]
44
- }
45
-
46
- export interface RollbarConfig{
47
- accessToken : string
48
- environment : string
49
- }