本文整理汇总了TypeScript中json-stable-stringify类的典型用法代码示例。如果您正苦于以下问题:TypeScript json-stable-stringify类的具体用法?TypeScript json-stable-stringify怎么用?TypeScript json-stable-stringify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了json-stable-stringify类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testFn
testFn(fullTestName, () => {
let input = readFileSync(join(dir, 'input.coffee'), { encoding: 'utf8' });
let actual = stripExtraInfo(stripContext(parse(input, {useCS2})));
writeFileSync(join(dir, `_actual_${useCS2 ? 'cs2' : 'cs1'}.json`), stringify(actual, {space: 2}), { encoding: 'utf8' });
if (process.env['OVERWRITE_EXPECTED_OUTPUT'] === 'true') {
writeFileSync(join(dir, 'output.json'), stringify(actual, {space: 2}), { encoding: 'utf8' });
}
let expected = JSON.parse(readFileSync(join(dir, 'output.json'), { encoding: 'utf8' }));
deepEqual(actual, expected);
});
示例2: stringify
.map(e => {
const paramsKey = stringify(e.params)
if (betterMessagesByParams[paramsKey]) {
return betterMessagesByParams[paramsKey]
}
const params = Object.keys(e.params)
.map(key => `${key}: ${e.params[key]}`)
.join(', ')
debug(stringify(e.params))
return `${name}${e.dataPath} ${e.message}. ${params}`
})
示例3: merge
/*
* Entity Entry Formatter
*/
async function merge(specEntries: StatusEntry[][]): Promise<MergedStatusEntry> {
const merged = await normalizer.merge(specEntries);
const text = stringify(merged, {
replacer: (key: string, mapOrSet: Map<any, any> | Set<any>): any => {
if (mapOrSet instanceof Map) {
const obj = {};
for (const pair of mapOrSet) {
obj[pair[0]] = pair[1];
}
return obj;
}
if (mapOrSet instanceof Set) {
const array = [];
for (const value of mapOrSet) {
array.push(value);
}
return array.sort();
}
return mapOrSet;
},
space: '\t',
});
await writeFile('data.json', text);
return merged;
}
示例4: normalize
/*
* Status Entry Formatter
*/
async function normalize(): Promise<StatusEntry[][]> {
const specEntries = await normalizer.normalize();
const text = stringify(specEntries);
await writeFile('raw.json', text);
return specEntries;
}
示例5: getPage
public getPage(
resultSpec: AFM.IResultSpec,
limit: number[] = [],
offset: number[] = []
): Promise<Execution.IExecutionResponses> {
const resultSpecFingerprint = stringify(resultSpec);
if (!this.responseFactory) {
throw new Error('Missing responseFactory!');
}
if (!this.executionPromises[resultSpecFingerprint]) {
this.executionPromises[resultSpecFingerprint] = this.responseFactory(resultSpec);
}
return this.executionPromises[resultSpecFingerprint].then(
(executionResponse: Execution.IExecutionResponse) => {
if (!this.resultFactory) {
throw new Error('Missing resultFactory!');
}
const safeOffset = offset.map((offsetItem = 0) => offsetItem);
const safeLimit = limit.map((limitItem = DEFAULT_LIMIT) => {
const safeLimitItem = Math.min(limitItem, DEFAULT_LIMIT);
if (safeLimitItem < limitItem) {
// tslint:disable-next-line:no-console
console.warn('The maximum limit per page is ' + DEFAULT_LIMIT);
}
return safeLimitItem;
});
return this.resultFactory(
executionResponse.links.executionResult,
safeLimit,
safeOffset
).then(
(executionResult: Execution.IExecutionResult | null) => ({
executionResult,
executionResponse
})
);
}
);
}
示例6: stringifyOld
const stringify = (options:StringifyOptions = {}) => (obj:any) => stringifyOld(obj, options);
示例7: hash
export function hash(a: any) {
if (isString(a) || isNumber(a) || isBoolean(a)) {
return String(a);
}
return stringify(a);
}
示例8: getFingerprint
public getFingerprint(): string {
return this.fingerprint ? this.fingerprint : stringify(this.afm);
}
示例9: it
it('should return correct fingerprint', () => {
const execFactory = () => Promise.resolve({});
const dataSource = new DataSource(execFactory, afm);
expect(dataSource.getFingerprint()).toEqual(stringify(afm));
});