Detalhes do pacote

@microsoft/fast-web-utilities

Microsoft472.5kMIT6.0.0

FAST web utilities

readme (leia-me)

FAST Web utilities

This package is a collection of utilities intended to be used for web projects.

Installation

npm i --save @microsoft/fast-web-utilities

Usage

DOM utilities

getKeyCode

The getKeyCode function gets the numeric key code associated with a keyboard event. This method is for use with DOM level 3 events that still use the deprecated keyCode property.

import { getKeyCode } from "@microsoft/fast-web-utilities";

handleKeyPress = (e) => {
    let keyCode = getKeyCode(e);

    // Do something based on keyCode value
}

HTML utilities

getClientRectWithMargin

The getClientRectWithMargin function gets the client bounding rectangle including any margins of an element.

import { getClientRectWithMargin } from "@microsoft/fast-web-utilities";

const itemWidth = getClientRectWithMargin(item).width;
const itemHeight = getClientRectWithMargin(item).height;

convertStylePropertyPixelsToNumber

The convertStylePropertyPixelsToNumber function will convert a property value from an elements computed style from pixels to a number value.

import { convertStylePropertyPixelsToNumber } from "@microsoft/fast-web-utilities";

const elementTopMargin = convertStylePropertyPixelsToNumber(style, "margin-top");

Key utilities

Key strings

Commonly used event.key values are available as individual exports. Additional key values will be added as needed.

import { keyEnter, keySpace } from "@microsoft/fast-web-utilities";

handleKeyPress = (e) => {
    switch (e.key) {
        case keySpace:
        case keyEnter:
            // Do something if key matches
            break;
    }
}

KeyCodes (enum)

Keycodes are deprecated and their use should be avoided. Use the individual string key values instead.

Localization utilities

Typescript enum

The Direction enum contains the ltr and rtl enum for use in a Typescript project.

import { Direction } from "@microsoft/fast-web-utilities";

let direction: Direction = Direction.ltr;

Number utilities

Limit

The limit function ensures that a value is between a min and max value. If the value is lower than min, min will be returned. If the value is greater than max, max will be retured.

import { limit } from "@microsoft/fast-web-utilities";
const incomingNumber; // 11 
const setNumberByLimit = limit(0, 10, incomingNumber); // returns 10

wrapInBounds

The wrapInBounds function keeps a given value within the bounds of a min and max value. If the value is larger than the max, the minimum value will be returned. If the value is smaller than the minimum, the maximum will be returned. Otherwise, the value is returned un-changed.

import { wrapInBounds } from "@microsoft/fast-web-utilities";
const slides; // 5
const index; // 5
const activeIndex = wrapInBounds(0, this.slides.length - 1, index) // returns 0

String utilities

Format

The format function builds a string from a format specifier and replacement parameters.

import { format } from "@microsoft/fast-web-utilities";

const formatterString = "View {0} {1}";

const newString = format(formatterString, "page", "4")); // "View page 4"

startsWith

The startsWith function checks to see if one string starts with another. The function is case sensitive.

import { startsWith } from "@microsoft/fast-web-utilities";

const matchIsFalse = startsWith("HelloWorld", "World"); // false
const matchIsTrue = startsWith("HelloWorld", "Hello"); // true

isNullOrWhiteSpace

The isNullOrWhiteSpace function determines if the specified string is undefined, null, empty, or whitespace. The function returns true if the value is undefined, null, empty, or whitespace, otherwise false.

import { isNullOrWhiteSpace } from "@microsoft/fast-web-utilities";

const myAnchor = document.querySelector("#id");
const checkWhitespace = isNullOrWhiteSpace(myAnchor.href);

pascalCase

The pascalCase function converts a string to Pascal Case

import { pascalCase } from "@microsoft/fast-web-utilities";

const hyphenatedToPascal = pascalCase("my-string");
const uppercaseToPascal = pascalCase("MY STRING");
const whitespaceToPascal = pascalCase(" my string ");

classNames

A utility for merging class names into a single string conditionally. Accepts any number of strings, functions that return strings and two index arrays where the first index is a string or function that returns a string, and the second index is a boolean.

import { classNames } from "@microsoft/fast-web-utilities";

