From 1b6b969f0c4e632df55191ab3a5d0dcaaae23c12 Mon Sep 17 00:00:00 2001 From: Chris Hitchcott Date: Sat, 31 Oct 2015 19:18:32 +0800 Subject: [PATCH] fixes https://github.com/neekey/ps/issues/7 - first field always starts at 0 --- lib/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index fad6491..bd44c6e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -34,13 +34,19 @@ module.exports.parse = function( output ){ if( index == 0 ){ var fields = line.split( /\s+/ ); // 保存各字段的开始和结束位置 + var fieldIndex = 0; fields.forEach(function( field ){ if( field ){ var info = titleInfo[ field ] = {}; // 记录字段值的开始和结束 - info.titleBegin = line.indexOf( field ); + if ( fieldIndex == 0 ){ + info.titleBegin = 0; + }else{ + info.titleBegin = line.indexOf( field ); + } info.titleEnd = info.titleBegin + field.length - 1; + fieldIndex++; } }); }