File tree Expand file tree Collapse file tree 3 files changed +31
-32
lines changed
Expand file tree Collapse file tree 3 files changed +31
-32
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- export * from './get-user-locale'
1+ type NativeModule = {
2+ getLocaleInfoEx : (
3+ lpLocaleName : string | null ,
4+ LCType : number ,
5+ lpLCData : Buffer
6+ ) => number
7+ }
8+
9+ // The native binary will be loaded lazily to avoid any possible crash at start
10+ // time, which are harder to trace.
11+ let _nativeModule : NativeModule | undefined = undefined
12+
13+ function getNativeModule ( ) {
14+ if ( _nativeModule === undefined && process . platform === 'win32' ) {
15+ _nativeModule = require ( 'bindings' ) ( 'win32-user-locale.node' )
16+ }
17+
18+ return _nativeModule
19+ }
20+
21+ const LOCALE_SNAME = 0x0000005c
22+
23+ export function getUserLocale ( ) : string | undefined {
24+ const buf = Buffer . alloc ( 256 )
25+ const result = getNativeModule ( ) ?. getLocaleInfoEx ( null , LOCALE_SNAME , buf )
26+
27+ return result !== undefined && result > 0
28+ ? buf . toString ( 'utf16le' , 0 , ( result - 1 ) * 2 )
29+ : undefined
30+ }
Original file line number Diff line number Diff line change 1- import { getUserLocale } from '../lib/get-user-locale '
1+ import { getUserLocale } from '../lib/'
22
33describe ( 'getUserLocale' , ( ) => {
44 it ( 'works' , ( ) => {
You can’t perform that action at this time.
0 commit comments