New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sh-input-currency

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sh-input-currency - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.travis.yml

302

bin/sh-input-currency.js

@@ -78,2 +78,6 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _shCore = __webpack_require__(/*! sh-core */ 3);
var _shCore2 = _interopRequireDefault(_shCore);
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; } }

@@ -91,3 +95,3 @@

__webpack_require__(/*! ./sh-input-currency.scss */ 3);
__webpack_require__(/*! ./sh-input-currency.scss */ 4);

@@ -103,3 +107,4 @@ var ShInputCurrency = function (_Component) {

_this.state = {
classList: ['sh-input-currency empty'],
value: '',
classList: 'sh-input-currency empty',
placeholderText: '+'

@@ -115,30 +120,5 @@ };

_createClass(ShInputCurrency, [{
key: 'getDecimal',
value: function getDecimal(value) {
if (!value) {
return null;
}
var num = value;
if (!_.isNumber(value)) {
var isNeg = '-' && _.includes(value, '-');
var regExp = '[^0-9.]';
var numString = value.replace(new RegExp(regExp, 'g'), '');
var numList = numString.split('.');
// numList will always have at least one value in array because we checked for an empty string earlier.
numList[0] += '.';
numString = numList.join('');
num = parseFloat(numString);
if (!num) {
num = 0;
} else if (isNeg) {
num *= -1;
}
}
return num;
key: 'runFormarters',
value: function runFormarters(txt) {
return '$' + this.formatNumber(Number(_shCore2.default.getDecimal(txt)).toFixed(2));
}

@@ -149,5 +129,6 @@ }, {

if (this.props.value) {
var text = this.runFormarters(this.props.value);
this.setState({
value: this.props.value,
classList: ['sh-input-currency']
value: text,
classList: 'sh-input-currency'
});

@@ -160,2 +141,3 @@ }

}
this.state.placeholderHolder = this.state.placeholderText;
}

@@ -168,4 +150,6 @@ }, {

this.setState({ value: text });
event.target.value = this.getDecimal(text);
this.props.onChange(event);
event.target.value = _shCore2.default.getDecimal(text);
if (this.props.onChange) {
this.props.onChange(event);
}
}

@@ -178,3 +162,3 @@ }, {

var text = event.target.value;
text = text.replace(/[,$]/g, '');
text = text.toString().replace(/[,$]/g, '');

@@ -186,3 +170,4 @@ if (this.props.onFocus) {

this.setState({
value: text
value: text,
placeholderText: ''
});

@@ -203,3 +188,3 @@ setTimeout(function () {

text = '$' + this.formatNumber(Number(this.getDecimal(text)).toFixed(2));
text = this.runFormarters(text);

@@ -212,3 +197,4 @@ if (this.props.onBlur) {

value: text,
classList: ['sh-input-currency']
placeholderText: this.state.placeholderHolder,
classList: 'sh-input-currency'
});

@@ -219,3 +205,3 @@

value: this.state.value,
classList: ['sh-input-currency empty']
classList: 'sh-input-currency empty'
});

@@ -230,8 +216,9 @@ }

var onBlur = _props.onBlur;
var className = _props.className;
var other = _objectWithoutProperties(_props, ['onFocus', 'onBlur']);
var other = _objectWithoutProperties(_props, ['onFocus', 'onBlur', 'className']);
return _react2.default.createElement(
'div',
{ className: this.state.classList },
{ className: this.props.className ? this.props.className + ' ' + this.state.classList : this.state.classList },
_react2.default.createElement(

@@ -245,3 +232,5 @@ 'label',

),
_react2.default.createElement('input', _extends({ ref: 'input', type: 'text'
_react2.default.createElement('input', _extends({ ref: 'input',
className: 'sh-currency-input',
type: 'text'
}, other, {

@@ -284,2 +273,219 @@ placeholder: this.state.placeholderText,

/* 3 */
/*!**********************************!*\
!*** ./~/sh-core/bin/sh-core.js ***!
\**********************************/
/***/ function(module, exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
if(true)
module.exports = factory(__webpack_require__(/*! lodash */ 2));
else if(typeof define === 'function' && define.amd)
define(["lodash"], factory);
else if(typeof exports === 'object')
exports["sh-core"] = factory(require("lodash"));
else
root["sh-core"] = factory(root["_"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDecimal = exports.getClassNames = undefined;
var _getClassNames = __webpack_require__(/*! ./util/get-class-names */ 1);
var _getClassNames2 = _interopRequireDefault(_getClassNames);
var _getDecimal = __webpack_require__(/*! ./util/get-decimal */ 3);
var _getDecimal2 = _interopRequireDefault(_getDecimal);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.getClassNames = _getClassNames2.default;
exports.getDecimal = _getDecimal2.default;
exports.default = {
getClassNames: _getClassNames2.default,
getDecimal: _getDecimal2.default
};
/***/ },
/* 1 */
/*!*************************************!*\
!*** ./src/util/get-class-names.js ***!
\*************************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = __webpack_require__(/*! lodash */ 2);
var _ = _interopRequireWildcard(_lodash);
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; } }
/**
* Get a string of classNames from the object passed in. Uses the keys for class names and only adds them if the value is true. Value of keys can be boolean, function, or strings. Functions are evaluated on call. Strings are appended to end of key.
*
* @param {object} classObject Object containing keys of class names.
* @returns {string}
*/
function getClassNames(classObject) {
var classNames = [];
for (var key in classObject) {
if (classObject.hasOwnProperty(key)) {
var check = classObject[key];
var className = _.kebabCase(key);
if (_.isFunction(check)) {
if (check()) {
classNames.push(className);
}
} else if (_.isString(check)) {
if (className === 'include' || _.includes(check, ' ')) {
classNames = _.concat(classNames, check.split(' '));
} else {
classNames.push(className + '-' + _.kebabCase(check));
}
} else if (check) {
classNames.push(className);
}
}
}
classNames = _.uniq(classNames);
return classNames.join(' ');
}
exports.default = getClassNames;
/***/ },
/* 2 */
/*!*************************************************************************************!*\
!*** external {"root":"_","commonjs2":"lodash","commonjs":"lodash","amd":"lodash"} ***!
\*************************************************************************************/
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ },
/* 3 */
/*!*********************************!*\
!*** ./src/util/get-decimal.js ***!
\*********************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = __webpack_require__(/*! lodash */ 2);
var _ = _interopRequireWildcard(_lodash);
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; } }
/**
* Get a decimal value from a string or number, remove any unnecessary characters.
*
* @param {string} value Alpha characters will be removed and a decimal will be returned. For example if you give it 'b.123' 0.123 will be returned.
* @returns {number}
*/
function getDecimal(value) {
if (!value) {
return null;
}
var num = value;
if (!_.isNumber(value)) {
var isNeg = '-' && _.includes(value, '-');
var regExp = '[^0-9.]';
var numString = value.toString().replace(new RegExp(regExp, 'g'), '');
var numList = numString.split('.');
// numList will always have at least one value in array because we checked for an empty string earlier.
numList[0] += '.';
numString = numList.join('');
num = parseFloat(numString);
if (!num) {
num = 0;
} else if (isNeg) {
num *= -1;
}
}
return num;
}
exports.default = getDecimal;
/***/ }
/******/ ])
});
;
//# sourceMappingURL=sh-core.js.map
/***/ },
/* 4 */
/*!************************************!*\

@@ -293,6 +499,6 @@ !*** ./src/sh-input-currency.scss ***!

// load the styles
var content = __webpack_require__(/*! !./../~/css-loader!./../~/sass-loader!./sh-input-currency.scss */ 4);
var content = __webpack_require__(/*! !./../~/css-loader!./../~/sass-loader!./sh-input-currency.scss */ 5);
if(typeof content === 'string') content = [[module.id, content, '']];
// add the styles to the DOM
var update = __webpack_require__(/*! ./../~/style-loader/addStyles.js */ 6)(content, {});
var update = __webpack_require__(/*! ./../~/style-loader/addStyles.js */ 7)(content, {});
if(content.locals) module.exports = content.locals;

