添加数学便利工具扩展 - #323
Open
3DJonas wants to merge 4 commits into
Open
Conversation
Author
|
增加更多代码!代码数量已经突破150+! |
Author
请求审核通过!不会卡作品!不要有问题!(这只是个便利扩展QWQ)
|
Closed
Author
|
你好,这个 PR 是为了在素材集市发布扩展。请问审核进度如何?有需要我修改的地方吗?谢谢! |
|
数学功能原版scratch和七星松的数据分析扩展中大部分能实现,字符串功能也是七星松的字符串处理有 |
|
数组功能七星松的变量数组扩展也有 |
|
而且强烈不推荐使用中文作为函数和i18n key,显得很“初学者” |
|
同时这是官方approved的扩展库,扩展集市的审核不需要在这里pr |
| '四舍五入': 'round [数] to [小数位数] decimals', | ||
| '最大值': 'max [数1] and [数2]', | ||
| '最小值': 'min [数1] and [数2]', | ||
| '拼接': 'concat [文本1] and [文本2]', |
| '分割': 'split [文本] by [分隔符] (JSON)', | ||
| '分割转列表': 'split [文本] by [分隔符] (JSON)', | ||
| '分割行': 'split lines [文本] (JSON)', | ||
| '包含': '[文本] contains [子文本]?', |
Comment on lines
+277
to
+396
| this['平方'] = this._平方.bind(this); | ||
| this['平方根'] = this._平方根.bind(this); | ||
| this['绝对值'] = this._绝对值.bind(this); | ||
| this['取余'] = this._取余.bind(this); | ||
| this['幂运算'] = this._幂运算.bind(this); | ||
| this['立方'] = this._立方.bind(this); | ||
| this['立方根'] = this._立方根.bind(this); | ||
| this['正弦'] = this._正弦.bind(this); | ||
| this['余弦'] = this._余弦.bind(this); | ||
| this['正切'] = this._正切.bind(this); | ||
| this['对数'] = this._对数.bind(this); | ||
| this['取整'] = this._取整.bind(this); | ||
| this['向上取整'] = this._向上取整.bind(this); | ||
| this['四舍五入'] = this._四舍五入.bind(this); | ||
| this['最大值'] = this._最大值.bind(this); | ||
| this['最小值'] = this._最小值.bind(this); | ||
| this['拼接'] = this._拼接.bind(this); | ||
| this['长度'] = this._长度.bind(this); | ||
| this['截取'] = this._截取.bind(this); | ||
| this['替换'] = this._替换.bind(this); | ||
| this['替换一次'] = this._替换一次.bind(this); | ||
| this['查找'] = this._查找.bind(this); | ||
| this['反向查找'] = this._反向查找.bind(this); | ||
| this['出现次数'] = this._出现次数.bind(this); | ||
| this['转大写'] = this._转大写.bind(this); | ||
| this['转小写'] = this._转小写.bind(this); | ||
| this['大小写互换'] = this._大小写互换.bind(this); | ||
| this['首字母大写'] = this._首字母大写.bind(this); | ||
| this['单词首字母大写'] = this._单词首字母大写.bind(this); | ||
| this['去首尾空格'] = this._去首尾空格.bind(this); | ||
| this['去左空格'] = this._去左空格.bind(this); | ||
| this['去右空格'] = this._去右空格.bind(this); | ||
| this['去所有空格'] = this._去所有空格.bind(this); | ||
| this['去指定字符'] = this._去指定字符.bind(this); | ||
| this['分割'] = this._分割.bind(this); | ||
| this['分割转列表'] = this._分割转列表.bind(this); | ||
| this['分割行'] = this._分割行.bind(this); | ||
| this['包含'] = this._包含.bind(this); | ||
| this['开头是'] = this._开头是.bind(this); | ||
| this['结尾是'] = this._结尾是.bind(this); | ||
| this['是全数字'] = this._是全数字.bind(this); | ||
| this['是全字母'] = this._是全字母.bind(this); | ||
| this['是全大写'] = this._是全大写.bind(this); | ||
| this['是全小写'] = this._是全小写.bind(this); | ||
| this['是全空格'] = this._是全空格.bind(this); | ||
| this['反转'] = this._反转.bind(this); | ||
| this['重复'] = this._重复.bind(this); | ||
| this['截取前'] = this._截取前.bind(this); | ||
| this['截取后'] = this._截取后.bind(this); | ||
| this['左对齐'] = this._左对齐.bind(this); | ||
| this['右对齐'] = this._右对齐.bind(this); | ||
| this['居中对齐'] = this._居中对齐.bind(this); | ||
| this['提取数字'] = this._提取数字.bind(this); | ||
| this['提取字母'] = this._提取字母.bind(this); | ||
| this['提取中文'] = this._提取中文.bind(this); | ||
| this['比较文本'] = this._比较文本.bind(this); | ||
| this['比较文本不区分大小写'] = this._比较文本不区分大小写.bind(this); | ||
| this['替换多行'] = this._替换多行.bind(this); | ||
| this['去除换行'] = this._去除换行.bind(this); | ||
| this['MD5加密'] = this._MD5加密.bind(this); | ||
| this['Base64编码'] = this._Base64编码.bind(this); | ||
| this['Base64解码'] = this._Base64解码.bind(this); | ||
| this['创建数组'] = this._创建数组.bind(this); | ||
| this['创建数组转列表'] = this._创建数组转列表.bind(this); | ||
| this['数组长度'] = this._数组长度.bind(this); | ||
| this['添加元素'] = this._添加元素.bind(this); | ||
| this['插入元素'] = this._插入元素.bind(this); | ||
| this['删除元素'] = this._删除元素.bind(this); | ||
| this['删除指定元素'] = this._删除指定元素.bind(this); | ||
| this['获取元素'] = this._获取元素.bind(this); | ||
| this['获取第一个元素'] = this._获取第一个元素.bind(this); | ||
| this['获取最后一个元素'] = this._获取最后一个元素.bind(this); | ||
| this['修改元素'] = this._修改元素.bind(this); | ||
| this['查找元素'] = this._查找元素.bind(this); | ||
| this['数组包含'] = this._数组包含.bind(this); | ||
| this['反转数组'] = this._反转数组.bind(this); | ||
| this['排序数组'] = this._排序数组.bind(this); | ||
| this['降序排序数组'] = this._降序排序数组.bind(this); | ||
| this['拼接数组'] = this._拼接数组.bind(this); | ||
| this['清空数组'] = this._清空数组.bind(this); | ||
| this['连接数组'] = this._连接数组.bind(this); | ||
| this['数组去重'] = this._数组去重.bind(this); | ||
| this['数组切片'] = this._数组切片.bind(this); | ||
| this['勾股求弦'] = this._勾股求弦.bind(this); | ||
| this['弦勾求股'] = this._弦勾求股.bind(this); | ||
| this['弦股求勾'] = this._弦股求勾.bind(this); | ||
| this['直角三角形面积'] = this._直角三角形面积.bind(this); | ||
| this['三角形周长'] = this._三角形周长.bind(this); | ||
| this['三角形面积'] = this._三角形面积.bind(this); | ||
| this['圆周长'] = this._圆周长.bind(this); | ||
| this['圆面积'] = this._圆面积.bind(this); | ||
| this['矩形面积'] = this._矩形面积.bind(this); | ||
| this['矩形周长'] = this._矩形周长.bind(this); | ||
| this['正方形面积'] = this._正方形面积.bind(this); | ||
| this['正方形周长'] = this._正方形周长.bind(this); | ||
| this['数组求和'] = this._数组求和.bind(this); | ||
| this['数组平均值'] = this._数组平均值.bind(this); | ||
| this['数组最大值'] = this._数组最大值.bind(this); | ||
| this['数组最小值'] = this._数组最小值.bind(this); | ||
| this['数组中位数'] = this._数组中位数.bind(this); | ||
| this['随机整数'] = this._随机整数.bind(this); | ||
| this['随机小数'] = this._随机小数.bind(this); | ||
| this['随机选择'] = this._随机选择.bind(this); | ||
| this['随机打乱数组'] = this._随机打乱数组.bind(this); | ||
| this['随机布尔'] = this._随机布尔.bind(this); | ||
| this['随机字母'] = this._随机字母.bind(this); | ||
| this['随机数字'] = this._随机数字.bind(this); | ||
| this['随机字符串'] = this._随机字符串.bind(this); | ||
| this['是偶数'] = this._是偶数.bind(this); | ||
| this['是奇数'] = this._是奇数.bind(this); | ||
| this['是正数'] = this._是正数.bind(this); | ||
| this['是负数'] = this._是负数.bind(this); | ||
| this['是零'] = this._是零.bind(this); | ||
| this['是直角三角形'] = this._是直角三角形.bind(this); | ||
| this['是等腰三角形'] = this._是等腰三角形.bind(this); | ||
| this['是等边三角形'] = this._是等边三角形.bind(this); | ||
| this['是数组'] = this._是数组.bind(this); | ||
| this['是文本'] = this._是文本.bind(this); | ||
| this['是数字'] = this._是数字.bind(this); | ||
| this['是布尔'] = this._是布尔.bind(this); |
There was a problem hiding this comment.
没必要bind,1.你的func没有用this
2.gandi调用func时自己就有bind
Comment on lines
+401
to
+404
| _平方(args) { const x = toNumber(args.数); return isNaN(x) ? NaN : x*x; } | ||
| _平方根(args) { const x = toNumber(args.数); return (isNaN(x) || x < 0) ? NaN : Math.sqrt(x); } | ||
| _绝对值(args) { const x = toNumber(args.数); return isNaN(x) ? NaN : Math.abs(x); } | ||
| _取余(args) { const a = toNumber(args.数), b = toNumber(args.除数); return (isNaN(a) || isNaN(b) || b === 0) ? NaN : ((a % b) + b) % b; } |
Comment on lines
+412
to
+414
| _取整(args) { const x = toNumber(args.数); return isNaN(x) ? NaN : Math.floor(x); } | ||
| _向上取整(args) { const x = toNumber(args.数); return isNaN(x) ? NaN : Math.ceil(x); } | ||
| _四舍五入(args) { const x = toNumber(args.数), d = Math.floor(toNumber(args.小数位数)); if (isNaN(x) || isNaN(d) || d < 0) return NaN; const factor = Math.pow(10, d); return Math.round(x * factor) / factor; } |
Comment on lines
+408
to
+410
| _正弦(args) { const deg = toNumber(args.角度); return isNaN(deg) ? NaN : Math.sin(deg * Math.PI / 180); } | ||
| _余弦(args) { const deg = toNumber(args.角度); return isNaN(deg) ? NaN : Math.cos(deg * Math.PI / 180); } | ||
| _正切(args) { const deg = toNumber(args.角度); return isNaN(deg) ? NaN : Math.tan(deg * Math.PI / 180); } |
| const hash = require('crypto').createHash('md5').update(s).digest('hex'); | ||
| return hash; | ||
| } catch(e) { | ||
| // 降级方案:使用第三方MD5简单实现(这里省略,若需要可加入一个纯JS MD5) |
Contributor
|
为啥不直接发扩展集市呢,官方扩展库原则上不再添加了新扩展了
… On Jul 2, 2026, at 12:28, BenPaoDeXiaoZhi ***@***.***> wrote:
@BenPaoDeXiaoZhi commented on this pull request.
In extensions/math-utils/math-utils.js <#323 (comment)>:
> + _居中对齐(args) { const s = toString(args.文本), len = Math.floor(toNumber(args.长度)), fill = toString(args.填充) || ' '; return s.padStart((len - s.length) / 2 + s.length, fill[0] || ' ').padEnd(len, fill[0] || ' '); }
+ _提取数字(args) { return (toString(args.文本).match(/\d+/g) || []).join(''); }
+ _提取字母(args) { return (toString(args.文本).match(/[a-zA-Z]+/g) || []).join(''); }
+ _提取中文(args) { return (toString(args.文本).match(/[\u4e00-\u9fa5]+/g) || []).join(''); }
+ _比较文本(args) { return toString(args.文本1) === toString(args.文本2); }
+ _比较文本不区分大小写(args) { return toString(args.文本1).toLowerCase() === toString(args.文本2).toLowerCase(); }
+ _替换多行(args) { return toString(args.文本).replace(new RegExp(toString(args.旧), 'g'), toString(args.新)); }
+ _去除换行(args) { return toString(args.文本).replace(/[\r\n]+/g, ''); }
+ _MD5加密(args) {
+ // 浏览器环境使用SubtleCrypto或简单实现(此版本使用内置crypto,但Scratch沙盒可能无crypto,若报错请删除此积木)
+ try {
+ const s = toString(args.文本);
+ const hash = require('crypto').createHash('md5').update(s).digest('hex');
+ return hash;
+ } catch(e) {
+ // 降级方案:使用第三方MD5简单实现(这里省略,若需要可加入一个纯JS MD5)
重复功能很多,估计不会通过
—
Reply to this email directly, view it on GitHub <#323?email_source=notifications&email_token=AAJQIUHMXI34DS4M42Z32BT5CXQGDA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINRRGQ2TCMZSGQY2M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussion_r3510467807>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAJQIUFX7MVJU2IT2YZMU235CXQGDAVCNFSNUABFKJSXA33TNF2G64TZHM2DOMBVGQ4DSNJYHNEXG43VMU5TINRZG4ZDQMZRG43KC5QC>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/AAJQIUFXNSMLT5JTVGGBKET5CXQGDA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINRRGQ2TCMZSGQY2M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/AAJQIUCNLO2QOTRFCD7B2WT5CXQGDA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINRRGQ2TCMZSGQY2M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today!
You are receiving this because you are subscribed to this thread.
|
Author
|
okok知道了,正在改
温暖月光
***@***.***
原始邮件
发件人:BenPaoDeXiaoZhi ***@***.***>
发件时间:2026年7月2日 12:28
收件人:Gandi-IDE/custom-extension ***@***.***>
抄送:3DJonas ***@***.***>, Author ***@***.***>
主题:Re: [Gandi-IDE/custom-extension] 添加数学便利工具扩展 (PR #323)
@BenPaoDeXiaoZhi commented on this pull request.
In extensions/math-utils/math-utils.js:
> + _居中对齐(args) { const s = toString(args.文本), len = Math.floor(toNumber(args.长度)), fill = toString(args.填充) || ' '; return s.padStart((len - s.length) / 2 + s.length, fill[0] || ' ').padEnd(len, fill[0] || ' '); } + _提取数字(args) { return (toString(args.文本).match(/\d+/g) || []).join(''); } + _提取字母(args) { return (toString(args.文本).match(/[a-zA-Z]+/g) || []).join(''); } + _提取中文(args) { return (toString(args.文本).match(/[\u4e00-\u9fa5]+/g) || []).join(''); } + _比较文本(args) { return toString(args.文本1) === toString(args.文本2); } + _比较文本不区分大小写(args) { return toString(args.文本1).toLowerCase() === toString(args.文本2).toLowerCase(); } + _替换多行(args) { return toString(args.文本).replace(new RegExp(toString(args.旧), 'g'), toString(args.新)); } + _去除换行(args) { return toString(args.文本).replace(/[\r\n]+/g, ''); } + _MD5加密(args) { + // 浏览器环境使用SubtleCrypto或简单实现(此版本使用内置crypto,但Scratch沙盒可能无crypto,若报错请删除此积木) + try { + const s = toString(args.文本); + const hash = require('crypto').createHash('md5').update(s).digest('hex'); + return hash; + } catch(e) { + // 降级方案:使用第三方MD5简单实现(这里省略,若需要可加入一个纯JS MD5)
重复功能很多,估计不会通过
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you authored the thread.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
提供数学计算、字符串处理、数组操作、几何计算等100多个积木