import {Source, StringFormatSourceRaw, StringFormatSource} from "../generator/Source"; export {Source, StringFormatSourceRaw, StringFormatSource}; export function kebabToPascal (kebab : string) : string { const arr = kebab.split("-").map((part) => { if (part.length == 0) { return ""; } else { return part[0].toUpperCase() + part.substr(1); } }); return arr.join(""); } export function pascalToCamel (pascal : string) : string { if (pascal.length == 0) { return ""; } return pascal[0].toLowerCase() + pascal.substr(1);; } export function kebabToCamel (kebab : string) : string { return pascalToCamel(kebabToPascal(kebab)); } export const BASIC_SOURCES : Source[] = [ { name : "array-like", type : "{ [index : number] : any, length : number, indexOf : (item : any) => number }" }, { name : "array", type : "any[]" }, { name : "boolean", type : "boolean" }, { name : "date", type : "Date" }, { name : "dictionary", type : "{ [key : string] : any }" }, { name : "function", type : "Function" }, { name : "null-or-undefined", type : "null|undefined" }, { name : "null", type : "null" }, { name : "number", type : "number" }, { name : "object", type : "Object" }, { name : "string", type : "string" }, { name : "undefined", type : "undefined" } ].map((s) => { return { ...s, pascal : kebabToPascal(s.name), camel : kebabToCamel(s.name), } }); export const STRING_FORMAT_RAW_SOURCES : StringFormatSourceRaw[] = [ { name : "date", cast : "new Date" }, { name : "number", cast : "parseFloat" } ]; export const STRING_FORMAT_SOURCES : StringFormatSource[] = STRING_FORMAT_RAW_SOURCES.map((raw) => { return { name : `string-format/${raw.name}`, type : "string", pascal : kebabToPascal(raw.name) + "String", camel : kebabToCamel(raw.name) + "String", basicName : raw.name, cast : raw.cast, generated : true, }; }); export const TYPED_GENERIC_RAW_SOURCES = [ { name : "mixed", type : "T" }, { name : "number", type : "T" }, { name : "object", type : "T" }, { name : "string", type : "T" } ]; export const TYPED_GENERIC_SOURCES : Source[] = TYPED_GENERIC_RAW_SOURCES.map((s) => { return { name : `generic/${s.name}`, basicName : s.name, type : s.type, pascal : `Generic${kebabToPascal(s.name)}`, camel : `generic${kebabToPascal(s.name)}`, } }); export const ARRAY_OF_RAW_SOURCES : Source[] = [ ...BASIC_SOURCES, ...STRING_FORMAT_SOURCES, ...TYPED_GENERIC_SOURCES ]; export const ARRAY_OF_SOURCES : Source[] = ARRAY_OF_RAW_SOURCES.map((source) => { return { name : `array-of/${source.name}`, type : `(${source.type})[]`, generated : true, pascal : `ArrayOf${source.pascal}`, camel : `arrayOf${source.pascal}` }; }); export const DICTIONARY_OF_RAW_SOURCES : Source[] = [ ...BASIC_SOURCES, ...STRING_FORMAT_SOURCES, ...TYPED_GENERIC_SOURCES ]; export const DICTIONARY_OF_SOURCES : Source[] = DICTIONARY_OF_RAW_SOURCES.map((source) => { return { name : `dictionary-of/${source.name}`, type : `{ [key : string] : ${source.type} }`, generated : true, pascal : `DictionaryOf${source.pascal}`, camel : `dictionaryOf${source.pascal}` }; }); export const ARRAY_OF_DICTIONARY_OF_RAW_SOURCES = DICTIONARY_OF_SOURCES; export const ARRAY_OF_DICTIONARY_OF_SOURCES : Source[] = DICTIONARY_OF_SOURCES.map((source) => { return { name : `array-of/${source.name}`, type : `(${source.type})[]`, generated : true, pascal : `ArrayOf${source.pascal}`, camel : `arrayOf${source.pascal}` }; }); export const DICTIONARY_OF_ARRAY_OF_RAW_SOURCES = ARRAY_OF_SOURCES; export const DICTIONARY_OF_ARRAY_OF_SOURCES : Source[] = ARRAY_OF_SOURCES.map((source) => { return { name : `dictionary-of/${source.name}`, type : `{ [key : string] : ${source.type} }`, generated : true, pascal : `DictionaryOf${source.pascal}`, camel : `dictionaryOf${source.pascal}` }; }); export const MAYBE_RAW_SOURCES : Source[] = [ ...BASIC_SOURCES, ...STRING_FORMAT_SOURCES, ...TYPED_GENERIC_SOURCES, ...ARRAY_OF_SOURCES, ...DICTIONARY_OF_SOURCES, ...ARRAY_OF_DICTIONARY_OF_SOURCES, ...DICTIONARY_OF_ARRAY_OF_SOURCES ]; export const MAYBE_SOURCES : Source[] = MAYBE_RAW_SOURCES.map((source) => { return { name : `maybe/${source.name}`, type : `null|undefined|(${source.type})`, generated : true, pascal : `Maybe${source.pascal}`, camel : `maybe${source.pascal}` }; }); export const ARRAY_OF_MAYBE_RAW_SOURCES : Source[] = MAYBE_SOURCES.filter((source) => { return source.name.indexOf("maybe/array-of") < 0; }); export const ARRAY_OF_MAYBE_SOURCES : Source[] = ARRAY_OF_MAYBE_RAW_SOURCES.map((source) => { return { name : `array-of/${source.name}`, type : `((${source.type})|null|undefined)[]`, generated : true, pascal : `ArrayOf${source.pascal}`, camel : `arrayOf${source.pascal}` }; }); export const MAYBE_ARRAY_OF_MAYBE_RAW_SOURCES : Source[] = ARRAY_OF_MAYBE_SOURCES; export const MAYBE_ARRAY_OF_MAYBE_SOURCES : Source[] = ARRAY_OF_MAYBE_SOURCES.map((source) => { return { name : `maybe/${source.name}`, type : `null|undefined|(${source.type})`, generated : true, pascal : `Maybe${source.pascal}`, camel : `maybe${source.pascal}` }; }); export const DICTIONARY_OF_MAYBE_RAW_SOURCES : Source[] = MAYBE_SOURCES.filter((source) => { return source.name.indexOf("maybe/dictionary-of") < 0; }); export const DICTIONARY_OF_MAYBE_SOURCES : Source[] = DICTIONARY_OF_MAYBE_RAW_SOURCES.map((source) => { return { name : `dictionary-of/${source.name}`, type : `((${source.type})|null|undefined)[]`, generated : true, pascal : `DictionaryOf${source.pascal}`, camel : `dictionaryOf${source.pascal}` }; }); export const MAYBE_DICTIONARY_OF_MAYBE_RAW_SOURCES : Source[] = DICTIONARY_OF_MAYBE_SOURCES; export const MAYBE_DICTIONARY_OF_MAYBE_SOURCES : Source[] = DICTIONARY_OF_MAYBE_SOURCES.map((source) => { return { name : `maybe/${source.name}`, type : `null|undefined|(${source.type})`, generated : true, pascal : `Maybe${source.pascal}`, camel : `maybe${source.pascal}` }; }); export const UNTYPED_GENERIC_SOURCES : string[] = [ "array", "dictionary", "null-or-undefined", ].map((s) => { return `generic/${s}`; }); export const IS_SOURCES : Source[] = [ ...BASIC_SOURCES, ...STRING_FORMAT_SOURCES, ...TYPED_GENERIC_SOURCES, ...ARRAY_OF_SOURCES, ...DICTIONARY_OF_SOURCES, ...ARRAY_OF_DICTIONARY_OF_SOURCES, ...DICTIONARY_OF_ARRAY_OF_SOURCES, ...MAYBE_SOURCES, ...ARRAY_OF_MAYBE_SOURCES, ...MAYBE_ARRAY_OF_MAYBE_SOURCES, ...DICTIONARY_OF_MAYBE_SOURCES, ...MAYBE_DICTIONARY_OF_MAYBE_SOURCES, ]; export const ANY_ERROR_CODE_SOURCES : Source[] = [ ...IS_SOURCES, ...UNTYPED_GENERIC_SOURCES.map((s) => { return { name : s, type : "???", generated : false, pascal : "???", camel : "???" }; }) ] export const ASSERT_SOURCES : Source[] = [ ...IS_SOURCES, ]; export const EXPORT_SOURCES : Source[] = [ ...IS_SOURCES, ];