UNPKG

node-easy-docx

Version:

NodeJs library to parse docx file content into JSON format.

70 lines (67 loc) 3.12 kB
'use strict' function getParagraphFormat (properties) { let result = {} 'w:jc' in properties ? '_attributes' in properties['w:jc'] && 'w:val' in properties['w:jc']['_attributes'] ? properties['w:jc']['_attributes']['w:val'] === 'both' ? result['textAlign'] = 'justify' : result['textAlign'] = properties['w:jc']['_attributes']['w:val'] : result['textAlign'] = 'left' : null 'w:ind' in properties ? '_attributes' in properties['w:ind'] && 'w:left' in properties['w:ind']['_attributes'] ? result['indentLeft'] = properties['w:ind']['_attributes']['w:left'] : null : null 'w:ind' in properties ? '_attributes' in properties['w:ind'] && 'w:right' in properties['w:ind']['_attributes'] ? result['indentRight'] = properties['w:ind']['_attributes']['w:right'] : null : null 'w:ind' in properties ? '_attributes' in properties['w:ind'] && 'w:hanging' in properties['w:ind']['_attributes'] ? result['indentHanging'] = properties['w:ind']['_attributes']['w:hanging'] : null : null 'w:ind' in properties ? '_attributes' in properties['w:ind'] && 'w:firstLine' in properties['w:ind']['_attributes'] ? result['indentFirstLine'] = properties['w:ind']['_attributes']['w:firstLine'] : null : null return result } function getTextFormat (properties) { let result = {} // Bold property 'w:b' in properties ? result['bold'] = true : null 'w:i' in properties ? result['italic'] = true : null 'w:caps' in properties ? '_attributes' in properties['w:caps'] && 'w:val' in properties['w:caps']['_attributes'] ? result['caps'] = properties['w:caps']['_attributes']['w:val'] : result['caps'] = false : null 'w:color' in properties ? '_attributes' in properties['w:color'] && 'w:val' in properties['w:color']['_attributes'] ? result['color'] = '#' + properties['w:color']['_attributes']['w:val'] : result['color'] = 'default' : null 'w:dstrike' in properties ? result['dstrike'] = true : null 'w:smallCaps' in properties ? '_attributes' in properties['w:smallCaps'] && 'w:val' in properties['w:smallCaps']['_attributes'] ? result['smallCaps'] = properties['w:smallCaps']['_attributes']['w:val'] : result['smallCaps'] = false : null 'w:strike' in properties ? result['strike'] = true : null 'w:sz' in properties ? '_attributes' in properties['w:sz'] && 'w:val' in properties['w:sz']['_attributes'] ? result['size'] = properties['w:sz']['_attributes']['w:val'] : result['size'] = 'default' : null 'w:u' in properties ? '_attributes' in properties['w:u'] && 'w:val' in properties['w:u']['_attributes'] ? result['underline'] = properties['w:u']['_attributes']['w:val'] : result['underline'] = 'default' : null 'w:u' in properties ? '_attributes' in properties['w:u'] && 'w:color' in properties['w:u']['_attributes'] ? result['underlineColor'] = properties['w:u']['_attributes']['w:color'] : result['underlineColor'] = 'default' : null return result } module.exports = Object.assign( {}, { getParagraphFormat, getTextFormat } )