MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / serializeObject

Method serializeObject

packages/entity-generator/src/SourceFile.ts:579–599  ·  view source on GitHub ↗
(options: {}, wordwrap?: number, spaces?: number, level = 0)

Source from the content-addressed store, hash-verified

577 }
578
579 protected serializeObject(options: {}, wordwrap?: number, spaces?: number, level = 0): string {
580 if (typeof wordwrap === 'number' && !Object.hasOwn(options, Config)) {
581 const res = this.serializeObject(options, undefined, undefined, level);
582 if (res.length <= wordwrap) {
583 return res;
584 }
585 }
586 const nextWordwrap = typeof wordwrap === 'number' ? 80 - (spaces ?? 0) - level * 2 : undefined;
587 const sep = typeof spaces === 'undefined' ? ', ' : `,\n${' '.repeat(spaces)}`;
588 const doIndent = typeof spaces !== 'undefined';
589 if (Array.isArray(options)) {
590 return `[${doIndent ? `\n${' '.repeat(spaces)}` : ''}${options.map(val => `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap : undefined, doIndent ? spaces : undefined, level + 1)}`).join(sep)}${doIndent ? `${options.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ''}]`;
591 }
592 const entries = Object.entries(options);
593 return `{${doIndent ? `\n${' '.repeat(spaces)}` : ' '}${entries
594 .map(([opt, val]) => {
595 const key = identifierRegex.test(opt) ? opt : this.quote(opt);
596 return `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${key}: ${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap - key.length - 2 /* ': '.length*/ : undefined, doIndent ? spaces : undefined, level + 1)}`;
597 })
598 .join(sep)}${doIndent ? `${entries.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ' '}}`;
599 }
600
601 protected serializeValue(val: unknown, wordwrap?: number, spaces?: number, level = 1) {
602 if (typeof val === 'object' && val !== null) {

Callers 8

generateMethod · 0.95
getPropertyDefinitionMethod · 0.95
serializeValueMethod · 0.95
getPropertyDecoratorMethod · 0.95
getPropertyIndexesMethod · 0.95
generateMethod · 0.80
generateMethod · 0.80

Calls 6

serializeValueMethod · 0.95
quoteMethod · 0.95
entriesMethod · 0.80
joinMethod · 0.65
testMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected