Socket
Socket
Sign inDemoInstall

multisplice

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

multisplice

easily splice a string multiple times, using offsets into the original string


Version published
Weekly downloads
8.9K
increased by2.3%
Maintainers
1
Weekly downloads
 
Created
Source

multisplice

easily splice a string multiple times, using offsets into the original string

npm travis standard

Install

npm install multisplice

Usage

Renaming identifiers in Javascript code:

var multisplice = require('./')
var dedent = require('dedent')
var astw = require('astw')

var src = dedent`
  function beep (boop) {
    boop *= baz
    console.log(boop)
  }
  var baz = 10
  beep(17)
`

var splicer = multisplice(src)
var renames = {}
var nextName = 'a'.charCodeAt()
astw(src)(function (node) {
  if (node.type === 'Identifier') {
    if (!renames[node.name]) renames[node.name] = String.fromCharCode(nextName++)

    splicer.splice(node.start, node.end, renames[node.name])
  }
})

console.log(splicer.toString())
function a (b) {
  b *= c
  d.e(b)
}
var c = 10
a(17)

API

var s = multisplice(string)

Create a string splicer instance. This instance will splice things into string.

s.splice(start, end, value)

Replace the slice from indices start to end in the original string with value.

s.slice(start, end)

Get a part of the spliced string, using indices start to end from the original string.

s.toString()

Get the full spliced string (.slice(0)).

License

Apache-2.0

Keywords

FAQs

Package last updated on 21 Feb 2018

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