to-string-tag-x
Advanced tools
Comparing version
{ | ||
"root": true, | ||
"extends": "@ljharb", | ||
"plugins": [ | ||
"import" | ||
], | ||
"rules": { | ||
"indent": ["error", 2, { | ||
"SwitchCase": 1 | ||
}], | ||
"global-require": 0, | ||
"max-params": 0, | ||
"block-scoped-var": 1 | ||
} | ||
} | ||
"extends": [ | ||
"@xotic750/eslint-config-standard-x" | ||
] | ||
} |
58
index.js
@@ -29,3 +29,3 @@ /** | ||
* | ||
* @version 1.2.0 | ||
* @version 1.3.0 | ||
* @author Xotic750 <Xotic750@gmail.com> | ||
@@ -37,36 +37,30 @@ * @copyright Xotic750 | ||
/* eslint strict: 1 */ | ||
'use strict'; | ||
/* global module */ | ||
var isNull = require('lodash.isnull'); | ||
var isUndefined = require('validate.io-undefined'); | ||
var toStr = Object.prototype.toString; | ||
;(function () { // eslint-disable-line no-extra-semi | ||
/** | ||
* The `toStringTag` method returns "[object type]", where type is the | ||
* object type. | ||
* | ||
* @param {*} value - The object of which to get the object type string. | ||
* @returns {string} The object type string. | ||
* @example | ||
* var toStringTag = require('to-string-tag-x'); | ||
* | ||
* var o = new Object(); | ||
* toStringTag(o); // returns '[object Object]' | ||
*/ | ||
module.exports = function toStringTag(value) { | ||
if (isNull(value)) { | ||
return '[object Null]'; | ||
} | ||
'use strict'; | ||
if (isUndefined(value)) { | ||
return '[object Undefined]'; | ||
} | ||
var isNull = require('lodash.isnull'); | ||
var isUndefined = require('validate.io-undefined'); | ||
var nullTag = '[object Null]'; | ||
var undefTag = '[object Undefined]'; | ||
var toStr = Object.prototype.toString; | ||
/** | ||
* The `toStringTag` method returns "[object type]", where type is the | ||
* object type. | ||
* | ||
* @param {*} value The object of which to get the object type string. | ||
* @return {string} The object type string. | ||
* @example | ||
* var o = new Object(); | ||
* | ||
* toStringTag(o); // returns '[object Object]' | ||
*/ | ||
module.exports = function toStringTag(value) { | ||
if (isNull(value)) { | ||
return nullTag; | ||
} | ||
if (isUndefined(value)) { | ||
return undefTag; | ||
} | ||
return toStr.call(value); | ||
}; | ||
}()); | ||
return toStr.call(value); | ||
}; |
@@ -30,3 +30,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.returnExports = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
* | ||
* @version 1.2.0 | ||
* @version 1.3.0 | ||
* @author Xotic750 <Xotic750@gmail.com> | ||
@@ -38,38 +38,32 @@ * @copyright Xotic750 | ||
/* eslint strict: 1 */ | ||
'use strict'; | ||
/* global module */ | ||
var isNull = _dereq_('lodash.isnull'); | ||
var isUndefined = _dereq_('validate.io-undefined'); | ||
var toStr = Object.prototype.toString; | ||
;(function () { // eslint-disable-line no-extra-semi | ||
/** | ||
* The `toStringTag` method returns "[object type]", where type is the | ||
* object type. | ||
* | ||
* @param {*} value - The object of which to get the object type string. | ||
* @returns {string} The object type string. | ||
* @example | ||
* var toStringTag = require('to-string-tag-x'); | ||
* | ||
* var o = new Object(); | ||
* toStringTag(o); // returns '[object Object]' | ||
*/ | ||
module.exports = function toStringTag(value) { | ||
if (isNull(value)) { | ||
return '[object Null]'; | ||
} | ||
'use strict'; | ||
if (isUndefined(value)) { | ||
return '[object Undefined]'; | ||
} | ||
var isNull = _dereq_('lodash.isnull'); | ||
var isUndefined = _dereq_('validate.io-undefined'); | ||
var nullTag = '[object Null]'; | ||
var undefTag = '[object Undefined]'; | ||
var toStr = Object.prototype.toString; | ||
return toStr.call(value); | ||
}; | ||
/** | ||
* The `toStringTag` method returns "[object type]", where type is the | ||
* object type. | ||
* | ||
* @param {*} value The object of which to get the object type string. | ||
* @return {string} The object type string. | ||
* @example | ||
* var o = new Object(); | ||
* | ||
* toStringTag(o); // returns '[object Object]' | ||
*/ | ||
module.exports = function toStringTag(value) { | ||
if (isNull(value)) { | ||
return nullTag; | ||
} | ||
if (isUndefined(value)) { | ||
return undefTag; | ||
} | ||
return toStr.call(value); | ||
}; | ||
}()); | ||
},{"lodash.isnull":2,"validate.io-undefined":3}],2:[function(_dereq_,module,exports){ | ||
@@ -76,0 +70,0 @@ /** |
@@ -1,2 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.returnExports=e()}}(function(){return function e(n,t,o){function s(r,u){if(!t[r]){if(!n[r]){var f="function"==typeof require&&require;if(!u&&f)return f(r,!0);if(i)return i(r,!0);var d=new Error("Cannot find module '"+r+"'");throw d.code="MODULE_NOT_FOUND",d}var l=t[r]={exports:{}};n[r][0].call(l.exports,function(e){var t=n[r][1][e];return s(t||e)},l,l.exports,e,n,t,o)}return t[r].exports}for(var i="function"==typeof require&&require,r=0;r<o.length;r++)s(o[r]);return s}({1:[function(e,n,t){!function(){"use strict";var t=e("lodash.isnull"),o=e("validate.io-undefined"),i=Object.prototype.toString;n.exports=function toStringTag(e){return t(e)?"[object Null]":o(e)?"[object Undefined]":i.call(e)}}()},{"lodash.isnull":2,"validate.io-undefined":3}],2:[function(e,n,t){function isNull(e){return null===e}n.exports=isNull},{}],3:[function(e,n,t){"use strict";function isUndefined(e){return void 0===e}n.exports=isUndefined},{}]},{},[1])(1)}); | ||
//# sourceMappingURL=lib/to-string-tag-x.map | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).returnExports=e()}}(function(){return function e(n,t,o){function s(i,u){if(!t[i]){if(!n[i]){var f="function"==typeof require&&require;if(!u&&f)return f(i,!0);if(r)return r(i,!0);var d=new Error("Cannot find module '"+i+"'");throw d.code="MODULE_NOT_FOUND",d}var l=t[i]={exports:{}};n[i][0].call(l.exports,function(e){var t=n[i][1][e];return s(t||e)},l,l.exports,e,n,t,o)}return t[i].exports}for(var r="function"==typeof require&&require,i=0;i<o.length;i++)s(o[i]);return s}({1:[function(e,n,t){"use strict";var o=e("lodash.isnull"),r=e("validate.io-undefined"),i=Object.prototype.toString;n.exports=function toStringTag(e){return o(e)?"[object Null]":r(e)?"[object Undefined]":i.call(e)}},{"lodash.isnull":2,"validate.io-undefined":3}],2:[function(e,n,t){n.exports=function isNull(e){return null===e}},{}],3:[function(e,n,t){"use strict";n.exports=function isUndefined(e){return void 0===e}},{}]},{},[1])(1)}); |
{ | ||
"name": "to-string-tag-x", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Get an object's ES6 @@toStringTag.", | ||
@@ -35,32 +35,48 @@ "homepage": "https://github.com/Xotic750/to-string-tag-x", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^11.0.0", | ||
"browserify": "^14.1.0", | ||
"@xotic750/eslint-config-standard-x": "^1.4.0", | ||
"browserify": "^14.4.0", | ||
"browserify-derequire": "^0.9.4", | ||
"cross-env": "^5.0.1", | ||
"es5-shim": "^4.5.9", | ||
"es6-shim": "^0.35.3", | ||
"es7-shim": "^6.0.0", | ||
"eslint": "^3.18.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint": "^4.1.1", | ||
"eslint-plugin-compat": "^1.0.4", | ||
"eslint-plugin-css-modules": "^2.7.2", | ||
"eslint-plugin-eslint-comments": "^1.0.2", | ||
"eslint-plugin-jsdoc": "^3.1.1", | ||
"eslint-plugin-json": "^1.2.0", | ||
"eslint-plugin-no-use-extend-native": "^0.3.12", | ||
"husky": "^0.13.4", | ||
"jasmine-node": "^1.14.5", | ||
"jsdoc-to-markdown": "^3.0.0", | ||
"json3": "^3.3.2", | ||
"make-jasmine-spec-runner-html": "^1.1.0", | ||
"make-jasmine-spec-runner-html": "^1.2.0", | ||
"nodemon": "^1.11.0", | ||
"nsp": "^2.6.3", | ||
"replace-x": "^1.1.1", | ||
"uglify-js": "^2.8.18" | ||
"parallelshell": "^3.0.1", | ||
"replace-x": "^1.3.1", | ||
"rimraf": "^2.6.1", | ||
"serve": "^6.0.0", | ||
"uglify-js": "^3.0.23" | ||
}, | ||
"scripts": { | ||
"build": "npm run build:setver && npm run security && npm run eslint && npm run browserify && npm run uglify && npm run docs && npm run build:jasmine && npm test", | ||
"build:jasmine": "make-jasmine-spec-runner-html", | ||
"clean": "rimraf README.md lib/*", | ||
"clean:jasmine": "rimraf tests/index.html tests/run.js", | ||
"clean:all": "npm run clean:jasmine && npm run clean", | ||
"build": "npm run clean && npm run lint && npm run browserify && npm run uglify && npm run docs && npm test && npm run security", | ||
"build:jasmine": "npm run clean:jasmine && make-jasmine-spec-runner-html", | ||
"build:setver": "PKG_VER=$(node -p -e \"require('./package.json').version\") && replace-x \" @version .*\" \" @version ${PKG_VER}\" index.js", | ||
"build:watch": "nodemon --watch index.js --watch package.json --exec 'npm run build'", | ||
"production": "npm run clean:all && npm run build:jasmine && npm run build:setver && npm run build", | ||
"start": "parallelshell \"serve\" \"nodemon --watch index.js --exec 'npm run build'\"", | ||
"docs": "jsdoc2md --name-format --example-lang js index.js > README.md", | ||
"eslint": "eslint *.js tests/spec/*.js", | ||
"lint": "eslint *.js tests/spec/*.js", | ||
"lint-fix": "eslint --fix *.js tests/spec/*.js", | ||
"security": "nsp check", | ||
"test": "jasmine-node --matchall tests/spec/", | ||
"test:watch": "nodemon --watch tests/spec/test.js --exec 'npm test'", | ||
"browserify": "browserify -p browserify-derequire -e index.js -o lib/to-string-tag-x.js -u 'crypto' -s returnExports", | ||
"uglify": "uglifyjs lib/to-string-tag-x.js -o lib/to-string-tag-x.min.js --compress --keep-fnames --mangle --beautify ascii_only=true,beautify=false --source-map lib/to-string-tag-x.map" | ||
"uglify": "uglifyjs lib/to-string-tag-x.js -o lib/to-string-tag-x.min.js --support-ie8 --compress --keep-fnames --mangle --beautify ascii_only=true,beautify=false --source-map filename=lib/to-string-tag-x.map", | ||
"precommit": "npm run production", | ||
"prepush": "npm run production" | ||
} | ||
} |
@@ -29,3 +29,3 @@ <a name="module_to-string-tag-x"></a> | ||
**See**: [19.1.3.6 Object.prototype.toString ( )](http://www.ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
**Version**: 1.2.0 | ||
**Version**: 1.3.0 | ||
**Author**: Xotic750 <Xotic750@gmail.com> | ||
@@ -49,5 +49,6 @@ **License**: [MIT](<https://opensource.org/licenses/MIT>) | ||
```js | ||
var toStringTag = require('to-string-tag-x'); | ||
var o = new Object(); | ||
toStringTag(o); // returns '[object Object]' | ||
``` |
@@ -1,70 +0,58 @@ | ||
/* jslint maxlen:80, es6:true, white:true */ | ||
'use strict'; | ||
/* jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true, | ||
freeze:true, futurehostile:true, latedef:true, newcap:true, nocomma:true, | ||
nonbsp:true, singleGroups:true, strict:true, undef:true, unused:true, | ||
es3:false, esnext:true, plusplus:true, maxparams:1, maxdepth:2, | ||
maxstatements:12, maxcomplexity:4 */ | ||
var hasSymbol = typeof Symbol === 'function' && typeof Symbol('') === 'symbol', | ||
toStringTag; | ||
if (typeof module === 'object' && module.exports) { | ||
require('es5-shim'); | ||
require('es5-shim/es5-sham'); | ||
if (typeof JSON === 'undefined') { | ||
JSON = {}; | ||
} | ||
require('json3').runInContext(null, JSON); | ||
require('es6-shim'); | ||
var es7 = require('es7-shim'); | ||
Object.keys(es7).forEach(function (key) { | ||
var obj = es7[key]; | ||
if (typeof obj.shim === 'function') { | ||
obj.shim(); | ||
} | ||
}); | ||
toStringTag = require('../../index.js'); | ||
} else { | ||
toStringTag = returnExports; | ||
} | ||
/* eslint strict: 1, max-lines: 1, symbol-description: 1, max-nested-callbacks: 1, | ||
max-statements: 1 */ | ||
describe('toStringTag', function () { | ||
it('primitives', function () { | ||
expect(toStringTag()).toBe('[object Undefined]'); | ||
expect(toStringTag(undefined)).toBe('[object Undefined]'); | ||
expect(toStringTag(null)).toBe('[object Null]'); | ||
expect(toStringTag(1)).toBe('[object Number]'); | ||
expect(toStringTag(true)).toBe('[object Boolean]'); | ||
expect(toStringTag('x')).toBe('[object String]'); | ||
if (hasSymbol) { | ||
expect(toStringTag(Symbol(''))).toBe('[object Symbol]'); | ||
} | ||
}); | ||
/* global JSON:true, expect, module, require, describe, it, returnExports */ | ||
;(function () { // eslint-disable-line no-extra-semi | ||
'use strict'; | ||
var hasSymbol = typeof Symbol === 'function' && typeof Symbol() === 'symbol', | ||
toStringTag; | ||
if (typeof module === 'object' && module.exports) { | ||
require('es5-shim'); | ||
require('es5-shim/es5-sham'); | ||
if (typeof JSON === 'undefined') { | ||
JSON = {}; | ||
it('primitives as objects', function () { | ||
expect(toStringTag(Object(1))).toBe('[object Number]'); | ||
expect(toStringTag(Object(true))).toBe('[object Boolean]'); | ||
expect(toStringTag(Object('x'))).toBe('[object String]'); | ||
if (hasSymbol) { | ||
expect(toStringTag(Object(Symbol('')))).toBe('[object Symbol]'); | ||
} | ||
require('json3').runInContext(null, JSON); | ||
require('es6-shim'); | ||
var es7 = require('es7-shim'); | ||
Object.keys(es7).forEach(function (key) { | ||
var obj = es7[key]; | ||
if (typeof obj.shim === 'function') { | ||
obj.shim(); | ||
} | ||
}); | ||
toStringTag = require('../../index.js'); | ||
} else { | ||
toStringTag = returnExports; | ||
} | ||
}); | ||
describe('toStringTag', function () { | ||
it('primitives', function () { | ||
expect(toStringTag()).toBe('[object Undefined]'); | ||
expect(toStringTag(undefined)).toBe('[object Undefined]'); | ||
expect(toStringTag(null)).toBe('[object Null]'); | ||
expect(toStringTag(1)).toBe('[object Number]'); | ||
expect(toStringTag(true)).toBe('[object Boolean]'); | ||
expect(toStringTag('x')).toBe('[object String]'); | ||
if (hasSymbol) { | ||
expect(toStringTag(Symbol())).toBe('[object Symbol]'); | ||
} | ||
}); | ||
it('primitives as objects', function () { | ||
expect(toStringTag(Object(1))).toBe('[object Number]'); | ||
expect(toStringTag(Object(true))).toBe('[object Boolean]'); | ||
expect(toStringTag(Object('x'))).toBe('[object String]'); | ||
if (hasSymbol) { | ||
expect(toStringTag(Object(Symbol()))).toBe('[object Symbol]'); | ||
} | ||
}); | ||
it('common objects', function () { | ||
expect(toStringTag([1, 2, 3])).toBe('[object Array]'); | ||
expect(toStringTag({})).toBe('[object Object]'); | ||
expect(toStringTag(describe)).toBe('[object Function]'); | ||
expect(toStringTag(new Date())).toBe('[object Date]'); | ||
expect(toStringTag(new Error('x'))).toBe('[object Error]'); | ||
}); | ||
it('common objects', function () { | ||
expect(toStringTag([ | ||
1, | ||
2, | ||
3 | ||
])).toBe('[object Array]'); | ||
expect(toStringTag({})).toBe('[object Object]'); | ||
expect(toStringTag(describe)).toBe('[object Function]'); | ||
expect(toStringTag(new Date())).toBe('[object Date]'); | ||
expect(toStringTag(new Error('x'))).toBe('[object Error]'); | ||
}); | ||
}()); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22450
8.74%15
15.38%53
1.92%26
62.5%274
-9.87%