Skip to content

An algorithm that can format a string to json-like template. 字符串JSON格式化的算法。

License

Notifications You must be signed in to change notification settings

CN-Tower/format-to-json

Repository files navigation

format-to-json

Format string to a json like template.

npm LICENSE MIT

Interface

format2json

format2json(source: string, options?: FormatOptions): Promise<FormatResult | string>;

FormatOptions

interface FormatOptions {
  indent?: number;      // Integer, Large then 0, default: 2
  isExpand?: boolean;   // Default: true
  isStrict?: boolean;   // Default: false
  isEscape?: boolean;   // Default: false
  isUnscape?: boolean;  // Default: false
  keyQtMark?: "'" | "\"" | ""; // Default: "\""
  valQtMark?: "'" | "\"";      // Default: "\""
}

FormatResult

// If `{ resultOnly: true }` in option,
// Just eturn the format result string.
interface FormatResult {
  result: string;
  status: {
    fmtType: 'info' | 'success' | 'warning' | 'danger';
    fmtSign: 'ost' | 'col' | 'val' | 'end' | 'war' | 'scc' | 'err';
    fmtLines: number;
    message: string;
    errFormat: boolean;
    errIndex: number;
    errExpect: string;
    errNear: string;
  }
}