@1studio/utils 中文文档教程

发布于 3年前 浏览 28 项目主页 更新于 3年前

utils · travis buildcodecov coverageversioncommittype

一组有用的实用程序,带有 Flow 类型检查(自 3.0 起)。

Installation

使用 npm:

$ npm i -S @1studio/utils

流的转译器:

$ npm i -D babel-loader babel-preset-env babel-preset-flow babel-minify babel-plugin-transform-class-properties babel-plugin-transform-object-rest-spread

.babelrc

{
  "presets": ["flow", "env"],
  "plugins": ["transform-class-properties", "transform-object-rest-spread"],
  "env": {
    "production": {
      "presets": ["babel-minify"]
    }
  }
}

webpack.config.js

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [/node_modules\/(?!@1studio)/],
        use: [{
          loader: 'babel-loader'
        }]
      },
    ],
  }

Manual

示例 (ES6):

import { getDistanceFromLatLonInKm } from '@1studio/utils/geometry';

const distance = getDistanceFromLatLonInKm(47.4925, 19.0513, 40.71448, -74.00598);
// Budapest <-> New York distance in km

示例(直接导入):

import checkPropTypes from '@1studio/utils/propType/checkPropTypes'

checkPropTypes('string', PropTypes.number);
// -> [errors]

示例(流):

// @flow

import clamp from '@1studio/utils/math/clamp';

clamp('a');
// => Flow errors

阅读更多

License

@1studio/utils 是 BSD 许可的

utils · travis buildcodecov coverageversioncommittype

A collection of useful utilities with Flow type checking (since 3.0).

Installation

Using npm:

$ npm i -S @1studio/utils

Transpiler for the Flow:

$ npm i -D babel-loader babel-preset-env babel-preset-flow babel-minify babel-plugin-transform-class-properties babel-plugin-transform-object-rest-spread

.babelrc

{
  "presets": ["flow", "env"],
  "plugins": ["transform-class-properties", "transform-object-rest-spread"],
  "env": {
    "production": {
      "presets": ["babel-minify"]
    }
  }
}

webpack.config.js

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [/node_modules\/(?!@1studio)/],
        use: [{
          loader: 'babel-loader'
        }]
      },
    ],
  }

Manual

Example (ES6):

import { getDistanceFromLatLonInKm } from '@1studio/utils/geometry';

const distance = getDistanceFromLatLonInKm(47.4925, 19.0513, 40.71448, -74.00598);
// Budapest <-> New York distance in km

Example (direct import):

import checkPropTypes from '@1studio/utils/propType/checkPropTypes'

checkPropTypes('string', PropTypes.number);
// -> [errors]

Example (Flow):

// @flow

import clamp from '@1studio/utils/math/clamp';

clamp('a');
// => Flow errors

Read more.

License

@1studio/utils is BSD licensed.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文