escss-estest
Advanced tools
Comparing version 1.4.8 to 1.4.9
194
lib/index.js
@@ -1,59 +0,45 @@ | ||
/* | ||
- true: shows data and logs details in console.log. | ||
- false: shows `isLogVisible: false. Log details cannot be displayed.` in console.log. | ||
/* | ||
- true: shows data and log details. | ||
- false: hidden data and log details. | ||
- When you change `isLogVisible` to protect information, here are some tips: | ||
1. General: | ||
- Affecting Development: | ||
Change in `node_modules/.vite/deps/escss-estest.js` and restart `npm run dev`. | ||
- Show log details during development, set `isLogVisible: true`: | ||
1. Nuxt: | ||
Changes in `node_modules/escss-estest/lib/index.js` and restart dev server. | ||
- Affecting Production: | ||
Change in `node_modules/escss-estest/lib/index.js` and then run `npm run build; npm run preview`. | ||
2. Nuxt: | ||
Any changes in `node_modules/escss-estest/lib/index.js` will take effect. | ||
2. Others: | ||
Changes in `node_modules/.vite/deps/escss-estest.js` and restart dev server. | ||
*/ | ||
const isLogVisible = false; | ||
const customErrMsg = "undefined error message"; | ||
const isLogVisible = false | ||
const customErrMsg = 'undefined error message' | ||
let _internalTestToken = ""; | ||
const _TYPES = [ | ||
"undefined", | ||
"null", | ||
"array", | ||
"object", | ||
"boolean", | ||
"NaN", | ||
"number", | ||
"bigint", | ||
"string", | ||
"symbol", | ||
"function", | ||
]; | ||
// Internal testing purpose, does not affect production. | ||
let internalTestToken = '' | ||
const TYPES = ['undefined', 'null', 'array', 'object', 'boolean', 'NaN', 'number', 'bigint', 'string', 'symbol', 'function'] | ||
/** | ||
* New types added to typeof in JavaScript. e.g, 'null' 、 'undefined' 、 'array' 、 'NaN' | ||
* @param {*} input | ||
* @returns | ||
* @returns {string} string | ||
*/ | ||
function fixType(input) { | ||
const isNull = input === null; | ||
const isArray = Array.isArray(input); | ||
const isNaN = Number.isNaN(input); | ||
const isNull = input === null | ||
const isArray = Array.isArray(input) | ||
const isNaN = Number.isNaN(input) | ||
const typeMap = { | ||
undefined: "undefined", | ||
object: isNull ? "null" : isArray ? "array" : "object", | ||
boolean: "boolean", | ||
number: isNaN ? "NaN" : "number", | ||
bigint: "bigint", | ||
string: "string", | ||
symbol: "symbol", | ||
function: "function", | ||
}; | ||
undefined: 'undefined', | ||
object: isNull ? 'null' : isArray ? 'array' : 'object', | ||
boolean: 'boolean', | ||
number: isNaN ? 'NaN' : 'number', | ||
bigint: 'bigint', | ||
string: 'string', | ||
symbol: 'symbol', | ||
function: 'function', | ||
} | ||
return ( | ||
typeMap[typeof input] || | ||
`❌ Internal Error from fixType, please send issue https://github.com/ESCSS-labs/ESCSS-ESTest/issues. input: ${input}.` | ||
); | ||
typeMap[typeof input] | ||
|| `❌ Internal Error from fixType, please send issue https://github.com/ESCSS-labs/ESCSS-ESTest/issues. input: ${input}.` | ||
) | ||
} | ||
@@ -64,48 +50,58 @@ | ||
* @param {*} input | ||
* @returns | ||
* @returns {string} string | ||
*/ | ||
function fixTextInLog(input) { | ||
switch (fixType(input)) { | ||
case "array": | ||
return fix_ArrayInLog(); | ||
case "object": | ||
return fix_ObjectInLog(); | ||
case "bigint": | ||
return `${input}n`; | ||
case "string": | ||
return `'${input}'`; | ||
case "symbol": | ||
return `Symbol(...)`; | ||
case 'array': | ||
return fix_ArrayInLog() | ||
case 'object': | ||
return fix_ObjectInLog() | ||
case 'bigint': | ||
return `${input}n` | ||
case 'string': | ||
return `'${input}'` | ||
case 'symbol': | ||
return `Symbol(...)` | ||
default: | ||
return input; | ||
return input | ||
} | ||
function fix_ArrayInLog() { | ||
let result = ""; | ||
let result = '' | ||
input.forEach((item) => { | ||
result += `${fixTextInLog(item)}, `; | ||
}); | ||
result += `${fixTextInLog(item)}, ` | ||
}) | ||
// Remove , and space in the end | ||
result = `[${result.trim().slice(0, -1)}]`; | ||
return result; | ||
result = `[${result.trim().slice(0, -1)}]` | ||
return result | ||
} | ||
function fix_ObjectInLog() { | ||
let result = ""; | ||
let result = '' | ||
for (const [key, value] of Object.entries(input)) { | ||
result += `${key}: ${fixTextInLog(value)}, `; | ||
result += `${key}: ${fixTextInLog(value)}, ` | ||
} | ||
// Remove , and space in the end | ||
result = `{${result.trim().slice(0, -1)}}`; | ||
return result; | ||
result = `{${result.trim().slice(0, -1)}}` | ||
return result | ||
} | ||
} | ||
function getErrorMsg(msg) { | ||
throw new Error( | ||
` | ||
🚫 isLogVisible: false. Unable to display log details. | ||
❗ ${msg} | ||
`, | ||
) | ||
} | ||
/** | ||
* 100% function coverage for easier life. More: https://github.com/ESCSS-labs/ESCSS-ESTest | ||
* 100% function coverage for easier life. demo: https://demo-estest-log-not-visible.netlify.app/ | ||
* @param {*} input | ||
* @param { "undefined" | "null" | "array" | "object" | "boolean" | "NaN" | "number" | "bigint" | "string" | "symbol" | "function" } type | ||
* @param { 'undefined' | 'null' | 'array' | 'object' | 'boolean' | 'NaN' | 'number' | 'bigint' | 'string' | 'symbol' | 'function' } type | ||
* @param {string} errMsg | ||
@@ -128,55 +124,37 @@ * @example | ||
function ESTest(input, type, errMsg = customErrMsg) { | ||
if (!_TYPES.includes(type)) { | ||
if (!isLogVisible) { | ||
throw new Error( | ||
` | ||
🚫 isLogVisible: false. Log details cannot be displayed. | ||
❗ ${errMsg} | ||
` | ||
); | ||
} | ||
if (!TYPES.includes(type)) { | ||
if (!isLogVisible) getErrorMsg(errMsg) | ||
throw new Error( | ||
` | ||
❌ Received 2nd Argument Type: ${fixTextInLog(type)} | ||
✅ Expected 2nd Argument Type: 'undefined' | 'null' | 'array' | 'object' | 'boolean' | 'NaN' | 'number' | 'bigint' | 'string' | 'symbol' | 'function' | ||
` | ||
); | ||
} else if (!["undefined", "string"].includes(typeof errMsg)) { | ||
if (!isLogVisible) { | ||
throw new Error( | ||
` | ||
🚫 isLogVisible: false. Log details cannot be displayed. | ||
❗ ${errMsg} | ||
` | ||
); | ||
} | ||
❌ Received 2nd Argument: ${fixTextInLog(type)} | ||
`, | ||
) | ||
} | ||
else if (!['undefined', 'string'].includes(typeof errMsg)) { | ||
if (!isLogVisible) getErrorMsg(errMsg) | ||
throw new Error( | ||
` | ||
✅ Expected Error Message Type: 'string' | ||
❌ Received Error Message Type: '${fixType(errMsg)}' --> ${fixTextInLog(errMsg)} | ||
✅ Expected Error Message Type: 'string' | ||
`, | ||
) | ||
} | ||
else if (fixType(input) !== type) { | ||
if (!isLogVisible) getErrorMsg(errMsg) | ||
throw new Error( | ||
` | ||
); | ||
} else if (fixType(input) !== type) { | ||
if (!isLogVisible) { | ||
throw new Error( | ||
` | ||
🚫 isLogVisible: false. Log details cannot be displayed. | ||
✅ Expected Type: ${fixTextInLog(type)} | ||
❌ Received Type: '${fixType(input)}' --> ${fixTextInLog(input)} | ||
❗ ${errMsg} | ||
` | ||
); | ||
} | ||
throw new Error( | ||
` | ||
❌ Received Type: '${fixType(input)}' --> ${fixTextInLog(input)} | ||
✅ Expected Type: ${fixTextInLog(type)} | ||
❗ ${errMsg} | ||
` | ||
); | ||
`, | ||
) | ||
} | ||
// Internal testing purpose, does not affect production. | ||
_internalTestToken = type; | ||
internalTestToken = type | ||
} | ||
export { _internalTestToken, isLogVisible, ESTest }; | ||
export { internalTestToken, isLogVisible, ESTest } |
{ | ||
"name": "escss-estest", | ||
"version": "1.4.8", | ||
"version": "1.4.9", | ||
"description": "100% function coverage for easier life.", | ||
@@ -25,3 +25,4 @@ "keywords": [ | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.js" | ||
"types": "./lib/index.js", | ||
"files": ["lib"] | ||
} |
@@ -151,4 +151,9 @@ ![logo](https://github.com/ESCSS-labs/ESCSS/blob/main/assets/logo.png) | ||
```bash | ||
# Nuxt 3 | ||
npx nuxi module add nuxt-escss-estest | ||
``` | ||
## License | ||
[see](https://github.com/ESCSS-labs/ESCSS-ESTest?tab=License-1-ov-file) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159
12210
5
221
1