// evaluates to "classOne classTwo classThree classFive"
const myJoinedClassNames = classNames(
    "classOne",
    () => "classTwo",
    ["classThree", true],
    ["classFour", false]
    [() => "classFive", true],
    [() => "classSix", false]
)

changelog (log de mudanças)

Change Log - @microsoft/fast-web-utilities

This log was last generated on Wed, 01 Jun 2022 17:53:14 GMT and should not be manually modified.

6.0.0

Wed, 01 Jun 2022 17:53:14 GMT

Major changes

  • remove deprecated keycodes and add additional keys (chhol@microsoft.com)

Patches

  • chore: fix broken build (roeisenb@microsoft.com)
  • Upgrade TypeScript (nicholasrice@users.noreply.github.com)

5.4.1

Wed, 04 May 2022 07:14:00 GMT

Patches

  • convert orientation enum to const object with corresponding type (chhol@microsoft.com)

5.4.0

Wed, 27 Apr 2022 07:21:09 GMT

Minor changes

  • update to typescript 4.6.2 and update ARIAMixin typings (chhol@microsoft.com)

Patches

  • Bump @microsoft/eslint-config-fast-dna to v2.1.0 (chhol@microsoft.com)

5.3.0

Sun, 17 Apr 2022 07:11:18 GMT

Minor changes

  • Instead of matchAll, used regex replace for pascalCase and added number to add to spinalCase (74849806+wannieman98@users.noreply.github.com)

5.2.0

Sun, 03 Apr 2022 07:12:01 GMT

Minor changes

  • Declare package as using ES modules (nicholasrice@users.noreply.github.com)

Patches

  • update exenv-es6 to 1.1.0 to ensure we lock to es module support (chhol@microsoft.com)

5.1.0

Tue, 25 Jan 2022 07:11:53 GMT

Minor changes

  • add findLastIndex and inRange functions to fast-web-utilities (john.kreitlow@microsoft.com)

5.0.2

Sun, 31 Oct 2021 07:17:45 GMT

Patches

  • update fast eslint package version (chhol@microsoft.com)

5.0.1

Wed, 13 Oct 2021 01:53:37 GMT

Patches

  • remove prefix from uniqueId function (john.kreitlow@microsoft.com)
  • remove throttle function (john.kreitlow@microsoft.com)
  • refactor: remove lodash-es as a dependency (connor@peet.io)

5.0.0

Sun, 19 Sep 2021 07:17:17 GMT

Major changes

  • add picker component (scomea@microsoft.com)

4.8.1

Sun, 12 Sep 2021 07:17:43 GMT

Patches

  • remove dependencies on keycode (scomea@microsoft.com)

4.8.0

Thu, 20 May 2021 07:24:10 GMT

Minor changes

  • add key string constants (john.kreitlow@microsoft.com)

4.7.3 (2021-02-08)

Note: Version bump only for package @microsoft/fast-web-utilities

4.7.2 (2021-02-08)

Note: Version bump only for package @microsoft/fast-web-utilities

4.7.1 (2021-01-30)

Bug Fixes

4.7.0 (2020-12-16)

