repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
webilix/regex-library
|
src/test/json-date.test.ts
|
<filename>src/test/json-date.test.ts<gh_stars>0
import { rxJsonDate } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['2000-01-01T00:00:00.000Z'];
const invalid: string[] = ['2000-01-01 00:00:00', '2000-01-01T00:00:00.000', '2000-01-01T00:00:00Z'];
testVerify('JSON DATE', rxJsonDate, valid, invalid);
testFind('JSON DATE', rxJsonDate, valid, invalid);
testReplace('JSON DATE', rxJsonDate, valid, invalid);
|
webilix/regex-library
|
src/method.ts
|
export const get = (pattern: string, fullLine: boolean = true, flags?: string): RegExp =>
fullLine ? new RegExp(`^${pattern}$`, flags) : new RegExp(pattern, flags);
export const verify = (pattern: string, text: string, flags?: string): boolean => get(pattern, true, flags).test(text);
export const find = (pattern: string, text: string, flags?: string): string[] =>
text.match(get(pattern, false, flags || 'g')) || [];
export const replace = (pattern: string, text: string, replaceWith: string = '', flags?: string): string =>
text.replace(get(pattern, false, flags || 'g'), replaceWith);
|
webilix/regex-library
|
src/lib/domain.ts
|
import { find, get, replace, verify } from '../method';
import { rxDomain } from '../regex';
export const DOMAIN = {
get: (fullLine: boolean = true, flags?: string): RegExp => get(rxDomain, fullLine, flags),
verify: (text: string): boolean => verify(rxDomain, text),
find: (text: string): string[] => find(rxDomain, text),
replace: (text: string, replaceWith: string = ''): string => replace(rxDomain, text, replaceWith),
};
|
webilix/regex-library
|
dist/test/json-date.test.d.ts
|
<reponame>webilix/regex-library
export {};
//# sourceMappingURL=json-date.test.d.ts.map
|
webilix/regex-library
|
dist/index.d.ts
|
export declare const RegX: {
DATE: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
DOMAIN: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
EMAIL: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
IP4: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
JSON_DATE: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
MOBILE: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
NUMERIC: {
get: (minLength?: number | undefined, maxLength?: number | undefined, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, minLength?: number | undefined, maxLength?: number | undefined) => boolean;
find: (text: string, minLength?: number | undefined, maxLength?: number | undefined) => string[];
replace: (text: string, replaceWith?: string, minLength?: number | undefined, maxLength?: number | undefined) => string;
};
PASSWORD: {
get: (length?: number, forceLowerCase?: boolean, forceUpperCase?: boolean, forceNumber?: boolean, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, length?: number, forceLowerCase?: boolean, forceUpperCase?: boolean, forceNumber?: boolean) => boolean;
};
TIME: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
URL: {
get: (full?: boolean, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, full?: boolean) => boolean;
find: (text: string, full?: boolean) => string[];
replace: (text: string, replaceWith?: string, full?: boolean) => string;
};
USERNAME: {
get: (length?: number, useDash?: boolean, useDot?: boolean, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, length?: number, useDash?: boolean, useDot?: boolean) => boolean;
};
};
//# sourceMappingURL=index.d.ts.map
|
webilix/regex-library
|
src/regex.ts
|
<reponame>webilix/regex-library
export const rxDate: string = `[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])`;
export const rxTime: string = `([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]`;
export const rxJsonDate: string = rxDate + `T` + rxTime + `.[0-9][0-9][0-9]Z`;
export const rxEmail: string =
`(([^<>()[\\]\\\\.,;:\\s@"]+(\\.[^<>()[\\]\\\\.,;:\\s@"]+)*)|(".+"))` +
`@` +
`((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))`;
export const rxMobile: string = `09([0-9]{9}|[0-9]{2}[- ]{1}[0-9]{3}[- ]{1}[0-9]{4})`;
export const rxNumeric = (minLength?: number, maxLength?: number): string => {
if (minLength !== undefined && minLength <= 0) throw new Error('minLength must be bigger than zero');
if (maxLength !== undefined && maxLength <= 0) throw new Error('maxLength must be bigger than zero');
if (minLength === undefined) return `[0-9]{1,}`;
if (maxLength === undefined) return `[0-9]{${minLength},}`;
if (maxLength !== undefined && minLength > maxLength)
throw new Error('maxLength must be equal or bigger than minLength');
return `[0-9]{${minLength}${minLength === maxLength ? '' : `,${maxLength}`}}`;
};
export const rxUsername = (length: number = 3, useDash: boolean = true, useDot: boolean = true): string => {
if (length < 3) throw new Error('length must be equal or bigger than 3');
return `[a-z]{1}[a-z0-9${useDash ? '-' : ''}${useDot ? '.' : ''}]{${length - 2},}[a-z]{1}`;
};
export const rxPassword = (
length: number = 8,
forceLowerCase: boolean = true,
forceUpperCase: boolean = true,
forceNumber: boolean = true,
): string => {
const lCase: string = forceLowerCase ? '(?=.*[a-z])' : '';
const uCase: string = forceUpperCase ? '(?=.*[A-Z])' : '';
const number: string = forceNumber ? '(?=.*[0-9])' : '';
return `${lCase}${uCase}${number}.{${length},}`;
};
export const rxDomain: string =
`(([a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9]|[a-zA-Z0-9])\\.)*` +
`([a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9]|[a-zA-Z0-9]){1}(\\.[a-zA-Z]{2,})+`;
export const rxUrl = (full: boolean = false): string =>
full
? `https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9]{2,}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=,]*)`
: `https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9]{2,}\\b[/]{0,1}`;
export const rxIP4: string =
`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.` +
`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.` +
`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.` +
`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)`;
|
webilix/regex-library
|
dist/method.d.ts
|
<filename>dist/method.d.ts
export declare const get: (pattern: string, fullLine?: boolean, flags?: string | undefined) => RegExp;
export declare const verify: (pattern: string, text: string, flags?: string | undefined) => boolean;
export declare const find: (pattern: string, text: string, flags?: string | undefined) => string[];
export declare const replace: (pattern: string, text: string, replaceWith?: string, flags?: string | undefined) => string;
//# sourceMappingURL=method.d.ts.map
|
webilix/regex-library
|
src/test/url.test.ts
|
import { rxUrl } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = [
'http://domain.com',
'https://domain.co.com',
'http://www.dd.com/',
'https://d.co/',
'https://d.c.co/',
];
const invalid: string[] = ['http//domain.com', 'http:domain.com', 'domain.com', 'https://d.c/'];
testVerify('URL', rxUrl(), valid, invalid);
testVerify('URL', rxUrl(true), ['https://google.com/page,1'], []);
testVerify('URL', rxUrl(false), [], ['https://google.com/page,1']);
testFind('URL', rxUrl(), valid, invalid);
testReplace('URL', rxUrl(), valid, invalid);
|
webilix/regex-library
|
dist/test/domain.test.d.ts
|
<filename>dist/test/domain.test.d.ts
export {};
//# sourceMappingURL=domain.test.d.ts.map
|
webilix/regex-library
|
dist/lib/username.d.ts
|
export declare const USERNAME: {
get: (length?: number, useDash?: boolean, useDot?: boolean, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, length?: number, useDash?: boolean, useDot?: boolean) => boolean;
};
//# sourceMappingURL=username.d.ts.map
|
webilix/regex-library
|
dist/test/username.test.d.ts
|
<reponame>webilix/regex-library<filename>dist/test/username.test.d.ts
export {};
//# sourceMappingURL=username.test.d.ts.map
|
webilix/regex-library
|
src/test/time.test.ts
|
<filename>src/test/time.test.ts<gh_stars>0
import { rxTime } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['00:00:00', '23:59:59'];
const invalid: string[] = ['24:00:00', '00:60:60', '00:00:60', '00:0:00', '00:00:0'];
testVerify('TIME', rxTime, valid, invalid);
testFind('TIME', rxTime, valid, invalid);
testReplace('TIME', rxTime, valid, invalid);
|
webilix/regex-library
|
src/test/date.test.ts
|
import { rxDate } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['1800-01-01', '1900-01-01', '2000-01-01', '2100-01-01', '0000-01-01', '9999-12-31'];
const invalid: string[] = ['2000-00-01', '2000-13-01', '2000-1-01', '2000-01-00', '2000-01-32', '2000-01-1'];
testVerify('DATE', rxDate, valid, invalid);
testFind('DATE', rxDate, valid, invalid);
testReplace('DATE', rxDate, valid, invalid);
|
webilix/regex-library
|
src/test/username.test.ts
|
import { rxUsername } from '../regex';
import { testVerify } from './_';
const valid: string[] = ['username', 'user1.-name'];
const invalid: string[] = ['ur', 'username1', '.username', 'username.', 'username-'];
testVerify('USERNAME', rxUsername(), valid, invalid);
testVerify('USERNAME', rxUsername(5, false, false), [], ['user', 'user.name', 'user-name']);
test('USERNAME: invalid input', () => {
const test = () => rxUsername(2);
expect(test).toThrow();
});
|
webilix/regex-library
|
dist/test/time.test.d.ts
|
export {};
//# sourceMappingURL=time.test.d.ts.map
|
webilix/regex-library
|
src/lib/numeric.ts
|
import { find, get, replace, verify } from '../method';
import { rxNumeric } from '../regex';
export const NUMERIC = {
get: (minLength?: number, maxLength?: number, fullLine: boolean = true, flags?: string): RegExp =>
get(rxNumeric(minLength, maxLength), fullLine, flags),
verify: (text: string, minLength?: number, maxLength?: number): boolean =>
verify(rxNumeric(minLength, maxLength), text),
find: (text: string, minLength?: number, maxLength?: number): string[] =>
find(rxNumeric(minLength, maxLength), text),
replace: (text: string, replaceWith: string = '', minLength?: number, maxLength?: number): string =>
replace(rxNumeric(minLength, maxLength), text, replaceWith),
};
|
webilix/regex-library
|
dist/test/password.test.d.ts
|
export {};
//# sourceMappingURL=password.test.d.ts.map
|
webilix/regex-library
|
src/test/ip4.test.ts
|
import { rxIP4 } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['127.0.0.1', '0.0.0.0', '255.255.255.255'];
const invalid: string[] = ['a.0.0.0', '0.a.0.0', '0.0.a.0', '0.0.0.a', '0.256.0.0', '0.0.256.0'];
testVerify('IP4', rxIP4, valid, invalid);
testFind('IP4', rxIP4, valid, invalid);
testReplace('IP4', rxIP4, valid, invalid);
|
webilix/regex-library
|
src/test/numeric.test.ts
|
import { rxNumeric } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['100', '010', '20000000'];
const invalid: string[] = ['S', 'S100', '100S', '+100', '-100', '100.00'];
testVerify('NUMERIC', rxNumeric(), valid, invalid);
testVerify('NUMERIC', rxNumeric(4), ['4444', '55555'], ['1', '22', '33']);
testVerify('NUMERIC', rxNumeric(4, 4), ['4444'], ['1', '22', '33', '55555']);
testFind('NUMERIC', rxNumeric(), valid, ['STRING']);
testReplace('NUMERIC', rxNumeric(), valid, ['STRING']);
test('NUMERIC: invalid input', () => {
const test1 = () => rxNumeric(0, 1);
expect(test1).toThrow();
const test2 = () => rxNumeric(1, 0);
expect(test2).toThrow();
const test3 = () => rxNumeric(2, 1);
expect(test3).toThrow();
});
|
webilix/regex-library
|
dist/test/email.test.d.ts
|
<filename>dist/test/email.test.d.ts<gh_stars>0
export {};
//# sourceMappingURL=email.test.d.ts.map
|
webilix/regex-library
|
src/test/mobile.test.ts
|
<filename>src/test/mobile.test.ts
import { rxMobile } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['09123456789', '0912 345 6789', '0912-345-6789'];
const invalid: string[] = ['0912345678', '9123456789', '+989123456789'];
testVerify('MOBILE', rxMobile, valid, invalid);
testFind('MOBILE', rxMobile, valid, invalid);
testReplace('MOBILE', rxMobile, valid, invalid);
|
webilix/regex-library
|
dist/test/numeric.test.d.ts
|
<reponame>webilix/regex-library
export {};
//# sourceMappingURL=numeric.test.d.ts.map
|
webilix/regex-library
|
dist/lib/time.d.ts
|
export declare const TIME: {
get: (fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string) => boolean;
find: (text: string) => string[];
replace: (text: string, replaceWith?: string) => string;
};
//# sourceMappingURL=time.d.ts.map
|
webilix/regex-library
|
dist/test/url.test.d.ts
|
<gh_stars>0
export {};
//# sourceMappingURL=url.test.d.ts.map
|
webilix/regex-library
|
src/test/password.test.ts
|
<reponame>webilix/regex-library
import { rxPassword } from '../regex';
import { testVerify } from './_';
const valid: string[] = ['AAAaaa111'];
const invalid: string[] = ['Aa1', 'AAAAAAAA', 'aaaaaaaa', '11111111'];
testVerify('PASSWORD', rxPassword(), valid, invalid);
testVerify('PASSWORD', rxPassword(4), ['Aa1.'], invalid);
|
webilix/regex-library
|
src/lib/date.ts
|
import { find, get, replace, verify } from '../method';
import { rxDate } from '../regex';
export const DATE = {
get: (fullLine: boolean = true, flags?: string): RegExp => get(rxDate, fullLine, flags),
verify: (text: string): boolean => verify(rxDate, text),
find: (text: string): string[] => find(rxDate, text),
replace: (text: string, replaceWith: string = ''): string => replace(rxDate, text, replaceWith),
};
|
webilix/regex-library
|
dist/regex.d.ts
|
<reponame>webilix/regex-library
export declare const rxDate: string;
export declare const rxTime: string;
export declare const rxJsonDate: string;
export declare const rxEmail: string;
export declare const rxMobile: string;
export declare const rxNumeric: (minLength?: number | undefined, maxLength?: number | undefined) => string;
export declare const rxUsername: (length?: number, useDash?: boolean, useDot?: boolean) => string;
export declare const rxPassword: (length?: number, forceLowerCase?: boolean, forceUpperCase?: boolean, forceNumber?: boolean) => string;
export declare const rxDomain: string;
export declare const rxUrl: (full?: boolean) => string;
export declare const rxIP4: string;
//# sourceMappingURL=regex.d.ts.map
|
webilix/regex-library
|
src/test/domain.test.ts
|
import { rxDomain } from '../regex';
import { testFind, testReplace, testVerify } from './_';
const valid: string[] = ['domain.com', 'domain.co.com', 'www.dd.com', 'd.com', 'd.co'];
const invalid: string[] = ['d.c', 'www.'];
testVerify('DOMAIN', rxDomain, valid, invalid);
testFind('DOMAIN', rxDomain, valid, invalid);
testReplace('DOMAIN', rxDomain, valid, invalid);
|
webilix/regex-library
|
src/index.ts
|
import { DATE } from './lib/date';
import { DOMAIN } from './lib/domain';
import { EMAIL } from './lib/email';
import { IP4 } from './lib/ip4';
import { JSON_DATE } from './lib/json-date';
import { MOBILE } from './lib/mobile';
import { NUMERIC } from './lib/numeric';
import { PASSWORD } from './lib/password';
import { TIME } from './lib/time';
import { URL } from './lib/url';
import { USERNAME } from './lib/username';
export const RegX = {
DATE,
DOMAIN,
EMAIL,
IP4,
JSON_DATE,
MOBILE,
NUMERIC,
PASSWORD,
TIME,
URL,
USERNAME,
};
|
webilix/regex-library
|
dist/lib/numeric.d.ts
|
<reponame>webilix/regex-library<filename>dist/lib/numeric.d.ts
export declare const NUMERIC: {
get: (minLength?: number | undefined, maxLength?: number | undefined, fullLine?: boolean, flags?: string | undefined) => RegExp;
verify: (text: string, minLength?: number | undefined, maxLength?: number | undefined) => boolean;
find: (text: string, minLength?: number | undefined, maxLength?: number | undefined) => string[];
replace: (text: string, replaceWith?: string, minLength?: number | undefined, maxLength?: number | undefined) => string;
};
//# sourceMappingURL=numeric.d.ts.map
|
webilix/regex-library
|
dist/test/_.d.ts
|
export declare const testVerify: (title: string, pattern: string, valid: string[], invalid: string[]) => void;
export declare const testFind: (title: string, pattern: string, valid: string[], invalid: string[]) => void;
export declare const testReplace: (title: string, pattern: string, valid: string[], invalid: string[]) => void;
//# sourceMappingURL=_.d.ts.map
|
deokgoo/project-2021_mandala_plan
|
src/pages/main/hooks/type.ts
|
export enum viewTypeEnum {
'mobile',
'web',
};
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/use-mandala-unit-update.ts
|
<filename>src/redux/mandala/hooks/use-mandala-unit-update.ts
import { useDispatch } from 'react-redux';
import { updateCoreUnit, updateCoreSideUnit, updateUnit } from '../actions';
import { mandalaStatusType, mandalaUnitType } from '../reducer/type';
const useMandalaUnitUpdate = ({isCore, dreamNum=null, unitNum=null}: mandalaStatusType) => {
const dispatch = useDispatch();
const updateMandala = ({title, description}: mandalaUnitType) => {
if (isCore) {
if (unitNum === null) {
console.log(1);
dispatch(updateCoreUnit(title, description));
} else {
console.log(2);
dispatch(updateCoreSideUnit(unitNum, title, description));
}
} else {
if (dreamNum === null) throw new Error('unexpect error');
if (unitNum === null) {
console.log(3);
dispatch(updateCoreSideUnit(dreamNum, title, description));
} else {
console.log(4);
dispatch(updateUnit(dreamNum, unitNum, title, description));
}
}
};
return {
updateMandala
};
}
export default useMandalaUnitUpdate;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-dream/index.tsx
|
import MandalaWebDream from './mandala-web-dream';
export default MandalaWebDream
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-web/hooks/use-main-web.ts
|
import { useState } from 'react';
import { mandalaStatusType } from '../../../redux/mandala/reducer/type';
const useMainWeb = () => {
const [select, setSelect] = useState<mandalaStatusType>({
isCore: true
});
const updateSelect = (payload: mandalaStatusType) => {
// updateSelect
setSelect(payload);
}
return {
select,
updateSelect,
}
};
export default useMainWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web/mandala-web.tsx
|
import React from 'react';
import styles from './mandala-web.module.scss';
import useMandalaSelector from './hooks/use-mandala-web';
import MandalaWebDream from '../mandala-web-dream';
const MandalaWeb = () => {
const {mandalaData} = useMandalaSelector();
const renderDreamContainer = () => {
return [
<MandalaWebDream key={0} dreamData={mandalaData.dream0} dreamStatus={{ isCore: false, dreamNum: 0 }} />,
<MandalaWebDream key={1} dreamData={mandalaData.dream1} dreamStatus={{ isCore: false, dreamNum: 1 }} />,
<MandalaWebDream key={2} dreamData={mandalaData.dream2} dreamStatus={{ isCore: false, dreamNum: 2 }} />,
<MandalaWebDream key={3} dreamData={mandalaData.dream3} dreamStatus={{ isCore: false, dreamNum: 3 }} />,
<MandalaWebDream key={4} dreamData={mandalaData.dreamCore} dreamStatus={{ isCore: true }} />,
<MandalaWebDream key={5} dreamData={mandalaData.dream4} dreamStatus={{ isCore: false, dreamNum: 4 }} />,
<MandalaWebDream key={6} dreamData={mandalaData.dream5} dreamStatus={{ isCore: false, dreamNum: 5 }} />,
<MandalaWebDream key={7} dreamData={mandalaData.dream6} dreamStatus={{ isCore: false, dreamNum: 6 }} />,
<MandalaWebDream key={8} dreamData={mandalaData.dream7} dreamStatus={{ isCore: false, dreamNum: 7 }} />,
]
}
return (
<div className={styles.container}>
{renderDreamContainer()}
</div>
)
};
export default MandalaWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web/hooks/use-mandala-web.ts
|
import { stateType } from '../../../redux/mandala/reducer/type';
import { useSelector } from 'react-redux';
import { globalReducerType } from '../../../redux/type';
const useMandalaWeb = () => {
const mandalaData: stateType = useSelector((state: globalReducerType) => state.mandalaReducer);
return {
mandalaData
}
}
export default useMandalaWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-unit/type.ts
|
<reponame>deokgoo/project-2021_mandala_plan
import { mandalaStatusType, mandalaUnitType } from '../../redux/mandala/reducer/type';
export interface propsType {
unitState: mandalaStatusType;
unitData: mandalaUnitType;
}
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/use-mandala-local.ts
|
import { useDispatch, useStore } from 'react-redux';
import { updateMandalaData } from '../actions';
const useMandalaLocal = () => {
const store = useStore();
const dispatch = useDispatch();
const storeData = () => {
localStorage.setItem('mandala', JSON.stringify(store.getState()));
}
const loadData = () => {
const mandalaData = localStorage.getItem('mandala');
if(!mandalaData) return;
dispatch(updateMandalaData(JSON.parse(mandalaData)));
}
return {
storeData,
loadData,
}
}
export default useMandalaLocal;
|
deokgoo/project-2021_mandala_plan
|
src/redux/store.ts
|
import { createStore, applyMiddleware, compose } from 'redux';
import middleware from './middleware';
import globalReducer from './reducer';
const composeEnhancers =
typeof window === 'object' &&
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;
const enhancer = composeEnhancers(applyMiddleware(middleware));
export default createStore(
globalReducer,
enhancer
);
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-web/main-web.tsx
|
import React from 'react';
import Header from '../../components/header';
import MandalaWeb from '../../components/mandala-web';
import styles from './main-web.module.scss';
import SettingWeb from '../../components/setting-web';
const MainWeb = () => {
return (
<>
<Header />
<div className={styles.container}>
<div className={styles.content}>
<MandalaWeb />
</div>
<div className={styles.setting}>
<SettingWeb />
</div>
</div>
</>
);
};
export default MainWeb;
|
deokgoo/project-2021_mandala_plan
|
src/router/index.tsx
|
import React from 'react';
import {
BrowserRouter,
Switch,
Route,
} from 'react-router-dom';
import Main from '../pages/main';
const Router = () => {
return (
<BrowserRouter>
<Switch>
<Route exact={true} path="/" component={Main}/>
</Switch>
</BrowserRouter>
);
}
export default Router;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main/hooks/index.ts
|
<filename>src/pages/main/hooks/index.ts
import UseMain from './use-main';
export default UseMain;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/actions/type.ts
|
export const UPDATE_CORE_UNIT = 'UPDATE_CORE_UNIT';
export const UPDATE_CORE_SIDE_UNIT = 'UPDATE_CORE_SIDE_UNIT';
export const UPDATE_UNIT = 'UPDATE_UNIT';
export const UPDATE_CURRENT_UNIT = 'UPDATE_CURRENT_UNIT';
export const UPDATE_MANDALA_DATA = 'UPDATE_MANDALA_DATA';
|
deokgoo/project-2021_mandala_plan
|
src/pages/main/hooks/use-main.test.ts
|
import { unmountComponentAtNode } from 'react-dom';
import { renderHook } from '@testing-library/react-hooks';
import useMain from './use-main';
import { act } from 'react-dom/test-utils';
import { viewTypeEnum } from './type';
let container: null | HTMLElement = null;
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
})
afterEach(() => {
if(!container) return;
unmountComponentAtNode(container);
container.remove();
container = null;
})
describe('hook test', () => {
it('windowDimensions test', async () => {
const { result, waitForNextUpdate } = await renderHook(() => useMain());
expect(result.current.windowViewType).toEqual(viewTypeEnum.web);
window = Object.assign(window, { innerWidth: 500, innerHeight: 500 });
act(() => {
setTimeout(() => {
window.dispatchEvent(new Event('resize'))},
100);
});
await waitForNextUpdate();
expect(result.current.windowViewType).toEqual(viewTypeEnum.mobile);
});
})
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/minimap/minimap.tsx
|
<gh_stars>0
import React from 'react';
import styles from './minimap.module.scss'
const Minimap = (props: any) => {
return (
<div className={styles.minimap}>
minimap
</div>
);
};
export default Minimap;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/reducer/type.ts
|
<reponame>deokgoo/project-2021_mandala_plan
export type unitNumType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
export type mandalaUnitType = { title: string, description: string };
export type mandalaDreamType = { core: mandalaUnitType; side: dreamType };
export type dreamType = [
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
mandalaUnitType,
];
export type sideDreamType = 'dream0'|'dream1'|'dream2'|'dream3'|'dream4'|'dream5'|'dream6'|'dream7';
export interface unitType {
core: mandalaUnitType;
side: dreamType;
}
export interface dreamStatusType {
isCore: boolean;
dreamNum?: number | null;
}
export type mandalaStatusType = dreamStatusType & { unitNum?: number|null }
export interface themesType {
currentTheme: number;
theme0: any;
}
export type stateType = {
[dream in sideDreamType]: unitType;
} & {
dreamCore: { core: mandalaUnitType; side: dreamType; };
} & { mandalaState: mandalaStatusType } & { themes: themesType };
|
deokgoo/project-2021_mandala_plan
|
src/components/setting-web/hooks/index.ts
|
<gh_stars>0
import useSettingWeb from './use-setting-web';
export default useSettingWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/organisms/mobile-main/index.tsx
|
<reponame>deokgoo/project-2021_mandala_plan
import mobileMain from "./mobile-main";
export default mobileMain;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/minimap/index.tsx
|
import Minimap from './minimap';
export default Minimap;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-unit/index.tsx
|
<gh_stars>0
import MandalaWebUnit from './mandala-web-unit';
export default MandalaWebUnit;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-mobile/index.tsx
|
<reponame>deokgoo/project-2021_mandala_plan<filename>src/components/UI/molecules/mandala-mobile/index.tsx
import MandalaMobile from './mandala-mobile';
export default MandalaMobile;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/type.ts
|
<reponame>deokgoo/project-2021_mandala_plan<gh_stars>0
import { MutableRefObject } from 'react';
export interface refsType {
titleRef: MutableRefObject<HTMLInputElement|null>;
descriptionRef: MutableRefObject<HTMLInputElement|null>;
}
|
deokgoo/project-2021_mandala_plan
|
src/components/setting-web/setting-web.tsx
|
<filename>src/components/setting-web/setting-web.tsx<gh_stars>0
import React, { FormEvent } from 'react';
import styles from './setting-web.module.scss';
import useSettingWeb from './hooks';
import useMandalaUnitUpdate from '../../redux/mandala/hooks/use-mandala-unit-update';
import useMandalaCurrentUnit from '../../redux/mandala/hooks/use-mandala-current-unit';
import useMandalaUnitSelector from '../../redux/mandala/hooks/use-mandala-unit-selector';
import useMandalaLocal from '../../redux/mandala/hooks/use-mandala-local';
const SettingWeb = () => {
const { refs: {titleRef, descriptionRef } } = useSettingWeb();
const { currentState, theme } = useMandalaCurrentUnit();
const { updateMandala } = useMandalaUnitUpdate(currentState ?? {isCore: true});
const { storeData, loadData } = useMandalaLocal();
const { initialData } = useMandalaUnitSelector(currentState);
const updateMandalaUnit = (e: FormEvent) => {
e.preventDefault();
if(!titleRef.current || !descriptionRef.current) return;
const title = titleRef.current?.value;
const description = descriptionRef.current?.value;
updateMandala({title, description});
// value reset
titleRef.current.value = '';
descriptionRef.current.value = '';
}
const saveLocalStoarge = (e: FormEvent) => {
e.preventDefault();
storeData();
}
const loadLocalStoarge = (e: FormEvent) => {
e.preventDefault();
loadData();
}
// {JSON.stringify(currentState)}
return (
<div className={styles.container}>
<div className={`${styles.preview} ${theme}`}>
<div className={styles.preview__title}>
{initialData?.title}
</div>
</div>
<form className={styles.formController}>
<label className={styles.titleLabel} htmlFor="title">Title</label>
<input id="title" className={styles.input} ref={titleRef} type="text" autoComplete="off" />
<label className={styles.titleLabel} htmlFor="description">Description</label>
<input id="description" className={styles.input} type="text" ref={descriptionRef} />
<button className={styles.submit} onClick={updateMandalaUnit}>
update
</button>
<button onClick={saveLocalStoarge}>save</button>
<button onClick={loadLocalStoarge}>load</button>
</form>
</div>
);
};
export default SettingWeb;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-mobile/main-mobile.tsx
|
import React from 'react';
import Header from '../../components/header';
import MobileMain from '../../components/UI/organisms/mobile-main';
const MainMobile = () => {
return (
<>
<Header />
<MobileMain />
</>
);
};
export default MainMobile;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web/index.tsx
|
<reponame>deokgoo/project-2021_mandala_plan
import MandalaWeb from './mandala-web';
export default MandalaWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web/hooks/use-mandala-web.test.ts
|
import useMandalaWeb from './use-mandala-web';
import { renderHook } from '@testing-library/react-hooks';
const mandalaState = {
dreamCore: {
core: {title: 'testCore', description: 'test...'},
side: [
{title: 'testSide1', description: 'testSide1 test...'},
{title: 'testSide2', description: 'testSide2 test...'},
{title: 'testSide3', description: 'testSide3 test...'},
{title: 'testSide4', description: 'testSide4 test...'},
{title: 'testSide5', description: 'testSide5 test...'},
{title: 'testSide6', description: 'testSide6 test...'},
{title: 'testSide7', description: 'testSide7 test...'},
{title: 'testSide8', description: 'testSide8 test...'},
]
},
}
jest.mock('react-redux', () => ({
useSelector: () => mandalaState,
}));
describe('useMandalaWeb ut', () => {
it('mandalaData check from redux', async () => {
const { result } = await renderHook(() => useMandalaWeb());
expect(result.current.mandalaData).toEqual(mandalaState);
});
});
|
deokgoo/project-2021_mandala_plan
|
src/components/header/header.tsx
|
import React, { memo } from 'react';
import styles from './header.module.scss';
const Header = memo(() => {
return (
<header className={styles.header}>
<div className={styles.title}>plan your dream</div>
<div className={styles.login}>login</div>
</header>
);
});
export default Header;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/use-mandala-dream-selector.ts
|
<reponame>deokgoo/project-2021_mandala_plan<gh_stars>0
import { useStore } from 'react-redux';
import { useEffect, useState } from 'react';
import {
dreamType,
mandalaDreamType,
mandalaStatusType,
mandalaUnitType,
stateType as mandalaStoreState
} from '../reducer/type';
const useMandalaDreamSelector = ({isCore, dreamNum}: mandalaStatusType) => {
const store = useStore();
const [initialData, setInitialData] = useState<mandalaDreamType>();
useEffect(() => {
const getCurrentData = (): { core: mandalaUnitType; side: dreamType } => {
const { mandalaReducer }: {mandalaReducer: mandalaStoreState} = store.getState();
if(isCore) {
return mandalaReducer.dreamCore;
} else {
// @ts-ignore
return mandalaReducer[`dream${dreamNum}`];
}
}
setInitialData(getCurrentData());
}, [isCore, dreamNum, store]);
return {
initialData,
}
}
export default useMandalaDreamSelector;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-web/hooks/index.ts
|
import useMainWeb from './use-main-web';
export default useMainWeb;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main/main.tsx
|
import React from 'react';
import UseMain from './hooks';
import MainWeb from '../main-web';
import MainMobile from '../main-mobile';
import { viewTypeEnum } from './hooks/type';
const Main = () => {
const { windowViewType } = UseMain();
return (windowViewType===viewTypeEnum.web ? <MainWeb /> : <MainMobile /> )
}
export default Main;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-mobile/index.tsx
|
import MainMobile from './main-mobile';
export default MainMobile;
|
deokgoo/project-2021_mandala_plan
|
src/components/setting-web/index.tsx
|
import SettingWeb from './setting-web';
export default SettingWeb;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/use-mandala-unit-selector.ts
|
import { useStore } from 'react-redux';
import { useEffect, useState } from 'react';
import { mandalaStatusType, mandalaUnitType, stateType as mandalaStoreState } from '../reducer/type';
const useMandalaUnitSelector = ({isCore, dreamNum, unitNum}: mandalaStatusType) => {
const store = useStore();
const [initialData, setInitialData] = useState<mandalaUnitType>();
useEffect(() => {
const getCurrentData = (): mandalaUnitType => {
const { mandalaReducer }: {mandalaReducer: mandalaStoreState} = store.getState();
if(isCore) {
if(unitNum === undefined || unitNum === null) {
return mandalaReducer.dreamCore.core
} else {
return mandalaReducer.dreamCore.side[unitNum];
}
} else {
if(dreamNum === null) throw new Error('unexpect error');
if(unitNum === null || unitNum === undefined) {
if(dreamNum === undefined) throw new Error('unexpect error');
return mandalaReducer.dreamCore.side[dreamNum];
} else {
// @ts-ignore
return mandalaReducer[`dream${dreamNum}`].side[unitNum];
}
}
}
setInitialData(getCurrentData());
}, [isCore, dreamNum, unitNum, store]);
return {
initialData,
}
}
export default useMandalaUnitSelector;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-dream/mandala-web-dream.tsx
|
<gh_stars>0
import React from 'react';
import styles from './mandala-web-dream.module.scss';
import MandalaWebUnit from '../mandala-web-unit';
import { propsType } from './type';
const MandalaWebDream = ({dreamData, dreamStatus}: propsType) => {
const renderUnitContainer = () => {
return [
<MandalaWebUnit key={0} unitData={dreamData.side[0]} unitState={{ ...dreamStatus, unitNum: 0 }} />,
<MandalaWebUnit key={1} unitData={dreamData.side[1]} unitState={{ ...dreamStatus, unitNum: 1 }} />,
<MandalaWebUnit key={2} unitData={dreamData.side[2]} unitState={{ ...dreamStatus, unitNum: 2 }} />,
<MandalaWebUnit key={3} unitData={dreamData.side[3]} unitState={{ ...dreamStatus, unitNum: 3 }} />,
<MandalaWebUnit key={4} unitData={dreamData.core} unitState={dreamStatus} />,
<MandalaWebUnit key={5} unitData={dreamData.side[4]} unitState={{ ...dreamStatus, unitNum: 4 }} />,
<MandalaWebUnit key={6} unitData={dreamData.side[5]} unitState={{ ...dreamStatus, unitNum: 5 }} />,
<MandalaWebUnit key={7} unitData={dreamData.side[6]} unitState={{ ...dreamStatus, unitNum: 6 }} />,
<MandalaWebUnit key={8} unitData={dreamData.side[7]} unitState={{ ...dreamStatus, unitNum: 7 }} />,
]
}
return (
<div className={styles.container}>
{renderUnitContainer()}
</div>
);
};
export default MandalaWebDream;
|
deokgoo/project-2021_mandala_plan
|
src/redux/reducer.ts
|
<gh_stars>0
import { combineReducers } from 'redux';
import mandalaReducer from './mandala/reducer';
export default combineReducers({ mandalaReducer });
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web/hooks/index.ts
|
<filename>src/components/mandala-web/hooks/index.ts
import useMandalaWeb from './use-mandala-web';
export default useMandalaWeb;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-mobile/mandala-mobile.tsx
|
import React from 'react';
import MandalaUnitMobile from '../mandala-unit-mobile';
import Arrow from '../arrow';
import styles from './mandala-mobile.module.scss';
const MandalaMobile = (props: any) => {
const renderMandalaMobile = () => {
let renderResult = [];
for(let i = 0; i < 9; i++) {
renderResult.push(<MandalaUnitMobile key={i} />);
}
return renderResult;
}
return (
<>
<Arrow />
<div className={styles.layout}>
<Arrow />
<div className={styles.mandalaMobileLayout}>
<div className={styles.container}>
{renderMandalaMobile()}
</div>
</div>
<Arrow />
</div>
<Arrow />
</>
);
};
export default MandalaMobile;
|
deokgoo/project-2021_mandala_plan
|
src/components/templates/mobile-template/index.tsx
|
<filename>src/components/templates/mobile-template/index.tsx
import MobileTemplate from './mobile-template';
export default MobileTemplate;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main-web/index.tsx
|
import MainWeb from './main-web';
export default MainWeb;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/reducer/index.ts
|
<reponame>deokgoo/project-2021_mandala_plan<filename>src/redux/mandala/reducer/index.ts<gh_stars>0
import {
UPDATE_CORE_SIDE_UNIT,
UPDATE_CORE_UNIT,
UPDATE_CURRENT_UNIT,
UPDATE_MANDALA_DATA,
UPDATE_UNIT,
} from '../actions/type';
import { AnyAction } from 'redux';
import initialState from './initialState';
import { stateType } from './type';
const reducer = (state: stateType = initialState, action: AnyAction) => {
switch (action.type) {
case UPDATE_CORE_UNIT: {
const {title, description} = action.payload;
const newDreamCore = {
...state.dreamCore,
core: {title, description},
}
return Object.assign({}, {...state}, {dreamCore: newDreamCore});
}
case UPDATE_CORE_SIDE_UNIT: {
const {dreamNum, title, description} = action.payload;
const newState = {...state}
newState.dreamCore.side[dreamNum] = {
title,
description,
}
// @ts-ignore
newState[`dream${dreamNum}`].core = {
title,
description
}
return Object.assign({}, {...state}, newState);
}
case UPDATE_UNIT: {
const {dreamNum, unitNum, title, description} = action.payload;
const newDream = {title, description};
const newState: stateType = Object.assign({}, {...state});
console.log(dreamNum, unitNum, title, description);
// @ts-ignore TODO: typescript
newState[`dream${dreamNum}`].side[unitNum] = newDream;
return newState;
}
case UPDATE_CURRENT_UNIT: {
const {isCore, dreamNum, unitNum} = action.payload;
return Object.assign({}, {...state}, {mandalaState: {isCore, dreamNum, unitNum}})
}
case UPDATE_MANDALA_DATA: {
const {mandalaData} = action.payload;
return mandalaData.mandalaReducer;
}
default:
return state;
}
}
export default reducer;
|
deokgoo/project-2021_mandala_plan
|
src/components/setting-web/hooks/use-setting-web.ts
|
import { useRef } from 'react';
const useSettingWeb = () => {
const refs = {
titleRef: useRef<HTMLInputElement>(null),
descriptionRef: useRef<HTMLInputElement>(null),
themeRef: useRef<HTMLInputElement>(null),
}
return {
refs,
}
}
export default useSettingWeb;
|
deokgoo/project-2021_mandala_plan
|
src/pages/main/hooks/use-main.ts
|
import { useEffect, useState } from 'react';
import { viewTypeEnum } from './type';
const getWindowDimensions = () => {
const {innerWidth: width, innerHeight: height} = window;
return {
width,
height
};
}
const useMain = () => {
const mobileWidth = 690;
const [windowViewType, setWindowViewType] = useState<viewTypeEnum>(
getWindowDimensions().width<mobileWidth?viewTypeEnum.mobile:viewTypeEnum.web);
useEffect(() => {
const handleResize = () => {
setWindowViewType(
getWindowDimensions().width<mobileWidth?viewTypeEnum.mobile:viewTypeEnum.web);
}
window.removeEventListener('resize', handleResize);
window.addEventListener('resize', handleResize);
}, []);
return {
windowViewType
}
}
export default useMain;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-form/mandala-form.tsx
|
<gh_stars>0
import React from 'react';
import styles from './mandala-form.module.scss';
const MandalaForm = (props: any) => {
return (
<div className={styles.container}>
<div className={styles.titleInputContainer}>
<input className={styles.titleInput} type="text" />
</div>
<div className={styles.descriptionContainer}>
<textarea className={styles.description} />
</div>
</div>
);
};
export default MandalaForm;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/actions/index.ts
|
import {
UPDATE_CORE_UNIT,
UPDATE_CORE_SIDE_UNIT,
UPDATE_UNIT, UPDATE_CURRENT_UNIT, UPDATE_MANDALA_DATA,
} from './type';
import { mandalaStatusType } from '../reducer/type';
export const updateCoreUnit = (title: string, description: string) => ({
type: UPDATE_CORE_UNIT,
payload: {
title,
description,
}
})
export const updateCoreSideUnit = (dreamNum: number, title: string, description: string) => ({
type: UPDATE_CORE_SIDE_UNIT,
payload: {
dreamNum,
title,
description,
}
});
export const updateUnit = (dreamNum: number, unitNum: number, title: string, description: string) => ({
type: UPDATE_UNIT,
payload: {
dreamNum,
unitNum,
title,
description,
}
});
export const updateCurrentUnit = ({isCore, dreamNum, unitNum}: mandalaStatusType) => ({
type: UPDATE_CURRENT_UNIT,
payload: {
isCore,
dreamNum,
unitNum,
}
});
export const updateMandalaData = (mandalaData: any) => ({
type: UPDATE_MANDALA_DATA,
payload: {
mandalaData,
}
});
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-unit-mobile/index.tsx
|
import MandalaUnitMobile from './mandala-unit-mobile';
export default MandalaUnitMobile;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-unit-mobile/mandala-unit-mobile.tsx
|
import React from 'react';
import style from './mandala-unit-mobile.module.scss';
const MandalaUnitMobile = (props: any) => {
return (
<div className={style.container}>
text
</div>
);
};
export default MandalaUnitMobile;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/organisms/mobile-main/mobile-main.tsx
|
import React from 'react';
import Minimap from '../../molecules/minimap';
import MandalaMobile from '../../molecules/mandala-mobile';
import MandalaForm from '../../molecules/mandala-form';
const MobileMain = (props: any) => {
return (
<main>
<Minimap />
<MandalaMobile />
<MandalaForm />
</main>
);
};
export default MobileMain;
|
deokgoo/project-2021_mandala_plan
|
src/components/templates/mobile-template/mobile-template.tsx
|
import React from 'react';
import Header from '../../header';
import MobileMain from '../../UI/organisms/mobile-main';
const MobileTemplate = (props: any) => {
return (
<>
<Header />
<MobileMain />
</>
);
};
export default MobileTemplate;
|
deokgoo/project-2021_mandala_plan
|
src/redux/type.ts
|
import { stateType as mandalaStateType } from './mandala/reducer/type';
export interface globalReducerType {
mandalaReducer: mandalaStateType
}
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/arrow/arrow.tsx
|
import React from 'react';
import styles from './arrow.module.scss';
const Arrow = (props: any) => {
return (
<>
<div className={styles.container}>
<img src="" alt="arrow"/>
</div>
</>
);
};
export default Arrow;
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/hooks/use-mandala-current-unit.ts
|
<filename>src/redux/mandala/hooks/use-mandala-current-unit.ts
import { useDispatch, useSelector } from 'react-redux';
import { mandalaStatusType, themesType } from '../reducer/type';
import { updateCurrentUnit } from '../actions';
import { useCallback, useEffect, useState } from 'react';
import { globalReducerType } from '../../type';
const useMandalaCurrentUnit = () => {
const dispatch = useDispatch();
const [theme, setTheme] = useState();
const currentState: mandalaStatusType = useSelector((state: globalReducerType) => state.mandalaReducer.mandalaState);
const currentTheme: themesType = useSelector((state: globalReducerType) => state.mandalaReducer.themes);
useEffect(() => {
const judgeTheme = () => {
// @ts-ignore
const theme = currentTheme[`theme${currentTheme.currentTheme}`];
if(currentState.isCore) {
if(currentState.unitNum === undefined) {
return theme.core;
}else {
return theme.side;
}
}else {
if(currentState.unitNum === undefined) {
return theme.side;
}else {
return theme.dream;
}
}
}
setTheme(judgeTheme());
}, [currentState, currentTheme])
const updateCurrentState = useCallback(async (payload: mandalaStatusType) => {
dispatch(updateCurrentUnit(payload));
}, [dispatch]);
return {
updateCurrentState,
currentState,
currentTheme,
theme,
}
}
export default useMandalaCurrentUnit;
|
deokgoo/project-2021_mandala_plan
|
src/components/UI/molecules/mandala-form/index.tsx
|
import MandalaForm from './mandala-form';
export default MandalaForm;
|
deokgoo/project-2021_mandala_plan
|
src/components/header/header.test.tsx
|
<reponame>deokgoo/project-2021_mandala_plan
import { render, unmountComponentAtNode } from 'react-dom';
import { act } from 'react-dom/test-utils';
import Header from './header';
let container: null | HTMLElement = null;
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
if(!container) return;
unmountComponentAtNode(container);
container.remove();
container = null;
});
describe('test header', () => {
it('header title 확인', () => {
act(() => {
render(<Header />, container);
});
expect(container?.textContent).toEqual(expect.stringContaining('plan your dream'));
});
})
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-unit/mandala-web-unit.tsx
|
import React from 'react';
import styles from './mandala-web-unit.module.scss';
import useMandalaCurrentUnit from '../../redux/mandala/hooks/use-mandala-current-unit';
import { propsType } from './type';
const MandalaWebUnit = ({unitState, unitData}: propsType) => {
const { updateCurrentState } = useMandalaCurrentUnit();
const { currentState, currentTheme } = useMandalaCurrentUnit();
const onClick = () => {
updateCurrentState(unitState);
}
const isSelected = () => {
if(currentState.isCore !== unitState.isCore) return false;
if(currentState.dreamNum !== unitState.dreamNum) return false;
if(currentState.unitNum !== unitState.unitNum) return false;
return true;
}
const theme = () => {
// @ts-ignore
const theme = currentTheme[`theme${currentTheme.currentTheme}`];
if(unitState.isCore) {
if(unitState.unitNum === undefined) {
return theme.core;
}else {
return theme.side;
}
}else {
if(unitState.unitNum === undefined) {
return theme.side;
}else {
return theme.dream;
}
}
}
return (
<div className={`${isSelected()?styles.selected:''} ${styles.container} ${theme()}`} onClick={onClick}>
<div className={styles.title}>
{unitData.title}
</div>
</div>
);
};
export default MandalaWebUnit;
|
deokgoo/project-2021_mandala_plan
|
src/components/mandala-web-dream/type.ts
|
import { mandalaStatusType, unitType } from '../../redux/mandala/reducer/type';
export interface propsType {
dreamData: unitType;
dreamStatus: mandalaStatusType;
}
|
deokgoo/project-2021_mandala_plan
|
src/redux/mandala/reducer/initialState.ts
|
<filename>src/redux/mandala/reducer/initialState.ts
import { stateType } from './type';
import styles from './style.module.scss';
const initialState: stateType = {
dreamCore: {
core: {title: 'coreTitle', description: 'coreDescription'},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream0: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream1: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream2: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream3: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream4: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream5: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream6: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
dream7: {
core: {title: '', description: ''},
side: [
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
{title: '', description: ''},
]
},
mandalaState: {
isCore: false,
dreamNum: 0,
unitNum: 0,
},
themes: {
currentTheme: 0,
theme0: {
core: styles.color2,
dream: styles.color1,
side: styles.color5,
}
}
};
export default initialState;
|
forrl/typescript-error-reporter-action
|
src/index.ts
|
import Module from 'module'
import * as path from 'path'
import * as fs from 'fs'
import { getInput, setFailed } from '@actions/core'
import { reporter } from './reporter'
import type { CompilerOptions, Diagnostic, ParsedCommandLine } from "typescript"
type TS = typeof import('typescript')
async function main() {
try {
const project = getInput('project') || 'tsconfig.json'
const projectPath = resolveProjectPath(path.resolve(process.cwd(), project))
if (projectPath == null) {
throw new Error(`No valid typescript project was not found at: ${projectPath}`)
}
typecheck(projectPath)
} catch (e) {
console.error(e)
setFailed(e)
}
}
/**
* Attempts to resolve ts config file and returns either path to it or `null`.
*/
const resolveProjectPath = (projectPath:string) => {
try {
if (fs.statSync(projectPath).isFile()) {
return projectPath
} else {
const configPath = path.resolve(projectPath, "tsconfig.json")
return fs.statSync(configPath).isFile() ? configPath : null
}
} catch {
return null
}
}
const typecheck = (projectPath:string) => {
const ts = loadTS(projectPath)
const json = ts.readConfigFile(projectPath, ts.sys.readFile)
const config = ts.parseJsonConfigFileContent(
json.config,
ts.sys,
path.dirname(projectPath),
undefined,
path.basename(projectPath)
);
const errors = isIncrementalCompilation(config.options)
? performIncrementalCompilation(ts, projectPath)
: performCompilation(ts, config)
if (errors > 0) {
setFailed(`Found ${errors} errors!`)
}
}
const performIncrementalCompilation = (ts:TS, projectPath:string) => {
const report = reporter(ts)
const host = ts.createSolutionBuilderHost(ts.sys, undefined, report, report)
const builder = ts.createSolutionBuilder(host, [projectPath], { noEmit: true })
return builder.build()
}
const performCompilation = (ts: TS, config:ParsedCommandLine) => {
const report = reporter(ts)
const host = ts.createCompilerHost(config.options)
const program = ts.createProgram({
rootNames: config.fileNames,
options: config.options,
projectReferences: config.projectReferences,
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(config)
})
const configuration = program.getConfigFileParsingDiagnostics()
let all:Diagnostic[] = [...program.getSyntacticDiagnostics()]
if (all.length === 0) {
all = [
...program.getOptionsDiagnostics(),
...program.getGlobalDiagnostics()
]
if (all.length == 0) {
all = [...program.getSemanticDiagnostics()]
}
}
const diagnostics = ts.sortAndDeduplicateDiagnostics(all)
diagnostics.forEach(report)
return all.length
}
const isIncrementalCompilation = (options: CompilerOptions) =>
options.incremental || options.composite
const loadTS = (projectPath:string):TS => {
try {
const require = Module.createRequire(projectPath)
const ts = require('typescript')
console.log(`Using local typescript@${ts.version}`);
return ts
} catch (error) {
const ts = require('typescript')
console.log(`Failed to find project specific typescript, falling back to bundled typescript@${ts.version}`);
return ts
}
}
main()
|
forrl/typescript-error-reporter-action
|
src/reporter.ts
|
<reponame>forrl/typescript-error-reporter-action
import type { Diagnostic } from 'typescript'
import { issueCommand } from '@actions/core/lib/command'
type TS = typeof import('typescript')
export const reporter = (ts:TS) => (diagnostic:Diagnostic) => {
switch (diagnostic.category) {
case ts.DiagnosticCategory.Error: {
return issueCommand('error', readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
}
case ts.DiagnosticCategory.Warning: {
return issueCommand('warning', readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
}
}
}
export const readProperties = ({ start, file }:Diagnostic) => {
const fileName = file && file.fileName
if (!fileName) return {}
if (!start) return { file: fileName }
const content = file!.getFullText()
const { line, column } = parseLocation(content, start)
return { file: fileName, line: `${line}`, col: `${column}` }
}
export const parseLocation = (content:string, position:number) => {
let l = 1
let c = 0
for (let i = 0; i < content.length && i < position; i++) {
const cc = content[i]
if (cc === '\n') {
c = 0
l++
} else {
c++
}
}
return { line: l, column: c };
}
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/braze/index.ts
|
<reponame>jbwyme/action-destinations
import type { DestinationDefinition } from '@segment/actions-core'
import type { Settings } from './generated-types'
import { defaultValues } from '@segment/actions-core'
import updateUserProfile from './updateUserProfile'
import trackEvent from './trackEvent'
import trackPurchase from './trackPurchase'
const destination: DestinationDefinition<Settings> = {
name: 'Braze Cloud Mode',
slug: 'actions-braze-cloud',
mode: 'cloud',
description: 'Send events server-side to the Braze REST API.',
authentication: {
scheme: 'custom',
fields: {
api_key: {
label: 'API Key',
description: 'Created under Developer Console in the Braze Dashboard.',
type: 'password',
required: true
},
app_id: {
label: 'App ID',
description:
'The app identifier used to reference specific Apps in requests made to the Braze API. Created under Developer Console in the Braze Dashboard.',
type: 'string',
required: true
},
endpoint: {
label: 'REST Endpoint',
description: 'Your Braze REST endpoint. [See more details](https://www.braze.com/docs/api/basics/#endpoints)',
type: 'string',
format: 'uri',
choices: [
{ label: 'US-01 (https://dashboard-01.braze.com)', value: 'https://rest.iad-01.braze.com' },
{ label: 'US-02 (https://dashboard-02.braze.com)', value: 'https://rest.iad-02.braze.com' },
{ label: 'US-03 (https://dashboard-03.braze.com)', value: 'https://rest.iad-03.braze.com' },
{ label: 'US-04 (https://dashboard-04.braze.com)', value: 'https://rest.iad-04.braze.com' },
{ label: 'US-05 (https://dashboard-05.braze.com)', value: 'https://rest.iad-05.braze.com' },
{ label: 'US-06 (https://dashboard-06.braze.com)', value: 'https://rest.iad-06.braze.com' },
{ label: 'US-08 (https://dashboard-08.braze.com)', value: 'https://rest.iad-08.braze.com' },
{ label: 'EU-01 (https://dashboard-01.braze.eu)', value: 'https://rest.fra-01.braze.eu' }
],
default: 'https://rest.iad-01.braze.com',
required: true
}
}
},
extendRequest({ settings }) {
return {
headers: {
Authorization: `Bearer ${settings.api_key}`
}
}
},
actions: {
updateUserProfile,
trackEvent,
trackPurchase
},
presets: [
{
name: 'Track Calls',
subscribe: 'type = "track" and event != "Order Completed"',
partnerAction: 'trackEvent',
mapping: defaultValues(trackEvent.fields)
},
{
name: 'Order Completed Calls',
subscribe: 'event = "Order Completed"',
partnerAction: 'trackPurchase',
mapping: defaultValues(trackPurchase.fields)
},
{
name: 'Identify Calls',
subscribe: 'type = "identify"',
partnerAction: 'updateUserProfile',
mapping: defaultValues(updateUserProfile.fields)
}
]
}
export default destination
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/amplitude/__tests__/user-agent.test.ts
|
<reponame>jbwyme/action-destinations<filename>packages/destination-actions/src/destinations/amplitude/__tests__/user-agent.test.ts
import { parseUserAgentProperties } from '../user-agent'
describe('amplitude - custom user agent parsing', () => {
it('should parse custom user agent', () => {
//This is borrowed from amplitude tests so we know its parsable:
// https://github.com/amplitude/ua-parser-js/blob/master/test/device-test.json#L138
const userAgent =
'"Mozilla/5.0 (Linux; Android 5.0.1; Lenovo TAB 2 A7-30HC Build/LRX21M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.157 Safari/537.36"'
const result = parseUserAgentProperties(userAgent)
expect(result).toEqual({
os_name: 'Android',
os_version: '5.0.1',
device_model: 'TAB 2 A7'
})
})
it('should return an empty object when there is no user agent', () => {
const result = parseUserAgentProperties(undefined)
expect(result).toEqual({})
})
})
|
jbwyme/action-destinations
|
packages/browser-destinations/src/destinations/fullstory/event/index.ts
|
import type { BrowserActionDefinition } from '../../../lib/browser-destinations'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import * as FullStory from '@fullstory/browser'
const action: BrowserActionDefinition<Settings, typeof FullStory, Payload> = {
title: 'Event',
description: 'Track events',
platform: 'web',
defaultSubscription: 'type = "track"',
fields: {
name: {
description: 'The name of the event to be tracked',
label: 'name',
required: true,
type: 'string'
},
properties: {
description: 'A propeties object containing a payload',
label: 'properties',
required: false,
type: 'object'
}
},
perform: (client, event) => {
client.event(event.payload.name, event.payload.properties ?? {})
}
}
export default action
|
jbwyme/action-destinations
|
packages/browser-destinations/src/destinations/intercom/initialize.ts
|
<gh_stars>0
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { loadScript } from '../../runtime/load-script'
import { resolveWhen } from '../../runtime/resolve-when'
import { Settings } from './generated-types'
import { InitializeOptions } from '../../lib/browser-destinations'
async function load(appId: string) {
const ic = window.Intercom
if (typeof ic === 'function') {
// @ts-ignore
ic('reattach_activator')
ic('update', window.intercomSettings)
} else {
await loadScript(`https://widget.intercom.io/widget/${appId}`)
}
}
export async function initialize(options: InitializeOptions<Settings>): Promise<Intercom_.IntercomStatic> {
const app_id = options.settings.app_id
window.intercomSettings = { app_id }
await load(app_id)
await resolveWhen(() => window.document.querySelector('#intercom-frame') !== null)
// @ts-ignore intercom does some weird stuff with their global variables
return (...args) => window.Intercom.bind(window.Intercom)(...args)
}
|
jbwyme/action-destinations
|
packages/browser-destinations/src/destinations/intercom/index.ts
|
<reponame>jbwyme/action-destinations
import type { Settings } from './generated-types'
import type { BrowserDestinationDefinition } from '../../lib/browser-destinations'
import { browserDestination } from '../../runtime/shim'
import { initialize } from './initialize'
import show from './show'
export const destination: BrowserDestinationDefinition<Settings, Intercom_.IntercomStatic> = {
name: 'Intercom',
mode: 'device',
settings: {
app_id: {
label: 'Workspace ID',
type: 'string',
required: true,
description:
'Your workspace ID (this appears as app _id in your code) is a unique code assigned to your app when you create it in Intercom. https://www.intercom.com/help/en/articles/3539-where-can-i-find-my-workspace-id-app-id'
}
},
actions: {
show
},
initialize
}
export default browserDestination(destination)
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/customerio/trackEvent/index.ts
|
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
const action: ActionDefinition<Settings, Payload> = {
title: 'Track Event',
description: 'Track an event for a known person.',
defaultSubscription: 'type = "track"',
fields: {
id: {
label: 'Person ID',
description: 'ID of the person who triggered this event.',
type: 'string',
default: {
'@path': '$.userId'
}
},
anonymous_id: {
label: 'Anonymous ID',
description: 'Anonymous ID of the person who triggered this event.',
type: 'string',
default: {
'@path': '$.anonymousId'
}
},
name: {
label: 'Event Name',
description: 'Name of the event',
type: 'string',
required: true,
default: {
'@path': '$.event'
}
},
type: {
label: 'Event Type',
description: 'Override event type. Ex. "page".',
type: 'string',
default: {
'@path': '$.type'
}
},
data: {
label: 'Data',
description: 'Custom data to include with the event.',
type: 'object',
default: {
'@path': '$.properties'
}
}
},
perform: (request, { payload }) => {
const body: Payload = {
name: payload.name,
type: payload.type,
data: payload.data
}
let url = `https://track.customer.io/api/v1/customers/${payload.id}/events`
if (payload.id === undefined) {
url = 'https://track.customer.io/api/v1/events'
body.anonymous_id = payload.anonymous_id
}
return request(url, {
method: 'post',
json: body
})
}
}
export default action
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/google-enhanced-conversions/postConversion/generated-types.ts
|
<reponame>jbwyme/action-destinations<gh_stars>0
// Generated file. DO NOT MODIFY IT BY HAND.
export interface Payload {
/**
* The Google Ads conversion label. You can find this value from your Google Ads event snippet. The provided event snippet should have, for example, `send_to: AW-123456789/AbC-D_efG-h12_34-567`. Enter the part after the forward slash, without the AW- prefix, e.g. 123456789
*/
conversion_label: string
/**
* Email address of the customer who triggered the conversion event.
*/
email: string
/**
* Order ID of the conversion event. Google requires an Order ID even if the event is not an ecommerce event.
*/
transaction_id: string
/**
* User Agent of the customer who triggered the conversion event.
*/
user_agent: string
/**
* Timestamp of the conversion event.
*/
conversion_time: string | number
/**
* The monetary value attributed to the conversion event.
*/
value?: number
/**
* Currency of the purchase or items associated with the event, in 3-letter ISO 4217 format.
*/
currency_code?: string
/**
* Phone number of the purchaser, in E.164 standard format, e.g. +14150000000
*/
phone_number?: string
/**
* First name of the individual who triggered the conversion event.
*/
first_name?: string
/**
* Last name of the individual who triggered the conversion event.
*/
last_name?: string
/**
* Street address of the individual who triggered the conversion event.
*/
street_address?: string
/**
* City of the individual who triggered the conversion event.
*/
city?: string
/**
* Region of the individual who triggered the conversion event.
*/
region?: string
/**
* Post code of the individual who triggered the conversion event.
*/
post_code?: string
/**
* Country of the individual who triggered the conversion event.
*/
country?: string
}
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/amplitude/event-schema.ts
|
import { InputField } from '@segment/actions-core'
/**
* The common fields defined by Amplitude's events api
* @see {@link https://developers.amplitude.com/docs/http-api-v2#keys-for-the-event-argument}
*/
export const eventSchema: Record<string, InputField> = {
user_id: {
label: 'User ID',
type: 'string',
allowNull: true,
description:
'A readable ID specified by you. Must have a minimum length of 5 characters. Required unless device ID is present. **Note:** If you send a request with a user ID that is not in the Amplitude system yet, then the user tied to that ID will not be marked new until their first event.',
default: {
'@path': '$.userId'
}
},
device_id: {
label: 'Device ID',
type: 'string',
description:
'A device-specific identifier, such as the Identifier for Vendor on iOS. Required unless user ID is present. If a device ID is not sent with the event, it will be set to a hashed version of the user ID.',
default: {
'@if': {
exists: { '@path': '$.context.device.id' },
then: { '@path': '$.context.device.id' },
else: { '@path': '$.anonymousId' }
}
}
},
event_type: {
label: 'Event Type',
type: 'string',
description: 'A unique identifier for your event.',
required: true,
default: {
'@path': '$.event'
}
},
session_id: {
label: 'Session ID',
type: 'datetime',
description:
'The start time of the session, necessary if you want to associate events with a particular system. To use automatic Amplitude session tracking in browsers, enable Analytics 2.0 on your connected source.',
default: {
'@path': '$.integrations.Amplitude.session_id'
}
},
time: {
label: 'Timestamp',
type: 'datetime',
description:
'The timestamp of the event. If time is not sent with the event, it will be set to the request upload time.',
default: {
'@path': '$.timestamp'
}
},
event_properties: {
label: 'Event Properties',
type: 'object',
description:
'An object of key-value pairs that represent additional data to be sent along with the event. You can store property values in an array, but note that Amplitude only supports one-dimensional arrays. Date values are transformed into string values. Object depth may not exceed 40 layers.',
default: {
'@path': '$.properties'
}
},
user_properties: {
label: 'User Properties',
type: 'object',
description:
'An object of key-value pairs that represent additional data tied to the user. You can store property values in an array, but note that Amplitude only supports one-dimensional arrays. Date values are transformed into string values. Object depth may not exceed 40 layers.',
default: {
'@path': '$.traits'
}
},
groups: {
label: 'Groups',
type: 'object',
description:
'Groups of users for the event as an event-level group. You can only track up to 5 groups. **Note:** This Amplitude feature is only available to Enterprise customers who have purchased the Accounts add-on.'
},
app_version: {
label: 'App Version',
type: 'string',
description: 'The current version of your application.',
default: {
'@path': '$.context.app.version'
}
},
platform: {
label: 'Platform',
type: 'string',
description: 'Platform of the device.',
default: {
'@path': '$.context.device.type'
}
},
os_name: {
label: 'OS Name',
type: 'string',
description: 'The name of the mobile operating system or browser that the user is using.',
default: {
'@path': '$.context.os.name'
}
},
os_version: {
label: 'OS Version',
type: 'string',
description: 'The version of the mobile operating system or browser the user is using.',
default: {
'@path': '$.context.os.version'
}
},
device_brand: {
label: 'Device Brand',
type: 'string',
description: 'The device brand that the user is using.',
default: {
'@path': '$.context.device.brand'
}
},
device_manufacturer: {
label: 'Device Manufacturer',
type: 'string',
description: 'The device manufacturer that the user is using.',
default: {
'@path': '$.context.device.manufacturer'
}
},
device_model: {
label: 'Device Model',
type: 'string',
description: 'The device model that the user is using.',
default: {
'@path': '$.context.device.model'
}
},
carrier: {
label: 'Carrier',
type: 'string',
description: 'The carrier that the user is using.',
default: {
'@path': '$.context.network.carrier'
}
},
country: {
label: 'Country',
type: 'string',
description: 'The current country of the user.',
default: {
'@path': '$.context.location.country'
}
},
region: {
label: 'Region',
type: 'string',
description: 'The current region of the user.',
default: {
'@path': '$.context.location.region'
}
},
city: {
label: 'City',
type: 'string',
description: 'The current city of the user.',
default: {
'@path': '$.context.location.city'
}
},
dma: {
label: 'Designated Market Area',
type: 'string',
description: 'The current Designated Market Area of the user.'
},
language: {
label: 'Language',
type: 'string',
description: 'The language set by the user.',
default: {
'@path': '$.context.locale'
}
},
price: {
label: 'Price',
type: 'number',
description:
'The price of the item purchased. Required for revenue data if the revenue field is not sent. You can use negative values to indicate refunds.',
default: {
'@path': '$.properties.price'
}
},
quantity: {
label: 'Quantity',
type: 'integer',
description: 'The quantity of the item purchased. Defaults to 1 if not specified.',
default: {
'@path': '$.properties.quantity'
}
},
revenue: {
label: 'Revenue',
type: 'number',
description:
'Revenue = price * quantity. If you send all 3 fields of price, quantity, and revenue, then (price * quantity) will be used as the revenue value. You can use negative values to indicate refunds. **Note:** You will need to explicitly set this if you are using the Amplitude in cloud-mode.',
default: {
'@path': '$.properties.revenue'
}
},
productId: {
label: 'Product ID',
type: 'string',
description: 'An identifier for the item purchased. You must send a price and quantity or revenue with this field.',
default: {
'@path': '$.properties.productId'
}
},
revenueType: {
label: 'Revenue Type',
type: 'string',
description:
'The type of revenue for the item purchased. You must send a price and quantity or revenue with this field.',
default: {
'@path': '$.properties.revenueType'
}
},
location_lat: {
label: 'Latitude',
type: 'number',
description: 'The current Latitude of the user.',
default: {
'@path': '$.context.location.latitude'
}
},
location_lng: {
label: 'Longtitude',
type: 'number',
description: 'The current Longitude of the user.',
default: {
'@path': '$.context.location.longitude'
}
},
ip: {
label: 'IP Address',
type: 'string',
description:
'The IP address of the user. Use "$remote" to use the IP address on the upload request. Amplitude will use the IP address to reverse lookup a user\'s location (city, country, region, and DMA). Amplitude has the ability to drop the location and IP address from events once it reaches our servers. You can submit a request to Amplitude\'s platform specialist team here to configure this for you.',
default: {
'@path': '$.context.ip'
}
},
idfa: {
label: 'Identifier For Advertiser (IDFA)',
type: 'string',
description: 'Identifier for Advertiser. _(iOS)_',
default: {
'@if': {
exists: { '@path': '$.context.device.advertisingId' },
then: { '@path': '$.context.device.advertisingId' },
else: { '@path': '$.context.device.idfa' }
}
}
},
idfv: {
label: 'Identifier For Vendor (IDFV)',
type: 'string',
description: 'Identifier for Vendor. _(iOS)_',
default: {
'@path': '$.context.device.id'
}
},
adid: {
label: 'Google Play Services Advertising ID',
type: 'string',
description: 'Google Play Services advertising ID. _(Android)_',
default: {
'@if': {
exists: { '@path': '$.context.device.advertisingId' },
then: { '@path': '$.context.device.advertisingId' },
else: { '@path': '$.context.device.idfa' }
}
}
},
android_id: {
label: 'Android ID',
type: 'string',
description: 'Android ID (not the advertising ID). _(Android)_'
},
event_id: {
label: 'Event ID',
type: 'integer',
description:
'An incrementing counter to distinguish events with the same user ID and timestamp from each other. Amplitude recommends you send an event ID, increasing over time, especially if you expect events to occur simultanenously.'
},
insert_id: {
label: 'Insert ID',
type: 'string',
description:
'Amplitude will deduplicate subsequent events sent with this ID we have already seen before within the past 7 days. Amplitude recommends generating a UUID or using some combination of device ID, user ID, event type, event ID, and time.'
}
}
|
jbwyme/action-destinations
|
packages/core/src/__tests__/schema-validation.test.ts
|
import { validateSchema } from '../schema-validation'
import { fieldsToJsonSchema } from '../destination-kit/fields-to-jsonschema'
const schema = fieldsToJsonSchema({
a: {
label: 'a',
type: 'string'
},
b: {
label: 'b',
type: 'object'
},
c: {
label: 'c',
type: 'object',
properties: {
d: {
label: 'd',
type: 'string'
}
}
},
e: {
label: 'e',
type: 'boolean'
},
f: {
label: 'f',
type: 'integer'
}
})
describe('validateSchema', () => {
it('should remove any keys that are not specified', () => {
const payload = {
nope: 'not a property'
}
validateSchema(payload, schema, `testSchema`)
expect(payload).not.toHaveProperty('nope')
expect(payload).toMatchInlineSnapshot(`Object {}`)
})
it('should allow any properties when an object type does not specify', () => {
const payload = {
a: 'a',
b: {
anything: 'goes'
},
d: 'd'
}
validateSchema(payload, schema, `testSchema`)
expect(payload).toHaveProperty('b')
expect(payload.b).toHaveProperty('anything')
expect(payload).toMatchInlineSnapshot(`
Object {
"a": "a",
"b": Object {
"anything": "goes",
},
}
`)
})
// For now we always remove unknown keys, until builders have a way to specify the behavior
it.todo('should not remove nested keys for valid properties')
it('should coerce properties for more flexible but type-safe inputs', () => {
const payload = {
a: 1234,
e: 'true',
f: '123'
}
validateSchema(payload, schema, `testSchema`)
expect(payload).toMatchInlineSnapshot(`
Object {
"a": "1234",
"e": true,
"f": 123,
}
`)
})
})
|
jbwyme/action-destinations
|
packages/destination-actions/src/destinations/amplitude/groupIdentifyUser/generated-types.ts
|
<gh_stars>0
// Generated file. DO NOT MODIFY IT BY HAND.
export interface Payload {
/**
* A UUID (unique user ID) specified by you. **Note:** If you send a request with a user ID that is not in the Amplitude system yet, then the user tied to that ID will not be marked new until their first event. Required unless device ID is present.
*/
user_id?: string | null
/**
* A device specific identifier, such as the Identifier for Vendor (IDFV) on iOS. Required unless user ID is present.
*/
device_id?: string
/**
* Amplitude will deduplicate subsequent events sent with this ID we have already seen before within the past 7 days. Amplitude recommends generating a UUID or using some combination of device ID, user ID, event type, event ID, and time.
*/
insert_id?: string
/**
* The timestamp of the event. If time is not sent with the event, it will be set to the request upload time.
*/
time?: string
/**
* Additional data tied to the group in Amplitude.
*/
group_properties?: {
[k: string]: unknown
}
/**
* Type of the group
*/
group_type: string
/**
* Value of the group
*/
group_value: string
/**
* Amplitude has a default minimum id lenght of 5 characters for user_id and device_id fields. This field allows the minimum to be overridden to allow shorter id lengths.
*/
min_id_length?: number | null
}
|
jbwyme/action-destinations
|
packages/cli/src/lib/web-bundles.ts
|
import execa from 'execa'
export function webBundles(): string[] {
const command = 'ls packages/browser-destinations/dist/web/'
const files = execa.commandSync(command).stdout
return files.split('\n')
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.