Sleavely / Bark-JS

🔬 Parse barcode inputs 🏷️ in a unified GS1-128 format 📦🌐
Other
28 stars 8 forks source link

_this.fixedLength is not a function #30

Closed Uzef1997 closed 2 years ago

Uzef1997 commented 2 years ago

Information :-

System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Memory: 559.27 MB / 7.82 GB Binaries: Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 28, 30, 33 Build Tools: 30.0.2, 33.0.0 System Images: android-30 | Google APIs Intel x86 Atom Android NDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: Not Found Languages: Java: Not Found npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.4 => 0.66.4 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

I got this error when i tried to parse value of gs128 type barcode which is having expiry date here is the barcode which i tried to parse image

here is the error which i am getting image

Please help me thank you

Uzef1997 commented 2 years ago

Information :-

System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz Memory: 559.27 MB / 7.82 GB Binaries: Node: 16.13.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 28, 30, 33 Build Tools: 30.0.2, 33.0.0 System Images: android-30 | Google APIs Intel x86 Atom Android NDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: Not Found Languages: Java: Not Found npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.4 => 0.66.4 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

I got this error when i tried to parse value of gs128 type barcode which is having expiry date here is the barcode which i tried to parse image

here is the error which i am getting image

Please help me thank you

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch bark-js@1.2.0 for the project I'm working on.

Here is the diff that solved my above problem:

diff --git a/node_modules/bark-js/src/gs1/dataReaders.js b/node_modules/bark-js/src/gs1/dataReaders.js
index ae0fe4a..4531f6c 100644
--- a/node_modules/bark-js/src/gs1/dataReaders.js
+++ b/node_modules/bark-js/src/gs1/dataReaders.js
@@ -1,7 +1,7 @@

 const injectDecimal = require('./utils/injectDecimal')

-exports.fixedLength = (length) => ({
+export const fixedLength = (length) => ({
   barcode,
   fnc = String.fromCharCode(29),
 }) => {
@@ -46,7 +46,7 @@ exports.fixedLengthDecimal = (length, decimalPositionFromEnd) => ({
   barcode,
   fnc = String.fromCharCode(29),
 }) => {
-  const { value: originalValue, raw } = this.fixedLength(length)({ barcode, fnc })
+  const { value: originalValue, raw } = fixedLength(length)({ barcode, fnc })
   const value = injectDecimal(originalValue, decimalPositionFromEnd)
   return {
     value,
@@ -115,7 +115,8 @@ exports.date = () => ({
   barcode,
   fnc = String.fromCharCode(29),
 }) => {
-  const { value: yymmdd, raw } = this.fixedLength(6)({ barcode, fnc })
+
+  const { value: yymmdd, raw } = fixedLength(6)({ barcode, fnc })

   const year = parseInt(yymmdd.slice(0, 2), 10)
   const month = yymmdd.slice(2, 4)
@@ -142,7 +143,7 @@ exports.dateTime = ({ optionalMinutesAndSeconds = false } = {}) => ({
   barcode,
   fnc = String.fromCharCode(29),
 }) => {
-  const { value: yymmddhhmm, raw } = this.fixedLength(optionalMinutesAndSeconds ? 12 : 10)({ barcode, fnc })
+  const { value: yymmddhhmm, raw } = fixedLength(optionalMinutesAndSeconds ? 12 : 10)({ barcode, fnc })

   const { value: yymmdd } = this.date()({
     barcode: yymmddhhmm.slice(0, 6),
Sleavely commented 2 years ago

First off, thanks for the thorough report!

This seems related to #13 and #23 which are partially fixed by #24 (which is basically the same as the diff you posted). I would love to know more about your build process to understand what may be causing the issue - are you using Rollup, Webpack, Esbuild or similar? Could you share you build config here?

Regardless, since it seems to be a recurring problem I will merge and publish a patch this weekend.

Uzef1997 commented 2 years ago

Hello there i am using webpack