@@ -314,3 +520,3 @@ // Hot Module Replacement

/***/ },
/* 4 */
/* 5 */
/*!*******************************************************************!*\

@@ -321,3 +527,3 @@ !*** ./~/css-loader!./~/sass-loader!./src/sh-input-currency.scss ***!

exports = module.exports = __webpack_require__(/*! ./../~/css-loader/lib/css-base.js */ 5)();
exports = module.exports = __webpack_require__(/*! ./../~/css-loader/lib/css-base.js */ 6)();
// imports

@@ -333,3 +539,3 @@

/***/ },
/* 5 */
/* 6 */
/*!**************************************!*\

@@ -393,3 +599,3 @@ !*** ./~/css-loader/lib/css-base.js ***!

/***/ },
/* 6 */
/* 7 */
/*!*************************************!*\

@@ -396,0 +602,0 @@ !*** ./~/style-loader/addStyles.js ***!

4

karma.conf.js

@@ -19,3 +19,3 @@ var path = require('path');

{ type: 'text-summary' },
{ type: 'html', subdir: 'html' }
{ type: 'lcov', subdir: 'lcov' }
]

@@ -43,3 +43,3 @@ },

{
test: /\.jsx?$/,
test: /^((?!\.spec\.).)*\.jsx?$/,
loader: 'isparta',

@@ -46,0 +46,0 @@ include: path.join(__dirname, 'src')

{
"name": "sh-input-currency",
"version": "0.1.0",
"version": "0.1.1",
"description": "Currency input box superhero theme",

@@ -11,3 +11,4 @@ "main": "./bin/sh-input-currency.js",

"dev": "./node_modules/.bin/webpack -d --watch --config webpack.config.js",
"example": "./node_modules/.bin/webpack -d --watch --config webpack.example.config.js"
"example": "./node_modules/.bin/webpack -d --watch --config webpack.example.config.js",
"coveralls": "./node_modules/.bin/coveralls < ./bin/coverage/lcov/lcov.info"
},

@@ -36,2 +37,3 @@ "repository": {

"isparta-loader": "^2.0.0",
"coveralls": "^2.11.12",
"jasmine-core": "^2.4.1",

@@ -54,4 +56,4 @@ "karma": "^1.2.0",

"react-dom": "^15.3.0",
"sh-core": "^0.1.6"
"sh-core": "^0.1.22"
}
}

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

# shInputText
SuperheroUI - Input field for currency
# SuperheroUI [![Build Status](https://travis-ci.org/SuperheroUI/shInputCurrency.svg?branch=master)](https://travis-ci.org/SuperheroUI/shInputCurrency) [![Coverage Status](https://coveralls.io/repos/github/SuperheroUI/shInputCurrency/badge.svg)](https://coveralls.io/github/SuperheroUI/shInputCurrency)
InsideSales.com React UI
## ShInputCurrency
### Website (For examples, limits, and usage)
https://superheroui.github.io/
### Installation
Use npm to install the module
```sh
npm install sh-input-currency --save
```
Now you can import it into your project
```js
import ShInputCurrency from 'sh-input-currency';
```
import React, {Component} from 'react';
import * as _ from 'lodash';
import sh from 'sh-core';
require('./sh-input-currency.scss');

@@ -10,3 +11,4 @@

this.state = {
classList: ['sh-input-currency empty'],
value: '',
classList: 'sh-input-currency empty',
placeholderText: '+'

@@ -20,37 +22,14 @@ };

getDecimal(value) {
if (!value) {
return null;
}
var num = value;
if (!_.isNumber(value)) {
var isNeg = ('-' && _.includes(value, '-'));
runFormarters(txt){
return '$' + (this.formatNumber(Number(sh.getDecimal(txt)).toFixed(2)));
}
var regExp = '[^0-9.]';
var numString = value.replace(new RegExp(regExp, 'g'), '');
var numList = numString.split('.');
// numList will always have at least one value in array because we checked for an empty string earlier.
numList[0] += '.';
numString = numList.join('');
num = parseFloat(numString);
if (!num) {
num = 0;
} else if (isNeg) {
num *= -1;
}
}
return num;
};
componentDidMount() {
if (this.props.value) {
var text = this.runFormarters(this.props.value);
this.setState(
{
value: this.props.value,
classList: ['sh-input-currency']
value: text,
classList: 'sh-input-currency'
}

@@ -64,2 +43,3 @@ )

}
this.state.placeholderHolder = this.state.placeholderText;
}

@@ -71,4 +51,6 @@

this.setState({value: text});
event.target.value = this.getDecimal(text);
this.props.onChange(event);
event.target.value = sh.getDecimal(text);
if(this.props.onChange){
this.props.onChange(event);
}
};

@@ -79,3 +61,3 @@

var text = event.target.value;
text = text.replace(/[,$]/g, '');
text = text.toString().replace(/[,$]/g, '');

@@ -88,3 +70,4 @@ if (this.props.onFocus) {

{
value: text
value: text,
placeholderText: ''
}

@@ -104,3 +87,3 @@ );

text = '$' + (this.formatNumber(Number(this.getDecimal(text)).toFixed(2)));
text = this.runFormarters(text);

@@ -114,3 +97,4 @@ if (this.props.onBlur) {

value: text,
classList: ['sh-input-currency']
placeholderText: this.state.placeholderHolder,
classList: 'sh-input-currency'
}

@@ -123,3 +107,3 @@ );

value: this.state.value,
classList: ['sh-input-currency empty']
classList: 'sh-input-currency empty'
}

@@ -131,9 +115,11 @@ )

render() {
var {onFocus, onBlur, ...other} = this.props;
var {onFocus, onBlur, className, ...other} = this.props;
return (
<div className={this.state.classList}>
<div className={this.props.className ? this.props.className +' '+this.state.classList : this.state.classList}>
<label>
<span className="label">{this.props.label}</span>
<input ref="input" type="text"
<input ref="input"
className="sh-currency-input"
type="text"
{...other}

@@ -140,0 +126,0 @@ placeholder={this.state.placeholderText}

@@ -1,13 +0,127 @@

var React = require('react');
var ReactDOM = require('react-dom');
var TestUtils = require('react/lib/ReactTestUtils');
var ShInputCheckbox = require('./sh-input-currency').default;
var ShInputCurrency = require('./sh-input-currency').default;
describe('root', function() {
it('renders without problems', function() {
let value = true;
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} />);
expect(root.state).toBeTruthy();
});
describe('root', function () {
it('renders without problems', function () {
let value = true;
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value}/>);
expect(root.state).toBeTruthy();
});
it('things do No explode if there is no onChange function', function() {
let value = true;
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} />);
root.handleChange({
target: {
value: 3
}
});
});
it('things do No explode if there is no onFocus function', function() {
let value = true;
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} />);
root.handleFocus({
target: {
value: 3
}
});
});
it('works with on change, initial state and formats currency with dollar', function () {
let what = '0';
let changeMe = () => {
value = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={what} onChange={changeMe}/>);
let rootNode = ReactDOM.findDOMNode(root);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
expect(input.value).toBe('$0.00');
});
it('works a field is required', function () {
let what = '0';
let changeMe = () => {
value = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency required value={what} onChange={changeMe}/>);
let rootNode = ReactDOM.findDOMNode(root);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
expect(input.required).toBe(true);
expect(input.placeholder).toBe('Required Field');
});
it('input styles be set to empty if there is no value', function () {
var root = TestUtils.renderIntoDocument(<ShInputCurrency />);
let rootNode = ReactDOM.findDOMNode(root);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
TestUtils.Simulate.blur(input);
expect(rootNode.classList[1]).toBe('empty')
});
it('input styles not be set to empty if there is a value', function () {
let value = '0';
let changeMe = () => {
value = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} onChange={changeMe}/>);
let rootNode = ReactDOM.findDOMNode(root);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
TestUtils.Simulate.blur(input);
expect(rootNode.classList.length).toBe(1)
});
it('handle having outside onBlur', function () {
let value = '0';
let blurTest = 0;
let onBlur = ()=> {
blurTest = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} onBlur={onBlur}/>);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
TestUtils.Simulate.blur(input);
expect(blurTest).toBe(1)
});
it('handle having outside onFocus', function () {
let value = '0';
let focusTest = 0;
let onFocus = ()=> {
focusTest = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} onFocus={onFocus}/>);
expect(root.state).toBeTruthy();
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
TestUtils.Simulate.focus(input);
expect(focusTest).toBe(1)
});
it('handle internal changes, then format text to a currency', function () {
let value = '0';
let changeMe = () => {
value = 1;
};
var root = TestUtils.renderIntoDocument(<ShInputCurrency value={value} onChange={changeMe}/>);
let input = TestUtils.findRenderedDOMComponentWithClass(root, 'sh-currency-input');
root.handleChange({
target: {
value: 3
}
});
expect(value).toBe(1);
expect(input.value).toBe('3');
TestUtils.Simulate.blur(input);
expect(input.value).toBe('$3.00');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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