Skip to content

Commit

Permalink
refactoring - v1.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy-g committed Jan 5, 2024
1 parent 6055a2d commit 9880037
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
5 changes: 2 additions & 3 deletions cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ exports.osLocale = void 0;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
// @ts-check
// @ts-ignore
///<reference path="../index.d.ts"/>
///<reference types="basic-types"/>
const lib = require("./lib");
/**
* @typedef {(o: any) => o is Promise<any>} TPromiseChecker
Expand All @@ -37,6 +35,7 @@ let detector;
* @param {IsAsync=} async
* @returns {(options?: NsOsLocale.LocaleDetectorOptions) => R}
*/
// @ts-ignore
const detectorBase = (async) => (options = {}) => {
/* eslint-disable indent */
options = { spawn: true, cache: true, ...options };
Expand Down Expand Up @@ -80,7 +79,7 @@ let detector;
enumerable: false,
},
version: {
value: "v1.0.21",
value: "v1.0.22",
enumerable: true,
},
});
Expand Down
7 changes: 0 additions & 7 deletions cjs/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
// @ts-ignore
///<reference path="../index.d.ts"/>
///<reference path="./index.d.ts"/>
///<reference path="./extra-types.d.ts"/>
Object.defineProperty(exports, "__esModule", { value: true });
exports.localeGetters = exports.purgeExtraToken = exports.getEnvLocale = void 0;
const lcid = require("lcid");
const cp = require("child_process");
const { execFile, execFileSync } = cp;
/**
* @template T, A, B
* @typedef {void extends T ? A : T extends (void | false | undefined) ? A : B} Conditional
*/
/**
* @template R
* @typedef {{
Expand Down
5 changes: 2 additions & 3 deletions esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
// @ts-check
// @ts-ignore
///<reference path="../index.d.ts"/>
///<reference types="basic-types"/>
import * as lib from "./lib.mjs";
/**
* @typedef {(o: any) => o is Promise<any>} TPromiseChecker
Expand All @@ -34,6 +32,7 @@ let detector;
* @param {IsAsync=} async
* @returns {(options?: NsOsLocale.LocaleDetectorOptions) => R}
*/
// @ts-ignore
const detectorBase = (async) => (options = {}) => {
/* eslint-disable indent */
options = { spawn: true, cache: true, ...options };
Expand Down Expand Up @@ -77,7 +76,7 @@ let detector;
enumerable: false,
},
version: {
value: "v1.0.21",
value: "v1.0.22",
enumerable: true,
},
});
Expand Down
7 changes: 0 additions & 7 deletions esm/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
// @ts-ignore
///<reference path="../index.d.ts"/>
///<reference path="./index.d.ts"/>
///<reference path="./extra-types.d.ts"/>
import * as lcid from "lcid";
import * as cp from "child_process";
const { execFile, execFileSync } = cp;
/**
* @template T, A, B
* @typedef {void extends T ? A : T extends (void | false | undefined) ? A : B} Conditional
*/
/**
* @template R
* @typedef {{
Expand Down
31 changes: 30 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,36 @@
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
///<reference types="basic-types"/>

declare global {
/**
* T is falsy then return A, trusy then B
*
* ```ts
* type ConditionalX<T, A, B> = T extends (void | false | undefined) ? A : B // <- maybe not works
* type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
*
* function x<T extends true | void, R extends ConditionalX<T, string, string[]>>(need?: T): R {
* return (need? "": [""]) as R;
* }
* // string | string[]
* const xret = x();
* // string[]
* const xret2 = x(true);
*
* function ok<T extends true | void, R extends Conditional<T, string, string[]>>(need?: T): R {
* return (need? "": [""]) as R;
* }
* // string
* const okret = ok();
* // string[]
* const okret2 = ok(true);
* ```
*
* @date 20/03/31
*/
type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
}

export declare interface LocaleDetectorOptions {
/**
Expand Down
18 changes: 9 additions & 9 deletions logs/dots_test-result.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"linux": {
"options: use default(undefined)": "C",
"options: {\"spawn\":false}": "en-US",
"options: {\"spawn\":true,\"cache\":false}": "C",
"options: {\"spawn\":false,\"cache\":false}": "en-US"
"options: {spawn:false}": "en-US",
"options: {spawn:true,cache:false}": "C",
"options: {spawn:false,cache:false}": "en-US"
},
"win32": {
"options: use default(undefined)": "ja-JP",
"options: {\"spawn\":false}": "ja-JP",
"options: {\"spawn\":true,\"cache\":false}": "ja-JP",
"options: {\"spawn\":false,\"cache\":false}": "en-US"
"options: {spawn:false}": "ja-JP",
"options: {spawn:true,cache:false}": "ja-JP",
"options: {spawn:false,cache:false}": "en-US"
},
"darwin": {
"options: use default(undefined)": "en-US",
"options: {\"spawn\":false}": "en-US",
"options: {\"spawn\":true,\"cache\":false}": "en-US",
"options: {\"spawn\":false,\"cache\":false}": "en-US"
"options: {spawn:false}": "en-US",
"options: {spawn:true,cache:false}": "en-US",
"options: {spawn:false,cache:false}": "en-US"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "os-locale-s",
"version": "1.0.21",
"version": "1.0.22",
"description": "Its a light weight version that minimizes the dependency module of `os-locale`",
"private": false,
"main": "./cjs/index.js",
Expand Down Expand Up @@ -55,6 +55,6 @@
"jest": "29.7.0"
},
"scripts": {
"test": "jest --silent=false --colors -c=jest.configjs.js"
"test": "jest --silent=false --colors -c=jest.configjs.js && cat logs/dots_test-result.json"
}
}
15 changes: 8 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/*!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Copyright (C) 2020 jeffy-g <[email protected]>
Released under the MIT license
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
// @ts-ignore
/// <reference path="./index.d.ts"/>
// @ts-ignore
/// <reference path="../src/index.d.ts"/>
const fs = require("fs");
/**
* @typedef {typeof process.platform} TOSTokens
Expand All @@ -33,10 +31,14 @@ const fs = require("fs");
* @type {NsOsLocale.LocaleDetector}
*/
let osLocale;
// @ts-ignore
/**
* @param {TGThisKeys} varName
* @param {boolean} fallback
* @returns {boolean}
*/
const ifDefined = (varName, fallback) => typeof global[varName] !== "undefined" ? global[varName] : fallback;
// @ts-ignore
const debug = ifDefined("printSync", false);
const asyncDebug = ifDefined("printAsync", false);
const DEFAULT = 1;
const WIN = 1;
const LINUX = 1;
Expand Down Expand Up @@ -115,11 +117,10 @@ const emitCallback = (localeResult, detectorOpt, async) => async () => {
if (!root) {
root = localeResult[process.platform] = {};
}
root[`options: ${opt ? JSON.stringify(opt).replace(/\\"/g, "") : "use default(undefined)"}`] = locale;
root[`options: ${opt ? JSON.stringify(opt).replace(/"/g, "") : "use default(undefined)"}`] = locale;
debug && printInfo(async ? "async " : "", locale, opt);
tryMatch(locale);
};

eachModule(".");
/**
* @param {string} path module path `"../src/"(.ts)` or `"../dist/"(.js)`
Expand Down

0 comments on commit 9880037

Please sign in to comment.