##// END OF EJS Templates
corrected code to support ts strict mode...
corrected code to support ts strict mode safe.ts - more tight typings - added notImplemented stub function - added fork funtion - added keys function (like Object.keys but extracts keys type) - added isKeyof typeguard - added 'primitive' union type added EventProvider for the observable

File last commit:

r115:691199f665e0 ioc ts support
r115:691199f665e0 ioc ts support
Show More
format.ts
72 lines | 1.9 KiB | video/mp2t | TypeScriptLexer
cin
ported string format traits to typescript
r55 import { format as dojoFormatNumber } from "dojo/number";
import { format as dojoFormatDate } from "dojo/date/locale";
cin
fixed "singleton" activation type handling in container configuration...
r65 import { Formatter, compile as _compile } from "./StringFormat";
cin
ported string format traits to typescript
r55
cin
corrected code to support ts strict mode...
r115 import { isNumber, isNull, get } from "../safe";
cin
ported string format traits to typescript
r55
interface NumberFormatOptions {
round?: number;
pattern?: string;
}
cin
corrected code to support ts strict mode...
r115 function convertNumber(value: any, _pattern?: string) {
cin
ported string format traits to typescript
r55 if (isNumber(value)) {
const nopt = {} as NumberFormatOptions;
cin
corrected code to support ts strict mode...
r115 let pattern = _pattern;
if (pattern && pattern.indexOf("!") === 0) {
cin
ported string format traits to typescript
r55 nopt.round = -1;
pattern = pattern.substr(1);
}
nopt.pattern = pattern;
return dojoFormatNumber(value, nopt);
cin
corrected code to support ts strict mode...
r115 } else {
return "";
cin
ported string format traits to typescript
r55 }
}
cin
corrected code to support ts strict mode...
r115 function convertDate(value: any, pattern?: string) {
cin
ported string format traits to typescript
r55 if (value instanceof Date) {
cin
corrected code to support ts strict mode...
r115 const m = pattern && pattern.match(/^(\w+)-(\w+)$/);
cin
ported string format traits to typescript
r55 if (m)
return dojoFormatDate(value, {
selector: m[2],
formatLength: m[1]
});
else if (pattern === "iso")
return value.toISOString();
else
return dojoFormatDate(value, {
selector: "date",
datePattern: pattern
});
cin
corrected code to support ts strict mode...
r115 } else {
return "";
cin
ported string format traits to typescript
r55 }
}
const _formatter = new Formatter([convertNumber, convertDate]);
cin
fixed "singleton" activation type handling in container configuration...
r65 function format(msg: string, ...args: any[]) {
return _formatter.format(msg, ...args);
}
cin
corrected code to support ts strict mode...
r115 function _convert(value: any, pattern?: string) {
cin
fixed "singleton" activation type handling in container configuration...
r65 return _formatter.convert(value, pattern);
}
namespace format {
export const convert = _convert;
export function compile(text: string) {
const template = _compile(text);
cin
corrected code to support ts strict mode...
r115 return (...data: any[]) => {
cin
fixed "singleton" activation type handling in container configuration...
r65 return template((name, pattern) => {
cin
corrected code to support ts strict mode...
r115 const value = get(name, data);
cin
fixed "singleton" activation type handling in container configuration...
r65 return !isNull(value) ? convert(value, pattern) : "";
});
};
}
}
export = format;