numora 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +8 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/numora)
|
|
4
4
|
|
|
5
|
-
A lightweight, framework-agnostic numeric input library for handling currency and decimal inputs in **financial/DeFi** applications. Built with TypeScript with
|
|
5
|
+
A lightweight, framework-agnostic numeric input library for handling currency and decimal inputs in **financial/DeFi** applications. Built with TypeScript and designed for modern web applications with:
|
|
6
|
+
|
|
7
|
+
- **Zero dependencies** - minimal footprint for your bundle
|
|
8
|
+
- **Type safety** - fully typed API for better developer experience
|
|
9
|
+
- **Framework agnostic** - use with any framework or vanilla JavaScript
|
|
10
|
+
- **Customizable** - extensive options to fit your specific needs
|
|
11
|
+
|
|
12
|
+
## Demo
|
|
13
|
+
|
|
14
|
+
Check out the [live demo](https://numora.netlify.app/) to see Numora in action.
|
|
6
15
|
|
|
7
16
|
## Features
|
|
8
17
|
|
|
@@ -56,8 +65,8 @@ The NumericInput constructor accepts the following options:
|
|
|
56
65
|
|
|
57
66
|
Numora is also available for popular frameworks:
|
|
58
67
|
|
|
59
|
-
- React: `numora-react`
|
|
60
|
-
- Vue: `numora-vue`
|
|
68
|
+
- React: `numora-react` (in progress)
|
|
69
|
+
- Vue: `numora-vue` (in progress)
|
|
61
70
|
- Svelte: `numora`
|
|
62
71
|
|
|
63
72
|
## License
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.defineProperty;var f=(t,e,n)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var r=(t,e,n)=>f(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=t=>t.replace(/[^0-9.]/g,""),L=t=>t.replace(/(\..*?)\./g,"$1"),o=t=>L(y(t)),g=t=>t.replace(/,/g,"."),v=t=>[".",","].some(n=>t.key===n&&t.target&&t.target.value.includes(".")),a=(t,e)=>{const[n,i]=t.split(".");return i?`${n}.${i.slice(0,e)}`:t};function D(t,e){const n=t.target;n.value=g(n.value),n.value=o(n.value),n.value=a(n.value,e)}function b(t){v(t)&&t.preventDefault()}function C(t,e){var d;const n=t.target,{value:i,selectionStart:s,selectionEnd:E}=n,c=o(((d=t.clipboardData)==null?void 0:d.getData("text/plain"))||""),u=i.slice(0,s||0)+c+i.slice(E||0),[I,...h]=u.split("."),l=I+(h.length>0?"."+h.join(""):"");t.preventDefault(),n.value=a(l,e);const m=(s||0)+c.length-(u.length-l.length);return n.setSelectionRange(m,m),a(l,e)}const p=2;class A{constructor(e,{maxDecimals:n=p,onChange:i,...s}){r(this,"element");r(this,"options");this.options={maxDecimals:n,onChange:i,...s},this.createInputElement(e),this.setupEventListeners()}createInputElement(e){this.element=document.createElement("input"),this.element.setAttribute("minlength","1"),this.element.setAttribute("pattern","^[0-9]*[.,]?[0-9]*$"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal");const{maxDecimals:n,onChange:i,...s}=this.options;Object.assign(this.element,s),e.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this))}handleChange(e){D(e,this.options.maxDecimals||p),this.options.onChange&&this.options.onChange(e.target.value)}handleKeyDown(e){b(e)}handlePaste(e){C(e,this.options.maxDecimals),this.options.onChange&&this.options.onChange(e.target.value)}getValue(){return this.element.value}setValue(e){this.element.value=e}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(e,n){this.element.addEventListener(e,n)}removeEventListener(e,n){this.element.removeEventListener(e,n)}}exports.NumericInput=A;exports.alreadyHasDecimal=v;exports.handleOnChangeNumericInput=D;exports.handleOnKeyDownNumericInput=b;exports.handleOnPasteNumericInput=C;exports.replaceCommasWithDots=g;exports.sanitizeNumericInput=o;exports.trimToMaxDecimals=a;
|
package/dist/index.mjs
CHANGED
|
@@ -69,5 +69,12 @@ class N {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
72
|
-
N as NumericInput
|
|
72
|
+
N as NumericInput,
|
|
73
|
+
f as alreadyHasDecimal,
|
|
74
|
+
A as handleOnChangeNumericInput,
|
|
75
|
+
I as handleOnKeyDownNumericInput,
|
|
76
|
+
x as handleOnPasteNumericInput,
|
|
77
|
+
L as replaceCommasWithDots,
|
|
78
|
+
p as sanitizeNumericInput,
|
|
79
|
+
o as trimToMaxDecimals
|
|
73
80
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "numora",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Framework-agnostic headless finance input library",
|
|
5
|
+
"homepage": "https://numora.netlify.app/",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
@@ -9,9 +10,9 @@
|
|
|
9
10
|
],
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
12
14
|
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.js"
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
+
"require": "./dist/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|