Function sortPinyin

  • Sort Chinese by Chinese phonetic alphabet

    Type Parameters

    • T = string
    • P = string

    Parameters

    • a: T

      The first element for comparison.

    • b: P

      The second element for comparison.

    • options: CollatorOptions = {}

      An object adjusting the output format.

    Returns number

    • number
    const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']

    items.sort(sortPinyin)
    // [ ",11", 0, "10", 13, 3, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]

    items.sort((a, b) => sortPinyin(a, b, { ignorePunctuation: true, numeric:true }))
    // [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]

    5.14.0