0.1.2 • Published 4 years ago

obj2str v0.1.2

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

obj2str

object(Object, Function, Array) to string

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
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago