Topwo博客
首页
博客
项目
华氏温度和摄氏温度互转
JavaScript
2021-11-09
```javascript /** * 华氏温度(32℉) 转化为摄氏温度(0℃) */ function f2c(s) { return s.replace(/(\d+(\.\d*)?)℉/g, function($0,$1,$2) { return (($1-32) * 5/9) + '℃'; }); } ```
阅读原文>>
JS驼峰属性和下划线属性互转
JavaScript
2021-11-09
> 最近在写node端,遇到数据库直接返回数据带下划线的情况 > 需要把下划线属性换成驼峰属性 > 入库时驼峰属性需要换成下划线属性 ## 1. 字符串,将下划线替换为小驼峰 ### 方法1: ```javascript const strUnderlineToSmallCamel = (val, char = '_') => { const arr = val.split(''); const index = arr.indexOf(char);
阅读原文>>
js正则判断一个字符串里必须包含大写字母,小写字母,数字,特殊字符
JavaScript
2021-11-09
```javascript /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[#@*&.]).*$/ ```
阅读原文>>
Java驼峰风格、下划线风格互转
Java
2021-11-09
```java /** * 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br> * 例如:HelloWorld->HELLO_WORLD * @param name 转换前的驼峰式命名的字符串 * @return 转换后下划线大写方式命名的字符串 */ public static String underscoreName(String name) { StringBuilder result = new StringBuilder(); if (name != null && name.length() > 0) {
阅读原文>>
Promise实现原理,便于理解Promise
JavaScript
2021-11-09
```javascript /** * 自定义 Promise 实现,遵循 Promise/A+ 规范 * 包含 Promise 的核心功能和常用静态方法 */ class MyPromise { /** * 构造函数,初始化 Promise 状态 * @param {Function} executor - 执行器函数,接收 resolve 和 reject 两个参数 */
阅读原文>>
JS中的扩展运算符(...)和剩余运算符(...)
JavaScript
2021-11-09
## 一、概念 在JS中,扩展运算符(spread)是三个点 (...) ,剩余运算符(rest)也是三个点 (...) ## 二、扩展运算符 ### (1)基本使用:扩展运算符的主要作用是将一个数组转为用逗号分隔的参数序列,它好比 rest 的逆运算 ```javascript //传递数据代替多个字符串的形式 function test(a,b,c){ console.log(a); // 1 console.log(b); // 2
阅读原文>>
koa接收post请求参数(通过koa-bodyparser)
JavaScript
2021-11-09
> koa-bodyparser中间件地址:[https://www.npmjs.com/package/koa-bodyparser](https://www.npmjs.com/package/koa-bodyparser) ## 1. 安装koa-bodyparser > cnpm i koa-bodyparser --save ## 2. 引入bodyparser模块 ```javascript const bodyParser = require('koa-bodyparser'); app.use(bodyParser()); ```
阅读原文>>
koa接受get请求参数(Request)
JavaScript
2021-11-09
* 示例请求url如下: http://localhost:3000/?color=blue&size=small ## 1. 获取请求 URL. >ctx.url || ctx.request.url /?color=blue&size=small ## 2. 获取请求原始URL。 >ctx.originalUrl || ctx.request.originalUrl /?color=blue&size=small
阅读原文>>
koa获取请求参数的三种方法
JavaScript
2021-11-09
## ctx.request.body: 需要npm安装koa-bodyparser中间件,获取post请求参数; ## ctx.params: 获取动态路径参数; ```javascript router.get('/package/:aid/:cid', async (ctx)=>{ //获取动态路由的传值 console.log(ctx.params); //{ aid: '123', cid: '456' } ctx.body="详情";
阅读原文>>
socket.io的socket.emit和io.emit区别
JavaScript
2021-11-05
* `socket.emit('message', "this is a test");` //sending to sender-client only * `socket.broadcast.emit('message', "this is a test");` //sending to all clients except sender * `socket.broadcast.to('game').emit('message', 'nice game');` //sending to all clients in 'game' room(channel) except sender * `socket.to('game').emit('message', 'enjoy the game');` //sending to sender client, only if they are in 'game' room(channel) * `socket.broadcast.to(socketid).emit('message', 'for your eyes only');` //sending to individual socketid * `io.emit('message', "this is a test");` //sending to all clients, include sender * `io.in('game').emit('message', 'cool game');` //sending to all clients in 'game' room(channel), include sender * `io.of('myNamespace').emit('message', 'gg');` //sending to all clients in namespace 'myNamespace', include sender * `socket.emit();` //sending to sender-client only
阅读原文>>
首页
上一页
21
下一页
尾页
文章推荐
华氏温度和摄氏温度互转
2021-11-09
JS驼峰属性和下划线属性互转
2021-11-09
js正则判断一个字符串里必须包含大写字母,小写字母,数字,特殊字符
2021-11-09
Java驼峰风格、下划线风格互转
2021-11-09
Promise实现原理,便于理解Promise
2021-11-09