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

obj2str

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obj2str

object/array/function to string

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

obj2str

object(Object, Function, Array) to string

Downloads Version License

npm i -S obj2str
# or
yarn add obj2str

Usage

./test/index.js

const { obj2str } = require('obj2str')

// test object
const obj = {
  a: 1111,
  b: 'fsdfs,d\'fsd',
  b2: 'this\'s an object',
  b3: `This's a test object`,
  212: 'xxdfdf',
  c: {
    cc: '3333',
    c2: 'sdfsf"d"fsd',
    c3: {
      d: 2222
    }
  },
  k: null,
  f: undefined,
  g: 0,
  fn: function(str) {
    return str + 'hello world!'
  },
  fn2: (a) => a + 10,
  arr: [
    122,
    'xxx',
    {
      aa: 232434,
      bb: 'bb'
    },
    'dsfsdf'
  ]
}

const str = obj2str(obj, {
  // initSpaces: 4,
  // indentSpaces: 4,
  prefix: 'const obj = ',
  // doubleQuotes: true,
  // keyQuote: true
})

console.log(str)
node ./test/index.js

print

const obj = {
    212: 'xxdfdf',
    a: 1111,
    b: 'fsdfs,d\'fsd',
    b2: 'this\'s an object',
    b3: 'This\'s a test object',
    c: {
        cc: '3333',
        c2: 'sdfsf"d"fsd',
        c3: {
            d: 2222
        }
    },
    k: null,
    f: undefined,
    g: 0,
    fn: function(str) {
        return str + 'hello world!'
    },
    fn2: (a) => a + 10,
    arr: [
        122,
        'xxx',
        {
            aa: 232434,
            bb: 'bb'
        },
        'dsfsdf'
    ]
}

Methods

MethodParametersDescription
obj2str(o: any, options?: TypeOptions)return string
options
PropsTypeDescription
initSpacesnumberDefault indentation space for all lines, default: 0
indentSpacesnumberNumber of spaces to indent when formatting, default: 2
prefixstringConcatenation string prefix of the first line, default: ''
doubleQuotesbooleanWhether the string uses double quotes, default: false
keyQuotebooleanWhether the key of the object uses quote, default: false

Keywords

FAQs

Package last updated on 27 Dec 2020

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