(
object: object,
options: StringifyOptions = {},
)
| 105 | * @returns The INI string |
| 106 | */ |
| 107 | export function stringify( |
| 108 | object: object, |
| 109 | options: StringifyOptions = {}, |
| 110 | ): string { |
| 111 | const { |
| 112 | replacer = defaultReplacer, |
| 113 | pretty = false, |
| 114 | lineBreak = "\n", |
| 115 | } = options; |
| 116 | const assignment = pretty ? " = " : "="; |
| 117 | |
| 118 | const entries = Object.entries(object).sort(sort); |
| 119 | |
| 120 | const lines = []; |
| 121 | for (const [key, value] of entries) { |
| 122 | if (isPlainObject(value)) { |
| 123 | const sectionName = key; |
| 124 | lines.push(`[${sectionName}]`); |
| 125 | for (const [key, val] of Object.entries(value)) { |
| 126 | const line = `${key}${assignment}${replacer(key, val, sectionName)}`; |
| 127 | lines.push(line); |
| 128 | } |
| 129 | } else { |
| 130 | const line = `${key}${assignment}${replacer(key, value)}`; |
| 131 | lines.push(line); |
| 132 | } |
| 133 | } |
| 134 | return lines.join(lineBreak); |
| 135 | } |
no test coverage detected