Socket
Socket
Sign inDemoInstall

any-size

Package Overview
Dependencies
5
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

30

index.d.ts
/**
* Get the size of any type of value.
* @param input The value to get the size of.
* @example
* ```
* const size = require("any-size");
*
* size("unicorns");
* //=> 8
*
* size([1, 2, 3, 4, 5]);
* //=> 5
*
* size({a: 1, b: 2, c: 3});
* //=> 3
* ```
Get the size of a value.
@param input The value to get the size of.
@example
```
const size = require("any-size")
size("unicorns")
//=> 8
size([1, 2, 3, 4, 5])
//=> 5
size({a: 1, b: 2, c: 3})
//=> 3
```
*/

@@ -18,0 +18,0 @@ declare function anySize(input: unknown): number

"use strict"
const { default: is } = require("@sindresorhus/is")
const is = require("@sindresorhus/is")
const stringLength = require("string-length")
module.exports = (input) => {
if (is.plainObject(input)) return Object.keys(input).length
if (is.arrayLike(input)) return input.length
if (is.string(input)) return stringLength(input)
if (is.number(input)) return input.toString().length
if (is.map(input) || is.set(input)) return input.size
module.exports = input => {
if (is.plainObject(input)) {
return Object.getOwnPropertyNames(input).length + Object.getOwnPropertySymbols(input).length
}
if (is.arrayLike(input)) {
return input.length
}
if (is.string(input)) {
return stringLength(input)
}
if (is.number(input)) {
return input.toString().length
}
if (is.map(input) || is.set(input)) { // eslint-disable-line unicorn/no-fn-reference-in-iterator
return input.size
}
return 0
}
{
"name": "any-size",
"version": "1.0.1",
"version": "1.0.2",
"description": "Get the size of any type of value.",

@@ -18,3 +18,3 @@ "repository": "https://github.com/Richienb/any-size.git",

"lint": "xo",
"test": "yarn lint && ava"
"test": "xo && ava"
},

@@ -35,16 +35,13 @@ "keywords": [

"dependencies": {
"@sindresorhus/is": "^2.1.0",
"string-length": "^4.0.0"
"@sindresorhus/is": "^3.1.2",
"string-length": "^4.0.1"
},
"devDependencies": {
"ava": "^3.0.0",
"eslint-config-richienb": "^0.3.0",
"xo": "^0.25.3"
"ava": "^3.13.0",
"eslint-config-richienb": "^0.5.0",
"xo": "^0.33.1"
},
"resolutions": {
"eslint": "^6.8.0"
},
"xo": {
"extends": "richienb/node"
"extends": "richienb"
}
}
# Any Size [![Travis CI Build Status](https://img.shields.io/travis/com/Richienb/any-size/master.svg?style=for-the-badge)](https://travis-ci.com/Richienb/any-size)
Get the size of any type of value. Supports objects, array-like objects, strings with ansi stripping and unicode normalization, numbers, maps and sets.
Get the size of a value. Supports objects, array-like objects, strings (with ansi stripping and unicode character recognition), numbers, maps and sets.

@@ -16,11 +16,11 @@ [![NPM Badge](https://nodei.co/npm/any-size.png)](https://npmjs.com/package/any-size)

```js
const size = require("any-size");
const size = require("any-size")
size("unicorns");
size("unicorns")
//=> 8
size([1, 2, 3, 4, 5]);
size([1, 2, 3, 4, 5])
//=> 5
size({a: 1, b: 2, c: 3});
size({a: 1, b: 2, c: 3})
//=> 3

@@ -27,0 +27,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc