本文整理汇总了TypeScript中json-stable-stringify.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default (obj: any): string => {
if (Array.isArray(obj) && obj.length === 0) {
return "[]";
} else if (typeof obj === "object" && Object.keys(obj).length === 0) {
return "{}";
}
return stringify(obj, { space: 2 });
};
示例2: callback
fs.stat(filePath, (err:Error, stats:fs.Stats) => {
if (err) {
return callback(err, false, null);
}
else if (!stats.isFile() && !stats.isDirectory()) {
return callback(new Error('PathValidator.validateStats: The specified path is not a valid file or directory. "' + filePath + '"'), false, null);
}
// remove device id from stats
if (statsToValidate.dev) {
delete statsToValidate.dev;
}
delete stats.dev;
// remove time of last access from stats
if (statsToValidate.atime) {
delete statsToValidate.atime;
}
delete stats.atime;
// @see http://stackoverflow.com/a/1144249
var isValid:boolean = stringify(stats) === stringify(statsToValidate);
callback(null, isValid, stats);
});
示例3: to_key
export function to_key(s: any): string {
if (immutable.Map.isMap(s)) {
s = s.toJS();
}
// NOTE: s is not undefined.
return json_stable(s) as string;
}
示例4: to_key
export function to_key(x: string[] | string | undefined): string | undefined {
if (typeof x === "object") {
return json_stable_stringify(x);
} else {
return x;
}
}
示例5: output
export function output(v: any[]): string {
let s = "";
let x: any;
for (x of v) {
if (x.content == null) continue;
if (x.content.data != null) {
return json(x.content.data);
}
if (x.content.text != null) {
s += x.content.text;
}
if (x.content.ename != null) {
return json(x.content);
}
}
return s;
}
示例6: stringify
format: (fields: Fields) => {
const value = fields[formattingInstruction.field];
return [
{
field: formattingInstruction.field,
value: typeof value === 'object' ? stringify(value) : `${value}`,
highlights: [],
},
];
},
示例7: add_shortcut
function add_shortcut(s: any, name: any, val: any) {
if (s.mode == null) {
for (let mode of ["escape", "edit"]) {
add_shortcut(merge(s, { mode }), name, val);
}
return;
}
shortcut_to_command[json(s)] = { name, val };
if (s.alt) {
s = copy_without(s, "alt");
s.meta = true;
return add_shortcut(s, name, val);
}
}
示例8: if
columns: logColumns.map(logColumn => {
if (SavedSourceConfigurationTimestampColumnRuntimeType.is(logColumn)) {
return {
timestamp: document.key.time,
};
} else if (SavedSourceConfigurationMessageColumnRuntimeType.is(logColumn)) {
return {
message: formatLogMessage(document.fields),
};
} else {
return {
field: logColumn.fieldColumn.field,
value: stringify(document.fields[logColumn.fieldColumn.field] || null),
};
}
}),
示例9: hash
export function hash(a: any) {
if (isNumber(a)) {
return a;
}
const str = isString(a) ? a : stableStringify(a);
// short strings can be used as hash directly, longer strings are hashed to reduce memory usage
if (str.length < 100) {
return str;
}
// from http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
let h = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
h = ((h<<5)-h)+char;
h = h & h; // Convert to 32bit integer
}
return h;
}
示例10: synctable
export function synctable(
query,
options,
client,
throttle_changes : undefined | number,
use_cache : boolean = true
): SyncTable {
if (options == null) {
options = [];
}
if (!use_cache) {
return new SyncTable(query, options, client, throttle_changes);
}
const cache_key = json_stable_stringify({
query,
options,
throttle_changes
});
let S: SyncTable | undefined = synctables[cache_key];
if (S != null) {
if (S.get_state() === "connected") {
// same behavior as newly created synctable
emit_connected_in_next_tick(S);
}
} else {
S = synctables[cache_key] = new SyncTable(
query,
options,
client,
throttle_changes
);
S.cache_key = cache_key;
}
S.reference_count += 1;
return S;
}