本文整理汇总了TypeScript中fast-json-stable-stringify.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const reporter: ChangeReporter = (path, parent, node, old, current) => {
if (options.listener) {
if (old === current || stableStringify(old) === stableStringify(current)) {
return;
}
const op = old === undefined ? 'add' : current === undefined ? 'remove' : 'replace';
options.listener(
op,
path,
parent,
current,
);
}
};
示例2: getStoreKeyName
export function getStoreKeyName(
fieldName: string,
args?: Object,
directives?: Directives,
): string {
if (
directives &&
directives['connection'] &&
directives['connection']['key']
) {
if (
directives['connection']['filter'] &&
(directives['connection']['filter'] as string[]).length > 0
) {
const filterKeys = directives['connection']['filter']
? (directives['connection']['filter'] as string[])
: [];
filterKeys.sort();
const queryArgs = args as { [key: string]: any };
const filteredArgs = {} as { [key: string]: any };
filterKeys.forEach(key => {
filteredArgs[key] = queryArgs[key];
});
return `${directives['connection']['key']}(${JSON.stringify(
filteredArgs,
)})`;
} else {
return directives['connection']['key'];
}
}
let completeFieldName: string = fieldName;
if (args) {
// We can't use `JSON.stringify` here since it's non-deterministic,
// and can lead to different store key names being created even though
// the `args` object used during creation has the same properties/values.
const stringifiedArgs: string = stringify(args);
completeFieldName += `(${stringifiedArgs})`;
}
if (directives) {
Object.keys(directives).forEach(key => {
if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;
if (directives[key] && Object.keys(directives[key]).length) {
completeFieldName += `@${key}(${JSON.stringify(directives[key])})`;
} else {
completeFieldName += `@${key}`;
}
});
}
return completeFieldName;
}
示例3: stableStringify
const newHandler = (argument: A, context: JobHandlerContext<A, I, O>) => {
const argumentJson = stableStringify(argument);
const maybeJob = runs.get(argumentJson);
if (maybeJob) {
return maybeJob;
}
const run = handler(argument, context).pipe(
replayMessages ? shareReplay() : share(),
);
runs.set(argumentJson, run);
return run;
};
示例4: constructor
constructor(config: Config.ProjectConfig) {
this._config = config;
this._transformCache = new Map();
let projectCache = projectCaches.get(config);
if (!projectCache) {
projectCache = {
configString: stableStringify(this._config),
ignorePatternsRegExp: calcIgnorePatternRegexp(this._config),
transformedFiles: new Map(),
};
projectCaches.set(config, projectCache);
}
this._cache = projectCache;
}
示例5: hash
export function hash(a: any): string | number {
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 < 250) {
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;
}
示例6: generateSchemaHash
export function generateSchemaHash(schema: GraphQLSchema): string {
const introspectionQuery = getIntrospectionQuery();
const documentAST = parse(introspectionQuery);
const result = execute(schema, documentAST) as ExecutionResult;
// If the execution of an introspection query results in a then-able, it
// indicates that one or more of its resolvers is behaving in an asynchronous
// manner. This is not the expected behavior of a introspection query
// which does not have any asynchronous resolvers.
if (
result &&
typeof (result as PromiseLike<typeof result>).then === 'function'
) {
throw new Error(
[
'The introspection query is resolving asynchronously; execution of an introspection query is not expected to return a `Promise`.',
'',
'Wrapped type resolvers should maintain the existing execution dynamics of the resolvers they wrap (i.e. async vs sync) or introspection types should be excluded from wrapping by checking them with `graphql/type`s, `isIntrospectionType` predicate function prior to wrapping.',
].join('\n'),
);
}
if (!result || !result.data || !result.data.__schema) {
throw new Error('Unable to generate server introspection document.');
}
const introspectionSchema: IntrospectionSchema = result.data.__schema;
// It's important that we perform a deterministic stringification here
// since, depending on changes in the underlying `graphql-js` execution
// layer, varying orders of the properties in the introspection
const stringifiedSchema = stableStringify(introspectionSchema);
return createSHA('sha512')
.update(stringifiedSchema)
.digest('hex');
}
示例7: stableStringify
return `Set(${[...this].map(x => stableStringify(x)).join(',')})`;