Repository: zh-lx/pinyin-pro (ts)

Issue:
开启拼音模式后，"乐"字在姓名中的读音也变了
代码：
  console.log(
    "不开启姓氏模式,曾乐的读音:",
    pinyin("曾乐", {
      toneType: "none",
    })
  );

  console.log(
    "开启姓氏模式,曾乐的读音:",
    pinyin("曾乐", {
      toneType: "none",
      mode: "surname",
    })
  );

结果：
不开启姓氏模式,曾乐的读音: ceng le
开启姓氏模式,曾乐的读音: zeng yue

试了一下其他姓氏也会这样

问：姓氏模式打开应该只会订正姓的读音，而不应该订正名字的读音？请问是否有这个功能呢


Pull request description:
fix: 修复 surname:head 对于复姓开头不生效的问题
close #237 

Patch:
diff --git a/lib/common/segmentit/index.ts b/lib/common/segmentit/index.ts
index a8e8353..c297eb2 100644
--- a/lib/common/segmentit/index.ts
+++ b/lib/common/segmentit/index.ts
@@ -176,7 +176,7 @@ export class AC {
           if (surname === "off") {
             return item.priority !== Priority.Surname;
           } else if (surname === "head") {
-            return i === 0;
+            return item.length - 1 - i === 0;
           } else {
             return true;
           }
@@ -193,7 +193,7 @@ export class AC {
             if (surname === "off") {
               return item.priority !== Priority.Surname;
             } else if (surname === "head") {
-              return i === 0;
+              return item.length - 1 - i === 0;
             } else {
               return true;
             }


Test patch:
diff --git a/test/surname.test.js b/test/surname.test.js
index 41d8727..ace1f1d 100644
--- a/test/surname.test.js
+++ b/test/surname.test.js
@@ -46,4 +46,12 @@ describe("surname", () => {
       "zēng jīng cāng hǎi nán wèi shuǐ hǎo hǎo xué xí lè"
     );
   });
+
+  it("[surname]surname head double", () => {
+    const result = pinyin("令狐冲", { surname: "head" });
+    expect(result).to.be.equal("líng hú chōng");
+
+    const result1 = pinyin("万俟英", { surname: "head" });
+    expect(result1).to.be.equal("mò qí yīng");
+  });
 });