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

flatten-deep-and-glue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatten-deep-and-glue

Flattens deeply nested arrays and objects and transforms them to separated string by default.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Introduction

flattenDeepAndGlue is a small function that expands objects or arrays of strings to separated strings,
by default. The reason I made this module us to easily use Laravel's validation messages with sweetAlert2 or toastr. If you don't want to create a separated toast for each error, the plugin creates a string with rows for each error message value.

How to use

The examples use ES2015 syntax

With module loader

import flatten from 'flatten-deep-with-glue'

const 
  messageToTransform = { name: 'Name is required', email: 'Email is required' },
  transformedMessage = flatten(messageToTransform) // 'Name is required <br/>Email is required'

In the Browser

<script src="path/to/flattenDeepAndGlue.js"></script>

<script>
    var 
        messageToTransform = { name: 'Name is required', email: 'Email is required' },
        transformedMessage = flattenDeepAndGlue(messageToTransform) // 'Name is required <br/>Email is required'
</script>

You could also pass deeply nested objects like [5, 'error', { name: 'Required' }] and will get 5,error,Required. The second parameter is the separator so flatten(myMessage, ',') would output a comma separated list of myMessage's values. Passing false to the separator param will just return a the flattened array without transforming it into a string

Keywords

FAQs

Package last updated on 31 Oct 2017

Did you know?

Socket

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.

Install

Related posts

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