Skip to content

Instantly share code, notes, and snippets.

View wulucxy's full-sized avatar

qingtong wulucxy

View GitHub Profile
@wulucxy
wulucxy / If.js
Last active July 9, 2018 01:12
React IF 条件判断组件 #react
import React from 'react'
import PropTypes from 'prop-types'
class IF extends React.PureComponent {
static defaultProps = {
fallback: null
}
static propTypes = {
children: PropTypes.oneOfType([PropTypes.element, PropTypes.string])
.isRequired,
@wulucxy
wulucxy / util-array.md
Last active July 9, 2018 01:17
Array #snippet

Array

removeArrayItem

删除数组中指定索引的字段

const removeArrayItem = (arr, i) => {
  return ([
    ...arr.slice(0, i),
@wulucxy
wulucxy / url.md
Created July 9, 2018 01:18
Url #snippet

Url

composeUrl

合并 url

import qs from 'qs'

const composeUrl = (url, params) => {
@wulucxy
wulucxy / String.md
Created July 9, 2018 01:20
String #snippet

String

compareStrings

对比字符串是否相等

const compareStrings = (a, b, ignoreCase) => {
  a = String(a)
 b = String(b)
@wulucxy
wulucxy / Http.md
Created July 9, 2018 01:20
Http #snippet

Http

getHeader

获取头字段 大小写不敏感

const getHeader = (header, field) => {
  if (!header) {
 return ''
@wulucxy
wulucxy / Number.md
Last active July 9, 2018 02:31
Number #snippet

Number

formatNumberByThousand

将数字修改为千分位计数方式

const formatNumberByThousand = (value) => {
  return value && value.toLocaleString('en-us')
}
@wulucxy
wulucxy / Dom.md
Created July 9, 2018 01:22
Dom #snippet

DOM

hasClass

检测对象是否有指定的class

const hasClass = (el, cls) => {
  if (!el || !cls) return false
  if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.')
if (componentHasNoState) {
 return itsStatelessComponent()
} else if (componentHasSimplePropsState && propsHasNoNestedObjects) {
 return itsPureComponent()
} else {
 return itsComponent()
}
@wulucxy
wulucxy / refs.md
Created July 9, 2018 01:28
组件引用 #React

组件refs如何获取到dom元素

  • innerRef
export default function LinePath ({innerRef}) {
  return (
    <g>
      <path
 ref={innerRef}
@wulucxy
wulucxy / npm.md
Last active November 7, 2018 14:43
npm

首先,通过npm_package_前缀,npm 脚本可以拿到package.json里面的字段。比如,下面是一个package.json。

{ "name": "foo", "version": "1.2.5", "scripts": { "view": "node view.js" } }