sheng-tool
    Preparing search index...

    Function getUnicodeCharacterAt

    • 按用户感知字符读取指定位置的字符。

      原生 charAt() / value[index] 都按 UTF-16 code unit 取值,可能只取到半个 surrogate pair, 也会把国旗、肤色 emoji、ZWJ 序列拆开。本函数的 index 对应 grapheme cluster 下标。

      Parameters

      • value: string

        被读取的字符串。

      • index: number

        用户感知字符下标。

      Returns string

      指定位置的用户感知字符;越界、负数或非有限数字时返回空字符串。

      0.2.0

      getUnicodeCharacterAt('A😀🇯🇵👍🏽B', 2)  // '🇯🇵'
      getUnicodeCharacterAt('A😀🇯🇵👍🏽B', -1) // ''