5.0.0-alpha.0 • Published 9 months ago

@ndla/util v5.0.0-alpha.0

Weekly downloads
219
License
GPL-3.0
Repository
github
Last release
9 months ago

ndla-util

Collection of util functions used by NDLA

Installation

yarn add @ndla/util
npm install @ndla/util

Usage

import uuid from "@ndla/util/uuid";

const unique = uuid();
console.log(unique); // > 'b56f476a-bc77-49cd-8be1-9d9aa93117ca'

or

import { uuid } from "@ndla/util";

const unique = uuid();
console.log(unique); // > '0ada1b02-5888-43fd-9fbc-ccdbb69528f2'

API(functions)

uuid()

Get an unique identifier.

const unique = util.uuid();
console.log(unique); // > '95821b33-694c-40e8-824c-d115a046d009'

getComponentName()

Get component name of a React component. Useful in HOCs.

import { getComponentName } from '@ndla/util';

const withHOC = (WrappedComponent) => {
  class NameOfHoc extends Component {
    ....
    render() {
      return createElement(WrappedComponent, nextProps);
    }
  }

  NameOfHoc.displayName = `NameOfHoc(${getComponentName(WrappedComponent)})`;
  return hoistNonReactStatics(NameOfHoc, WrappedComponent);
};

export default withStateHandler;

copyTextToClipboard(text)

Copies text to clipboard by (1) creating a hidden textarea with the provided text, (2) selects the text, (3) runs document.execCommand('copy').

import { copyTextToClipboard } from "@ndla/util";
copyTextToClipboard("Hello world!");

tagsI18N(object, locale, withFallback, preferdLocales)

Finds translation for a specific language in an array named tags from an object. Prefered locales is a fallback option if the given locale translation does not exist. If no preferdLocales is defined, it is default sat to ['nb', 'nn', 'en'].

import { tagsI18N } from "@ndla/util";
tagsI18N(object, "nb", false, ["nb", "nn", "en"]);
5.0.0-alpha.0

9 months ago

4.1.0

12 months ago

4.0.4

1 year ago

4.0.3

2 years ago

3.1.14

2 years ago

3.1.15

2 years ago

3.2.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.1.13

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.10

2 years ago

3.1.9

3 years ago

3.1.8

3 years ago

3.1.1

3 years ago

3.1.7

3 years ago

3.1.6

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

2.0.5

3 years ago

3.0.0

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.3-alpha.64

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.6

5 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.3-alpha.40

6 years ago

0.3.2

6 years ago

0.3.1

7 years ago

0.3.0

7 years ago