New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

surround-contents

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

surround-contents

原生 Range.surroundContents 的增强版,支持跨节点包裹。

latest
Source
npmnpm
Version
0.0.7
Version published
Maintainers
1
Created
Source

Range.surroundContents()的加强版

用来解决原生surroundContents,无法跨边界用新节点包裹指定Range的问题。

用法:

import surroundContents from 'surround-contents'

surroundContents(getSelection().getRangeAt(0), () => {
    const span = document.createElement('span')
    span.style.background = 'red'
    return span
})

参数

参数名类型描述
rangeAtRange必填。需要处理的 Range 对象。默认值:null
newDomMethodFunction选填。创建新节点的函数。默认值见下方代码块。每次需新建节点,不能复用。

默认值示例:

() => document.createElement('span')

安装

npm install surround-contents
# 或
yarn add surround-contents

贡献

欢迎提 issue 或 PR!

License

MIT

变更日志

详见 CHANGELOG.md

Keywords

surroundContents

FAQs

Package last updated on 27 Jun 2025

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