
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
sugar2.0框架的对象类型检测类库
用例如下:
const type = require('sugar-type');
type.inspect([]); //'array'
type.inspect({test: 1}); //'object'
type.inspect('123'); //'string'
type.inspect(123); //'number'
type.inspect(NaN); //'number'
type.inspect(function(){}); //'function'
type.inspect(new Date()); //'date'
type.inspect(new Error()); //'error'
type.inspect(new Map()); //'map'
还有更加快捷的判断,返回布尔值,如下:
检查Array、Object、Map、Set4个对象是否为空,其他类型会返回true。
type.isEmpty({}); // true
type.isEmpty({a: 1}); // false
type.isEmpty(123); // true
返回是否为对象类型,用法如下:
type.isSymbol(Symbol('symbol')); // true
type.isSymbol(123); // false
返回是否为对象类型,用法如下:
type.isObject({}); // true
type.isObject(123); // false
返回是否为数组类型,用法如下:
type.isArray([1, 2, 3]); // true
type.isArray('string'); // false
返回是否为函数类型,用法如下:
type.isFunction(function(){}); // true
type.isFunction('string'); // false
返回是否为正则类型,用法如下:
type.isRegExp(/^abc/g); // true
type.isRegExp(true); // false
返回是否为日期类型,用法如下:
type.isDate(new Date()); // true
type.isDate(true); // false
返回是否为数学类型,用法如下:
type.isMath(Math); // true
type.isMath(123); // false
返回是否为错误类型,用法如下:
type.isError(new Error('这里有问题')); // true
type.isError(true); // false
返回是否为JSON类型,用法如下:
type.isJSON(JSON); // true
type.isJSON(true); // false
返回是否为参数类型,用在函数里的参数数组判断,用法如下:
function fn(param) {
console.log(type.isArguments(arguments)); // true
console.log(type.isArguments(true)); // false
}
fn('param');
返回是否为map类型,用法如下:
let map = new Map();
map.set(1, '我是小1');
map.set(2, '我是小二');
map.set(3, '我是小三');
type.isMap(map); // true
type.isMap(true); // false
返回是否为set类型,用法如下:
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
type.isMap(set); // true
type.isMap(true); // false
返回是否为字符串类型
返回是否为数字类型
返回是否为布尔类型
返回是否为null类型
返回是否为undefined类型
FAQs
Object type inspect
The npm package sugar-type receives a total of 9 weekly downloads. As such, sugar-type popularity was classified as not popular.
We found that sugar-type demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.