Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-fns

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-fns - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

48

index.js

@@ -0,1 +1,9 @@

// Helper function to check if an object is empty (including arrays)
const isEmpty = (obj) => {
if (obj == null) return true
if (Array.isArray(obj)) return obj.length === 0
if (typeof obj === 'object') return Object.keys(obj).length === 0
return false
}
///////////////////////////////////////////////////////////////////////////////

@@ -98,15 +106,27 @@ // MAIN

iterable = Array.from({ length: collection }, (_, i) => i)
} else if (Array.isArray(collection)) {
} else {
iterable = collection
} else if (typeof collection === 'object' && collection !== null) {
iterable = Object.entries(collection)
} else {
return '' // Return empty string for invalid inputs
}
return iterable.reduce((html, item, index) => {
const [value, key] = Array.isArray(collection) ? [item, index] : item
const returnedFromCallback = callback(value, key)
return returnedFromCallback ? html + returnedFromCallback : html
}, '')
let html = ''
if (Array.isArray(iterable)) {
for (let i = 0; i < iterable.length; i++) {
const returnedFromCallback = callback(iterable[i], i)
if (returnedFromCallback) {
html += returnedFromCallback
}
}
} else if (typeof iterable === 'object' && iterable !== null) {
for (const key in iterable) {
if (Object.prototype.hasOwnProperty.call(iterable, key)) {
const returnedFromCallback = callback(iterable[key], key)
if (returnedFromCallback) {
html += returnedFromCallback
}
}
}
}
return html
}

@@ -133,10 +153,2 @@

// Helper function to check if an object is empty (including arrays)
const isEmpty = (obj) => {
if (obj == null) return true
if (Array.isArray(obj)) return obj.length === 0
if (typeof obj === 'object') return Object.keys(obj).length === 0
return false
}
if (

@@ -143,0 +155,0 @@ evaluatedCondition === false ||

{
"name": "html-fns",
"version": "1.2.1",
"version": "1.2.2",
"description": "Set of convinient pure functions to generate HTML on server-side via tagged template literals.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc