@qlean/york-core
Advanced tools
Comparing version 0.4.0 to 0.6.1
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,57 +6,51 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var _colors = require('./styles/colors'); | ||
Object.defineProperty(exports, 'colors', { | ||
Object.defineProperty(exports, "colors", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_colors).default; | ||
return _colors["default"]; | ||
} | ||
}); | ||
var _capitalize = require('./utils/capitalize'); | ||
Object.defineProperty(exports, 'capitalize', { | ||
Object.defineProperty(exports, "capitalize", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_capitalize).default; | ||
return _capitalize["default"]; | ||
} | ||
}); | ||
var _formatPhoneForHref = require('./utils/formatPhoneForHref'); | ||
Object.defineProperty(exports, 'formatPhoneForHref', { | ||
Object.defineProperty(exports, "formatPhoneForHref", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_formatPhoneForHref).default; | ||
return _formatPhoneForHref["default"]; | ||
} | ||
}); | ||
var _formatServerError = require('./utils/formatServerError'); | ||
Object.defineProperty(exports, 'formatServerError', { | ||
Object.defineProperty(exports, "formatServerError", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_formatServerError).default; | ||
return _formatServerError["default"]; | ||
} | ||
}); | ||
var _format = require('./utils/format'); | ||
Object.defineProperty(exports, 'format', { | ||
Object.defineProperty(exports, "format", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_format).default; | ||
return _format["default"]; | ||
} | ||
}); | ||
var _money = require('./utils/money'); | ||
Object.defineProperty(exports, 'money', { | ||
Object.defineProperty(exports, "money", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_money).default; | ||
return _money["default"]; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _colors = _interopRequireDefault(require("./styles/colors")); | ||
var _capitalize = _interopRequireDefault(require("./utils/capitalize")); | ||
var _formatPhoneForHref = _interopRequireDefault(require("./utils/formatPhoneForHref")); | ||
var _formatServerError = _interopRequireDefault(require("./utils/formatServerError")); | ||
var _format = _interopRequireDefault(require("./utils/format")); | ||
var _money = _interopRequireDefault(require("./utils/money")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = { | ||
exports["default"] = void 0; | ||
var _default = { | ||
green: '#20A052', | ||
red: '#D13737', | ||
blue: '#2FAFDE', | ||
yellow: '#FAE12E', | ||
red: '#D13737', | ||
transparent: 'transparent', | ||
white: '#FFFFFF', | ||
smoke: '#F8F8F8', | ||
whisper: '#ECECEC', | ||
silver: '#D9D9D9', | ||
whisper: '#ECECEC', | ||
grey: '#A6A6A6', | ||
ash: '#595959', | ||
coal: '#222222', | ||
black: '#000000', | ||
blue: '#2FAFDE', | ||
transparent: 'transparent' | ||
}; | ||
black: '#000000' | ||
}; | ||
exports["default"] = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = capitalize; | ||
exports["default"] = capitalize; | ||
function capitalize(string) { | ||
var unwrappedString = typeof string === 'string' ? string : ''; | ||
return '' + (unwrappedString[0] || '').toUpperCase() + unwrappedString.slice(1); | ||
return "".concat((unwrappedString[0] || '').toUpperCase()).concat(unwrappedString.slice(1)); | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = format; | ||
exports["default"] = format; | ||
var getFormattedMoney = function getFormattedMoney(number) { | ||
var formattedNumber = new Intl.NumberFormat('ru-RU').format(number / 100); | ||
var suffix = 'р.'; | ||
return formattedNumber + '\xA0' + suffix; | ||
return "".concat(formattedNumber, "\xA0").concat(suffix); | ||
}; | ||
@@ -14,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,5 +6,6 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = formatPhoneForHref; | ||
exports["default"] = formatPhoneForHref; | ||
function formatPhoneForHref(phone) { | ||
return 'tel:' + phone.replace(/(\s|-|\(|\))/g, ''); | ||
return "tel:".concat(phone.replace(/(\s|-|\(|\))/g, '')); | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports["default"] = void 0; | ||
var _ramda = require('ramda'); | ||
var R = _interopRequireWildcard(require("ramda")); | ||
var R = _interopRequireWildcard(_ramda); | ||
var _capitalize = _interopRequireDefault(require("./capitalize")); | ||
var _capitalize = require('./capitalize'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _capitalize2 = _interopRequireDefault(_capitalize); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
var getErrorData = function getErrorData(error) { | ||
@@ -36,3 +33,3 @@ var data = R.prop('data', error) || {}; | ||
return [value]; | ||
}), flattenAll, R.filter(R.is(String)), R.join(', '), _capitalize2.default)(errors); | ||
}), flattenAll, R.filter(R.is(String)), R.join(', '), _capitalize["default"])(errors); | ||
}; | ||
@@ -42,13 +39,18 @@ | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var errorData = getErrorData(error); | ||
var errorData = getErrorData(error); | ||
if (Array.isArray(errorData) && !errorData.length) { | ||
return {}; | ||
} | ||
if (Array.isArray(errorData) || config.flattenErrors) { | ||
return { _error: flattenErrors(errorData) }; | ||
return { | ||
_error: flattenErrors(errorData) | ||
}; | ||
} | ||
return R.pipe(R.map(flattenErrors), R.filter(R.identity))(errorData); | ||
}; | ||
exports.default = formatServerError; | ||
var _default = formatServerError; | ||
exports["default"] = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,33 +6,26 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = money; | ||
exports["default"] = money; | ||
var _format = require('./format'); | ||
var _format = _interopRequireDefault(require("./format")); | ||
var _format2 = _interopRequireDefault(_format); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// @param {Number} value | ||
function curryFormat(value) { | ||
// @param {String} formatter | ||
return function () { | ||
var formatter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'money'; | ||
return (0, _format2.default)(formatter, value); | ||
return (0, _format["default"])(formatter, value); | ||
}; | ||
} | ||
// @param {Number} value | ||
} // @param {Number} value | ||
// @param {Number} discount | ||
function addDiscount(value, discount) { | ||
var newValue = Math.ceil(value * (1 - discount / 100)); | ||
return newValue > 0 ? newValue : 0; | ||
} | ||
// @param {Number} value | ||
} // @param {Number} value | ||
// @param {Number|Array} discounts | ||
function money(value) { | ||
@@ -39,0 +32,0 @@ var discounts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; |
{ | ||
"name": "@qlean/york-core", | ||
"version": "0.4.0", | ||
"version": "0.6.1", | ||
"main": "lib/index.js", | ||
@@ -12,2 +12,3 @@ "description": "", | ||
"scripts": { | ||
"start": "babel src -d lib --ignore test.js -w", | ||
"build": "npm run clean && babel src -d lib --ignore test.js", | ||
@@ -18,18 +19,8 @@ "clean": "rimraf coverage lib", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage", | ||
"watch": "babel src -d lib --ignore test.js -w" | ||
"precommit": "lint-staged" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"eslint": "^4.12.1", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"jest": "^21.2.1", | ||
"ramda": "^0.25.0", | ||
"rimraf": "^2.6.2" | ||
"peerDependencies": { | ||
"ramda": ">=0.26" | ||
}, | ||
"peerDependencies": { | ||
"ramda": "*" | ||
} | ||
"gitHead": "f8d43a09443f6ee1e50bbd4fc96e5cd21128cd01" | ||
} |
@@ -1,7 +0,7 @@ | ||
export { default as colors } from './styles/colors'; | ||
export { default as colors } from './styles/colors' | ||
export { default as capitalize } from './utils/capitalize'; | ||
export { default as formatPhoneForHref } from './utils/formatPhoneForHref'; | ||
export { default as formatServerError } from './utils/formatServerError'; | ||
export { default as format } from './utils/format'; | ||
export { default as money } from './utils/money'; | ||
export { default as capitalize } from './utils/capitalize' | ||
export { default as formatPhoneForHref } from './utils/formatPhoneForHref' | ||
export { default as formatServerError } from './utils/formatServerError' | ||
export { default as format } from './utils/format' | ||
export { default as money } from './utils/money' |
export default { | ||
green: '#20A052', | ||
red: '#D13737', | ||
blue: '#2FAFDE', | ||
yellow: '#FAE12E', | ||
red: '#D13737', | ||
transparent: 'transparent', | ||
white: '#FFFFFF', | ||
smoke: '#F8F8F8', | ||
whisper: '#ECECEC', | ||
silver: '#D9D9D9', | ||
whisper: '#ECECEC', | ||
grey: '#A6A6A6', | ||
@@ -13,4 +15,2 @@ ash: '#595959', | ||
black: '#000000', | ||
blue: '#2FAFDE', | ||
transparent: 'transparent', | ||
}; | ||
} |
export default function capitalize(string) { | ||
const unwrappedString = typeof string === 'string' ? string : ''; | ||
return `${(unwrappedString[0] || '').toUpperCase()}${unwrappedString.slice(1)}`; | ||
const unwrappedString = typeof string === 'string' ? string : '' | ||
return `${(unwrappedString[0] || '').toUpperCase()}${unwrappedString.slice( | ||
1, | ||
)}` | ||
} |
@@ -1,14 +0,14 @@ | ||
const getFormattedMoney = (number) => { | ||
const formattedNumber = new Intl.NumberFormat('ru-RU').format(number / 100); | ||
const suffix = 'р.'; | ||
const getFormattedMoney = number => { | ||
const formattedNumber = new Intl.NumberFormat('ru-RU').format(number / 100) | ||
const suffix = 'р.' | ||
return `${formattedNumber}\u00a0${suffix}`; | ||
}; | ||
return `${formattedNumber}\u00a0${suffix}` | ||
} | ||
const formattersMap = { | ||
money: getFormattedMoney, | ||
}; | ||
} | ||
export default function format(formatter, value) { | ||
return formattersMap[formatter](value); | ||
return formattersMap[formatter](value) | ||
} |
export default function formatPhoneForHref(phone) { | ||
return `tel:${phone.replace(/(\s|-|\(|\))/g, '')}`; | ||
return `tel:${phone.replace(/(\s|-|\(|\))/g, '')}` | ||
} |
@@ -1,35 +0,35 @@ | ||
import * as R from 'ramda'; | ||
import * as R from 'ramda' | ||
import capitalize from './capitalize'; | ||
import capitalize from './capitalize' | ||
const getErrorData = (error) => { | ||
const data = R.prop('data', error) || {}; | ||
const errors = data.errors || data.error || []; | ||
return (typeof errors === 'string') ? [errors] : errors; | ||
}; | ||
const getErrorData = error => { | ||
const data = R.prop('data', error) || {} | ||
const errors = data.errors || data.error || [] | ||
return typeof errors === 'string' ? [errors] : errors | ||
} | ||
const flattenAll = i => ( | ||
R.flatten(R.values(i).map((value) => { | ||
const type = R.type(value); | ||
return (type === 'Object' || type === 'Array') | ||
? flattenAll(value) | ||
: value; | ||
})) | ||
); | ||
const flattenAll = i => | ||
R.flatten( | ||
R.values(i).map(value => { | ||
const type = R.type(value) | ||
return type === 'Object' || type === 'Array' ? flattenAll(value) : value | ||
}), | ||
) | ||
const flattenErrors = errors => R.pipe( | ||
R.unless(Array.isArray, value => [value]), | ||
flattenAll, | ||
R.filter(R.is(String)), | ||
R.join(', '), | ||
capitalize, | ||
)(errors); | ||
const flattenErrors = errors => | ||
R.pipe( | ||
R.unless(Array.isArray, value => [value]), | ||
flattenAll, | ||
R.filter(R.is(String)), | ||
R.join(', '), | ||
capitalize, | ||
)(errors) | ||
const formatServerError = (error, config = {}) => { | ||
const errorData = getErrorData(error); | ||
const errorData = getErrorData(error) | ||
if (Array.isArray(errorData) && !errorData.length) { | ||
return {}; | ||
return {} | ||
} | ||
if (Array.isArray(errorData) || config.flattenErrors) { | ||
return { _error: flattenErrors(errorData) }; | ||
return { _error: flattenErrors(errorData) } | ||
} | ||
@@ -39,5 +39,5 @@ return R.pipe( | ||
R.filter(R.identity), | ||
)(errorData); | ||
}; | ||
)(errorData) | ||
} | ||
export default formatServerError; | ||
export default formatServerError |
@@ -1,4 +0,3 @@ | ||
import format from './format'; | ||
import format from './format' | ||
// @param {Number} value | ||
@@ -9,6 +8,5 @@ | ||
return (formatter = 'money') => format(formatter, value); | ||
return (formatter = 'money') => format(formatter, value) | ||
} | ||
// @param {Number} value | ||
@@ -18,8 +16,7 @@ // @param {Number} discount | ||
function addDiscount(value, discount) { | ||
const newValue = Math.ceil(value * (1 - (discount / 100))); | ||
const newValue = Math.ceil(value * (1 - discount / 100)) | ||
return newValue > 0 ? newValue : 0; | ||
return newValue > 0 ? newValue : 0 | ||
} | ||
// @param {Number} value | ||
@@ -30,6 +27,8 @@ // @param {Number|Array} discounts | ||
if (Array.isArray(discounts)) { | ||
return curryFormat(discounts.reduce((acc, discount) => addDiscount(acc, discount), value)); | ||
return curryFormat( | ||
discounts.reduce((acc, discount) => addDiscount(acc, discount), value), | ||
) | ||
} | ||
return curryFormat(addDiscount(value, discounts)); | ||
return curryFormat(addDiscount(value, discounts)) | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
15200
0
22
435
2