Skip to content

Commit

Permalink
feat(utils): 新增 codepointToCharacter
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed May 27, 2023
1 parent 4a09230 commit eee8868
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ yarn.lock
pnpm-lock.yaml
lib
dist
src/*/index.ts
2 changes: 1 addition & 1 deletion src/regexp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/* istanbul ignore file */

// @index(['./**/*.ts', '!./**/*.test.*', '!**/__*'], f => `export * from '${f.path}'`)
export * from './RegExpBuilder'
export * from './blankCharsRegExpBuilder'
export * from './dataUrlRegExpBuilder'
export * from './emailRegExpBuilder'
export * from './emojiRegExpBuilder'
export * from './phoneNumberRegExpBuilder'
export * from './RegExpBuilder'
// @endindex
8 changes: 8 additions & 0 deletions src/utils/codepointToCharacter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { codepointToCharacter } from './codepointToCharacter'

describe('codepointToCharacter', () => {
test('ok', () => {
expect(codepointToCharacter('3297-fe0f')).toBe('㊗️')
expect(codepointToCharacter('1f4a1')).toBe('💡')
})
})
11 changes: 11 additions & 0 deletions src/utils/codepointToCharacter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Unicode 码点转为 UTF8 字符。
*
* @param codepoint 码点,支持以 `-` 分割多个码点
*/
export function codepointToCharacter(codepoint: string): string {
return codepoint
.split('-')
.map(str => String.fromCodePoint(parseInt(str, 16)))
.join('')
}
26 changes: 14 additions & 12 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,29 @@
/* istanbul ignore file */

export * from 'lodash-uni'
export * from './Calculator'
export * from './DataPacker'
export * from './EventBus'
export * from './GeoCoord'
export * from './LocalStoragePlus'
export * from './MiniProgramUrl'
export * from './RichUrl'
export * from './StringTemplate'
export * from './TreeData'
export * from './Wechat'

// @index(['./**/*.ts', '!./**/*.{test,perf}.*'], f => `export * from '${f.path}'`)
export * from './asRequiredDeep'
export * from './base64'
export * from './bindEvent'
export * from './Calculator'
export * from './cartesianProduct'
export * from './chooseFile'
export * from './chunkEqual'
export * from './cloneDeepFast'
export * from './codepointToCharacter'
export * from './constantCase'
export * from './copyTextToClipboard'
export * from './createSubmit'
export * from './createUrlQueryString'
export * from './DataPacker'
export * from './dedent'
export * from './defaultIndexTo'
export * from './devOrProd'
export * from './EventBus'
export * from './formatBytes'
export * from './formatNumber'
export * from './GeoCoord'
export * from './getCurrentScript'
export * from './getEnvironment'
export * from './getWechatPublicAccountQrcodeUrl'
Expand All @@ -42,12 +38,12 @@ export * from './ii'
export * from './inAndroid'
export * from './inBrowser'
export * from './inDeno'
export * from './indent'
export * from './inIOS'
export * from './inMiniProgram'
export * from './inNodeJS'
export * from './inTaro'
export * from './inWechatWebView'
export * from './indent'
export * from './isBlobUrl'
export * from './isChineseIDCardNumber'
export * from './isDataUrl'
Expand All @@ -62,34 +58,40 @@ export * from './jsonp'
export * from './keysStrict'
export * from './loadCss'
export * from './loadResource'
export * from './LocalStoragePlus'
export * from './loopUntil'
export * from './makeEnum'
export * from './md5'
export * from './MiniProgramUrl'
export * from './move'
export * from './omitStrict'
export * from './onceMeanwhile'
export * from './pMap'
export * from './parseDataUrl'
export * from './parseUrlQueryString'
export * from './pascalCase'
export * from './pickStrict'
export * from './placeKitten'
export * from './pMap'
export * from './prepareData'
export * from './readFile'
export * from './removeBlankChars'
export * from './removeEmojiChars'
export * from './removeNonWordChars'
export * from './RichUrl'
export * from './rot13'
export * from './roundTo'
export * from './run'
export * from './sampleBy'
export * from './sampleIndex'
export * from './selectDom'
export * from './signal'
export * from './StringTemplate'
export * from './swap'
export * from './toFullWidthString'
export * from './toHalfWidthString'
export * from './toSingleLineString'
export * from './traverse'
export * from './TreeData'
export * from './wait'
export * from './Wechat'
// @endindex

0 comments on commit eee8868

Please sign in to comment.