Features

  • add standard event types as exported strings (#4161) (f2d9087)

4.6.1 (2020-10-14)

Note: Version bump only for package @microsoft/fast-web-utilities

4.6.0 (2020-07-14)

Features

  • update typescript version and remove utility types dependencies for react packages (#3422) (09d07b5)

4.5.2 (2020-06-26)

Note: Version bump only for package @microsoft/fast-web-utilities

4.5.0 (2020-05-18)

Features

4.4.5 (2020-04-29)

Note: Version bump only for package @microsoft/fast-web-utilities

4.4.4 (2020-04-27)

Note: Version bump only for package @microsoft/fast-web-utilities

4.4.3 (2020-04-22)

Note: Version bump only for package @microsoft/fast-web-utilities

4.4.2 (2020-04-10)

Note: Version bump only for package @microsoft/fast-web-utilities

4.4.1 (2020-03-13)

Note: Version bump only for package @microsoft/fast-web-utilities

4.4.0 (2019-12-05)

Bug Fixes

  • horizontal overflow rtl scroll behavior and add rtl scrollLeft utility (#2462) (0cc2da5)

Features

  • add new utilities for checking HTML elements (#2481) (15de67e)

4.3.7 (2019-11-19)

Note: Version bump only for package @microsoft/fast-web-utilities

4.3.6 (2019-11-07)

Bug Fixes

  • canUsedForcedColors should be called canUseForcedColors (#2403) (8904df4)

4.3.5 (2019-10-25)

Note: Version bump only for package @microsoft/fast-web-utilities

4.3.4 (2019-10-24)

Bug Fixes

  • canUsedForcedColors function is not isomorphic (#2378) (0c929c8)

4.3.3 (2019-10-17)

Bug Fixes

  • components are not showing correct high contrast colors in Edge chromium, removed hard code value, and add more examples (#2327) (125a85c)

4.3.2 (2019-09-17)

Bug Fixes

  • improve render performance of page, grid, and column components (#2241) (7936adc)

4.3.1 (2019-09-09)

Bug Fixes

  • exit focus visible utility immediately with false value if DOM is unavailable (#2223) (3fbd6c2)

4.3.0 (2019-08-22)

Features

  • adds classNames utility (#2163) (d6a872d)
  • export individual keycodes as named exports and unreference KeyCodes (327d806)

4.2.1 (2019-08-09)

Bug Fixes

  • establish no side effects in fast-web-utilities (a97741a)

4.2.0 (2019-05-31)

Features

  • add query string parser (#1784) (de20112)
  • show values as dash separated and send camelCase values in the CSS property editor callback (#1772) (93d6223)

4.1.0 (2019-04-23)

Features

4.0.1 (2019-04-09)

Note: Version bump only for package @microsoft/fast-web-utilities

4.0.0 (2019-03-25)

Bug Fixes

  • update to use esModuleInterop in the TypeScript configuration files (#1211) (2ec0644)

Features

  • remove fast-application-utilities package (#1455) (7ee34fa)

BREAKING CHANGES

  • removal of fast-application-utilities-package
  • This will affect how imports will be handled by consumers

3.1.3 (2019-03-19)

Bug Fixes

3.1.2 (2019-02-21)

Note: Version bump only for package @microsoft/fast-web-utilities

3.1.1 (2019-02-07)

Note: Version bump only for package @microsoft/fast-web-utilities

3.1.0 (2019-01-26)

Features

  • add direction and localization helpers to fast-web-utilities (#1330) (be0f603)

3.0.4 (2018-12-21)

Bug Fixes

2.2.0 (2018-09-11)

Features

2.1.0 (2018-08-29)

Bug Fixes

  • fast-web-utilities: fix an issue where getClientRectWithMargin threw an error in EDGE and IE strict modes due to readonly properties (#767) (d3fa002)

Features

  • update Lerna to ^3.0.0 (#795) (9ce9a56)
  • upgrade to TypeScript 3.0.0 (#793) (e203e86)
  • fast-components-react-base: add callback to horizontal overflow to return and object that informs scroll start and end (#797) (37975f3)
  • fast-components-react-base: add tabs component (#761) (24a5bb3)
  • paragraph: adds paragraph as a new MSFT component (#805) (8325d3f)

2.0.0-corrected (2018-08-03)

Features

  • utilities: add fast-web-utilities as a new package (#686) (a31a581)

2.1.0 (2018-08-29)

Bug Fixes

  • fast-web-utilities: fix an issue where getClientRectWithMargin threw an error in EDGE and IE strict modes due to readonly properties (#767) (d3fa002)

Features

  • update Lerna to ^3.0.0 (#795) (9ce9a56)
  • upgrade to TypeScript 3.0.0 (#793) (e203e86)
  • fast-components-react-base: add callback to horizontal overflow to return and object that informs scroll start and end (#797) (37975f3)
  • fast-components-react-base: add tabs component (#761) (24a5bb3)
  • paragraph: adds paragraph as a new MSFT component (#805) (8325d3f)

2.0.0 (2018-08-02)

Features

  • utilities: add fast-web-utilities as a new package (#686) (a31a581)

1.9.0 (2018-07-14)

Features

  • utilities: add fast-web-utilities as a new package (#686) (a31a581)