(state, level, object, compact)
| 10773 | } |
| 10774 | |
| 10775 | function writeBlockMapping(state, level, object, compact) { |
| 10776 | var _result = '', |
| 10777 | _tag = state.tag, |
| 10778 | objectKeyList = Object.keys(object), |
| 10779 | index, |
| 10780 | length, |
| 10781 | objectKey, |
| 10782 | objectValue, |
| 10783 | explicitPair, |
| 10784 | pairBuffer; |
| 10785 | |
| 10786 | // Allow sorting keys so that the output file is deterministic |
| 10787 | if (state.sortKeys === true) { |
| 10788 | // Default sorting |
| 10789 | objectKeyList.sort(); |
| 10790 | } else if (typeof state.sortKeys === 'function') { |
| 10791 | // Custom sort function |
| 10792 | objectKeyList.sort(state.sortKeys); |
| 10793 | } else if (state.sortKeys) { |
| 10794 | // Something is wrong |
| 10795 | throw new YAMLException('sortKeys must be a boolean or a function'); |
| 10796 | } |
| 10797 | |
| 10798 | for (index = 0, length = objectKeyList.length; index < length; index += 1) { |
| 10799 | pairBuffer = ''; |
| 10800 | |
| 10801 | if (!compact || index !== 0) { |
| 10802 | pairBuffer += generateNextLine(state, level); |
| 10803 | } |
| 10804 | |
| 10805 | objectKey = objectKeyList[index]; |
| 10806 | objectValue = object[objectKey]; |
| 10807 | |
| 10808 | if (!writeNode(state, level + 1, objectKey, true, true, true)) { |
| 10809 | continue; // Skip this pair because of invalid key. |
| 10810 | } |
| 10811 | |
| 10812 | explicitPair = (state.tag !== null && state.tag !== '?') || |
| 10813 | (state.dump && state.dump.length > 1024); |
| 10814 | |
| 10815 | if (explicitPair) { |
| 10816 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { |
| 10817 | pairBuffer += '?'; |
| 10818 | } else { |
| 10819 | pairBuffer += '? '; |
| 10820 | } |
| 10821 | } |
| 10822 | |
| 10823 | pairBuffer += state.dump; |
| 10824 | |
| 10825 | if (explicitPair) { |
| 10826 | pairBuffer += generateNextLine(state, level); |
| 10827 | } |
| 10828 | |
| 10829 | if (!writeNode(state, level + 1, objectValue, true, explicitPair)) { |
| 10830 | continue; // Skip this pair because of invalid value. |
| 10831 | } |
| 10832 |
no test coverage detected