Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndla/util

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndla/util - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

1

es/convertFieldWithFallback.js

@@ -8,5 +8,4 @@ /**

*/
export default function convertFieldWithFallback(element, field, fallback) {
return element[field] ? element[field][field] : fallback;
}

@@ -8,3 +8,2 @@ /**

*/
export function copyTextToClipboard(text) {

@@ -18,3 +17,2 @@ var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;

var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';

@@ -30,7 +28,4 @@ textArea.style.top = 0;

textArea.style.height = '2em';
textArea.value = text;
el.appendChild(textArea);
textArea.select();

@@ -37,0 +32,0 @@

12

es/createUniversalPortal.js

@@ -8,5 +8,3 @@ /**

*/
// N.B This helper is intended to be used in https://github.com/ndlano/article-converter. It is not a general soultion for using portals in SSR applications.
import React from 'react';

@@ -19,11 +17,11 @@ import ReactDOM from 'react-dom';

export function createUniversalPortal(children, selector) {
if (!canUseDOM()) {
return React.createElement(
'div',
{ 'data-react-universal-portal': true },
children
);
return React.createElement("div", {
"data-react-universal-portal": true
}, children);
}
return ReactDOM.createPortal(children, document.querySelector(selector));
}

@@ -8,6 +8,4 @@ /**

*/
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;

@@ -18,7 +16,6 @@

content = _ref.content;
var docDefinition = {
footer: function footer(currentPage, pageCount) {
return {
text: currentPage.toString() + ' of ' + pageCount,
text: "".concat(currentPage.toString(), " of ").concat(pageCount),
style: 'footer'

@@ -56,3 +53,2 @@ };

};
pdfMake.createPdf(docDefinition).download(title);

@@ -59,0 +55,0 @@ };

@@ -8,3 +8,2 @@ /**

*/
var getComponentName = function getComponentName(component) {

@@ -11,0 +10,0 @@ return component.displayName || component.name || 'Component';

@@ -6,3 +6,2 @@ var getCurrentBreakpoint = function getCurrentBreakpoint() {

export default getCurrentBreakpoint;
export var breakpoints = {

@@ -9,0 +8,0 @@ mobile: 'mobile',

@@ -8,3 +8,2 @@ /**

*/
import defined from 'defined';

@@ -18,2 +17,3 @@

});
if (!locale && translations.length > 0) {

@@ -32,3 +32,2 @@ return translations[0];

var preferdLocales = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['nb', 'nn', 'en'];
var translations = defined(defined(obj, {})[fieldName], []);

@@ -35,0 +34,0 @@ var translation = defined(translations.find(function (d) {

@@ -8,3 +8,2 @@ /**

*/
export { default as uuid } from './uuid';

@@ -11,0 +10,0 @@ export { default as getComponentName } from './getComponentName';

@@ -14,7 +14,5 @@ var scrollbarWidth = null;

scrollDiv.style.top = '-9999px';
document.body.appendChild(scrollDiv);
scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;

@@ -35,4 +33,3 @@ };

var currentScrollPosition = void 0;
var currentScrollPosition;
var scrollTargets = [];

@@ -42,2 +39,3 @@

var htmlElement = document.querySelector('html');
if (enable) {

@@ -49,8 +47,11 @@ if (!scrollTargets.includes(uuid)) {

htmlElement.style.overflow = 'hidden';
htmlElement.style.paddingRight = scrollWidth + 'px';
htmlElement.style.paddingRight = "".concat(scrollWidth, "px");
var mastHead = document.querySelector('.c-masthead--fixed');
if (mastHead) {
mastHead.style.paddingRight = scrollWidth + 'px';
mastHead.style.paddingRight = "".concat(scrollWidth, "px");
}
htmlElement.style.position = isIosDeviceSafari ? 'fixed' : 'static'; // iOS scrolling fix
htmlElement.style.left = 0;

@@ -63,2 +64,3 @@ htmlElement.style.right = 0;

}
if (scrollTargets.length === 0) {

@@ -68,8 +70,12 @@ htmlElement.style.overflow = 'visible';

htmlElement.style.paddingRight = 0;
var _mastHead = document.querySelector('.c-masthead--fixed');
if (_mastHead) {
_mastHead.style.paddingRight = 0;
}
htmlElement.style.left = 'auto';
htmlElement.style.right = 'auto';
if (isIosDeviceSafari) {

@@ -76,0 +82,0 @@ setBodyScrollTop(currentScrollPosition);

@@ -8,3 +8,2 @@ /**

*/
function uuid(a) {

@@ -11,0 +10,0 @@ return a // eslint-disable-next-line

@@ -7,2 +7,3 @@ "use strict";

exports.default = convertFieldWithFallback;
/**

@@ -15,5 +16,4 @@ * Copyright (c) 2016-present, NDLA.

*/
function convertFieldWithFallback(element, field, fallback) {
return element[field] ? element[field][field] : fallback;
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -7,2 +7,3 @@ Object.defineProperty(exports, "__esModule", {

exports.copyTextToClipboard = copyTextToClipboard;
/**

@@ -15,3 +16,2 @@ * Copyright (c) 2017-present, NDLA.

*/
function copyTextToClipboard(text) {

@@ -25,3 +25,2 @@ var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;

var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';

@@ -37,7 +36,4 @@ textArea.style.top = 0;

textArea.style.height = '2em';
textArea.value = text;
el.appendChild(textArea);
textArea.select();

@@ -44,0 +40,0 @@

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {

var _react = require('react');
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
var _reactDom = require("react-dom");

@@ -26,5 +26,3 @@ var _reactDom2 = _interopRequireDefault(_reactDom);

*/
// N.B This helper is intended to be used in https://github.com/ndlano/article-converter. It is not a general soultion for using portals in SSR applications.
var canUseDOM = function canUseDOM() {

@@ -34,11 +32,11 @@ return !!(typeof window !== 'undefined' && window.document && window.document.createElement && !window.document.hidden);

function createUniversalPortal(children, selector) {
if (!canUseDOM()) {
return _react2.default.createElement(
'div',
{ 'data-react-universal-portal': true },
children
);
return _react2.default.createElement("div", {
"data-react-universal-portal": true
}, children);
}
return _reactDom2.default.createPortal(children, document.querySelector(selector));
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {

var _pdfmake = require('pdfmake/build/pdfmake');
var _pdfmake = require("pdfmake/build/pdfmake");
var _pdfmake2 = _interopRequireDefault(_pdfmake);
var _vfs_fonts = require('pdfmake/build/vfs_fonts');
var _vfs_fonts = require("pdfmake/build/vfs_fonts");

@@ -26,3 +26,2 @@ var _vfs_fonts2 = _interopRequireDefault(_vfs_fonts);

*/
_pdfmake2.default.vfs = _vfs_fonts2.default.pdfMake.vfs;

@@ -33,7 +32,6 @@

content = _ref.content;
var docDefinition = {
footer: function footer(currentPage, pageCount) {
return {
text: currentPage.toString() + ' of ' + pageCount,
text: "".concat(currentPage.toString(), " of ").concat(pageCount),
style: 'footer'

@@ -40,0 +38,0 @@ };

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,2 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
/**

@@ -14,3 +15,2 @@ * Copyright (c) 2016-present, NDLA.

*/
var getComponentName = function getComponentName(component) {

@@ -17,0 +17,0 @@ return component.displayName || component.name || 'Component';

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,2 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
var getCurrentBreakpoint = function getCurrentBreakpoint() {

@@ -8,0 +9,0 @@ return window.getComputedStyle(document.querySelector('body'), ':before').getPropertyValue('content').replace(/"/g, '');

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", {

var _defined = require('defined');
var _defined = require("defined");

@@ -15,2 +15,9 @@ var _defined2 = _interopRequireDefault(_defined);

/**
* Copyright (c) 2016-present, NDLA.
*
* This source code is licensed under the GPLv3 license found in the
* LICENSE file in the root directory of this source tree.
*
*/
var findFallbackTranslation = function findFallbackTranslation(translations, preferdLocales) {

@@ -22,2 +29,3 @@ var locale = preferdLocales.find(function (l) {

});
if (!locale && translations.length > 0) {

@@ -30,9 +38,3 @@ return translations[0];

});
}; /**
* Copyright (c) 2016-present, NDLA.
*
* This source code is licensed under the GPLv3 license found in the
* LICENSE file in the root directory of this source tree.
*
*/
};

@@ -43,3 +45,2 @@ var createFieldByLanguageFinder = function createFieldByLanguageFinder(fieldName, propName) {

var preferdLocales = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['nb', 'nn', 'en'];
var translations = (0, _defined2.default)((0, _defined2.default)(obj, {})[fieldName], []);

@@ -46,0 +47,0 @@ var translation = (0, _defined2.default)(translations.find(function (d) {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -7,5 +7,5 @@ Object.defineProperty(exports, "__esModule", {

var _uuid = require('./uuid');
var _uuid = require("./uuid");
Object.defineProperty(exports, 'uuid', {
Object.defineProperty(exports, "uuid", {
enumerable: true,

@@ -17,5 +17,5 @@ get: function get() {

var _getComponentName = require('./getComponentName');
var _getComponentName = require("./getComponentName");
Object.defineProperty(exports, 'getComponentName', {
Object.defineProperty(exports, "getComponentName", {
enumerable: true,

@@ -27,5 +27,5 @@ get: function get() {

var _copyTextToClipboard = require('./copyTextToClipboard');
var _copyTextToClipboard = require("./copyTextToClipboard");
Object.defineProperty(exports, 'copyTextToClipboard', {
Object.defineProperty(exports, "copyTextToClipboard", {
enumerable: true,

@@ -37,5 +37,5 @@ get: function get() {

var _convertFieldWithFallback = require('./convertFieldWithFallback');
var _convertFieldWithFallback = require("./convertFieldWithFallback");
Object.defineProperty(exports, 'convertFieldWithFallback', {
Object.defineProperty(exports, "convertFieldWithFallback", {
enumerable: true,

@@ -47,5 +47,5 @@ get: function get() {

var _i18nFieldFinder = require('./i18nFieldFinder');
var _i18nFieldFinder = require("./i18nFieldFinder");
Object.defineProperty(exports, 'tagsI18N', {
Object.defineProperty(exports, "tagsI18N", {
enumerable: true,

@@ -57,5 +57,5 @@ get: function get() {

var _noScroll = require('./noScroll');
var _noScroll = require("./noScroll");
Object.defineProperty(exports, 'noScroll', {
Object.defineProperty(exports, "noScroll", {
enumerable: true,

@@ -66,3 +66,3 @@ get: function get() {

});
Object.defineProperty(exports, 'isIosDeviceSafari', {
Object.defineProperty(exports, "isIosDeviceSafari", {
enumerable: true,

@@ -74,5 +74,5 @@ get: function get() {

var _getCurrentBreakpoint = require('./getCurrentBreakpoint');
var _getCurrentBreakpoint = require("./getCurrentBreakpoint");
Object.defineProperty(exports, 'getCurrentBreakpoint', {
Object.defineProperty(exports, "getCurrentBreakpoint", {
enumerable: true,

@@ -83,3 +83,3 @@ get: function get() {

});
Object.defineProperty(exports, 'breakpoints', {
Object.defineProperty(exports, "breakpoints", {
enumerable: true,

@@ -91,5 +91,5 @@ get: function get() {

var _downloadPdf = require('./downloadPdf');
var _downloadPdf = require("./downloadPdf");
Object.defineProperty(exports, 'downloadPdf', {
Object.defineProperty(exports, "downloadPdf", {
enumerable: true,

@@ -101,5 +101,5 @@ get: function get() {

var _createUniversalPortal = require('./createUniversalPortal');
var _createUniversalPortal = require("./createUniversalPortal");
Object.defineProperty(exports, 'createUniversalPortal', {
Object.defineProperty(exports, "createUniversalPortal", {
enumerable: true,

@@ -106,0 +106,0 @@ get: function get() {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -19,7 +19,5 @@ Object.defineProperty(exports, "__esModule", {

scrollDiv.style.top = '-9999px';
document.body.appendChild(scrollDiv);
scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;

@@ -40,4 +38,3 @@ };

var currentScrollPosition = void 0;
var currentScrollPosition;
var scrollTargets = [];

@@ -47,2 +44,3 @@

var htmlElement = document.querySelector('html');
if (enable) {

@@ -54,8 +52,11 @@ if (!scrollTargets.includes(uuid)) {

htmlElement.style.overflow = 'hidden';
htmlElement.style.paddingRight = scrollWidth + 'px';
htmlElement.style.paddingRight = "".concat(scrollWidth, "px");
var mastHead = document.querySelector('.c-masthead--fixed');
if (mastHead) {
mastHead.style.paddingRight = scrollWidth + 'px';
mastHead.style.paddingRight = "".concat(scrollWidth, "px");
}
htmlElement.style.position = isIosDeviceSafari ? 'fixed' : 'static'; // iOS scrolling fix
htmlElement.style.left = 0;

@@ -68,2 +69,3 @@ htmlElement.style.right = 0;

}
if (scrollTargets.length === 0) {

@@ -73,8 +75,12 @@ htmlElement.style.overflow = 'visible';

htmlElement.style.paddingRight = 0;
var _mastHead = document.querySelector('.c-masthead--fixed');
if (_mastHead) {
_mastHead.style.paddingRight = 0;
}
htmlElement.style.left = 'auto';
htmlElement.style.right = 'auto';
if (isIosDeviceSafari) {

@@ -81,0 +87,0 @@ setBodyScrollTop(currentScrollPosition);

@@ -6,2 +6,3 @@ "use strict";

});
/**

@@ -14,3 +15,2 @@ * Copyright (c) 2016-present, NDLA.

*/
function uuid(a) {

@@ -17,0 +17,0 @@ return a // eslint-disable-next-line

{
"name": "@ndla/util",
"version": "0.3.0",
"version": "0.3.1",
"description": "Collection of util functions used by NDLA",

@@ -8,12 +8,3 @@ "license": "GPL-3.0",

"module": "es/index.js",
"jsnext:main": "es/index.js",
"sideEffects": false,
"scripts": {
"build": "npm run build:commonjs && npm run build:es",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --quiet --out-dir lib --ignore __tests__",
"build:es": "cross-env BABEL_ENV=es babel src --quiet --out-dir es --ignore __tests__",
"clean": "rimraf lib es",
"test": "jest",
"prepublish": "npm run clean && npm run build"
},
"repository": {

@@ -20,0 +11,0 @@ "type": "git",

@@ -72,5 +72,7 @@ # ndla-util

### `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']`.
```js
````js
import { tagsI18N } from '@ndla/util';

@@ -84,2 +86,2 @@ tagsI18N(object, 'nb', false, ['nb', 'nn', 'en']);

downloadPdf({ title: 'myPdf', content: [{ text: 'PDF example', style: 'header'}, { text: 'Ingress text', style: 'ingress'}, { text: 'paragraph text #1', style: 'paragraph'}, { text: 'paragraph text #2', style: 'paragraph'}]);
```
````
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc