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

@beisen/common-func

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beisen/common-func - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

package-lock.json

3

index.js

@@ -9,3 +9,3 @@ /* eslint-disable */

import {clearToolTipDom, uid, judgeBrowser, judgeSys, getHeightLight, deepClone, transferData} from './src/index.js';
import {clearToolTipDom, uid, judgeBrowser, judgeSys, getHeightLight, deepClone, transferData, transFormat} from './src/index.js';

@@ -52,2 +52,3 @@ class App extends React.Component {

console.log(transferData([{id:1,pid:0},{id:2,pid:1}]))
console.log(transFormat('I {0} is {1} , a {0}', 1, 'wu'))
}

@@ -54,0 +55,0 @@

{
"name": "@beisen\/common-func",
"version": "0.0.14",
"version": "0.0.15",
"description": "CommonFunc",

@@ -5,0 +5,0 @@ "main": "lib\/index.js",

@@ -396,2 +396,21 @@ /* eslint-disable */

.replace(/&/g, '&');
}
}
/**
* 将字符串模板中的占位符替换为相应的变量
* @param {String} template 字符串模板, 变量key只能为数字
* @param {...any} variables 对应的变量
* 示例:(括号中的序号与翻译参数的顺序有关)
* console.log(transFormat("{0} is {1}", 1, 2));
* console.log(transFormat("{1} is {0}", 1, 2));
*/
export function transFormat(template, ...variables) {
const keys = template.match(/{\s*[0-9]+\s*}/g).map(str => {
return str.slice(1, str.length - 1).trim();
});
return keys.reduce(
(template, key) => template.replace(/{\s*[0-9]+\s*}/, variables[key]),
template
);
}
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