Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@1studio/utils

roberto404170BSD-3-Clause5.8.0

A collection of useful utilities.

utils, utilities, math, geometry, capitalizeFirstLetter, array sort, propTypes

readme

utils · travis build codecov coverage version commit type

A collection of useful utilities with Typescript type checking (since 5.0). - older version use Flow type checking.

Installation

Using npm:

$ npm i -S @1studio/utils

Transpiler for the Flow:

$ npm i -D @babel/core @babel/preset-env @babel/preset-typescript babel-loader

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-typescript"],
  "plugins": ["@babel/plugin-transform-runtime", "@babel/plugin-proposal-optional-chaining", "@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-class-properties"],
  "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.