How to import jregex library to ballerina app - libraries

I’m trying to validate regex in Ballerina using library samjs/jregex from https://central.ballerina.io/samjs/jregex
I’m trying to get this executed:
import ballerina/io;
import samjs/jregex;
public function main() {
//io:println(Commons:isValidDateTime("dupa"));
jregex:Pattern p = jregex:compile(regex = ".r");
jregex:Matcher m = p.matcher(input = "br");
var b = m.matches();
io:println(b);
}
I have run command ballerina pull samjs/jregex
My Ballerina.toml is:
[project]
org-name= "organization"
version= "0.1.0"
[platform]
target= "java8"
[[platform.libraries]]
artifactId = "mssql-jdbc"
version = "8.2.0"
path = "./mssql-jdbc-8.2.0.jre8.jar"
[dependencies]
However this is not working, because I’m getting error:
error: module not found: ballerinax/java:*_java8 or ballerinax/java:*_anyerror: samjs/jregex:0.2.0::/src/jregex/matcher.bal:1:1: cannot resolve module 'ballerinax/java'
error: module not found: ballerinax/java:*_java8 or ballerinax/java:*_any
error: samjs/jregex:0.2.0::/src/jregex/pattern.bal:1:1: cannot resolve module 'ballerinax/java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:85:29: undefined module 'java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:85:29: undefined function 'fromString'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:128:69: undefined module 'java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:128:69: undefined annotation 'Method'
it seems that import of jregex requires ballerinax, however I cannot import to code anything that is not directly used (Ballerina does not allow for "empty" imports).
Does anybody knows how to import this regex library to make it working in application?

Related

How to uses packages for the flutter app in the dart server?

My project has 3 sub-project including
dart_server
flutter_app
share
The share project is about objects, config, and paths, ... which was used in the dart_server and flutter_app projects.
In the share project. Some objects contain a package used for the flutter like the [get][1] package and this object is used for both projects (dart_server and flutter_app). When using this object in the dart_server project, it will error and the terminal will show an error too long.
error example:
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:299:35: Error: Type 'Offset' not found.
void addPosition(Duration time, Offset position) {
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:317:3: Error: Type 'Offset' not found.
Offset _previousVelocityAt(int index) {
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:24:58: Error: Undefined name 'Offset'.
static const Velocity zero = Velocity(pixelsPerSecond: Offset.zero);
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/gestures/velocity_tracker.dart:27:9: Error: 'Offset' isn't a type.
final Offset pixelsPerSecond;
^^^^^^
This can reproduce by creating a dart server project and import any package for the flutter like [get][1] in the file that will run and run this server by dart run.
How to use this object that contains packages for the flutter app?

dart:html not found -> cannot use WebSockets

I'm trying to build a WebSocket client app for my C# server and fail already at importing basic dart libraries:
bin/rpc_dart_test.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html';
^
bin/rpc_dart_test.dart:50:16: Error: Couldn't find constructor 'WebSocket'.
var ws = new WebSocket("ws://localhost:7077/ws");
^^^^^^^^^
bin/rpc_dart_test.dart:51:24: Error: 'MessageEvent' isn't a type.
ws.onMessage.listen((MessageEvent e) {
^^^^^^^^^^^^
bin/rpc_dart_test.dart:54:38: Error: Undefined name 'WebSocket'.
if (ws != null && ws.readyState == WebSocket.OPEN) {
^^^^^^^^^
How can I make this work? Just removing the import line as recommended in some Google results only makes the first error go away, but doesn't help in general. Changing from dart:html to package:http/http.dart neither works, because there is no WebSocket class in that package.

Loading R package iZID for simulating zero-inflated distribution

I am currently working on a project on zero-inflated models. I wish to simulate a sample of zero-inflated poisson distribution. When I type
install.packages("iZID")
library(iZID)
I got following error:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()),
versionCheck = vI[[j]]) :
namespace 'foreach' 1.4.4 is already loaded, but >= 1.4.7 is required
Error: package or namespace load failed for 'iZID'

No type named 'Error' in module 'Foundation'

I have created a class named Error. Now, there's also the class Error in Foundation and I still need to be able to access that one.
What I usually do in this case is apply proper namespacing:
Foundation.Error
However, I am getting the following error message:
No type named 'Error' in module 'Foundation'
I've checked the documentation to verify that Error is actually from Foundation:
What am I doing wrong?
The Error protocol
is defined in the Swift Standard Library. You don't even need to import
Foundation in order to use it:
$ swift
Welcome to Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1). Type :help for assistance.
1> var e: Error?
e: Error? = nil
2>
The fully qualified name is therefore Swift.Error.
The (useful) localizedDescription property however is defined in the Foundation
framework, as a protocol extension method.

RollupJS: Unresolved internal dependency

I'm getting an error that looks like it's unable to resolve my import to my other module.
Running rollup -c I'm getting the following error
(!) Unresolved dependencies
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency
components/main/view (imported by src\index.js)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
C:\Users\n88040\AppData\Roaming\npm\node_modules\rollup\dist\rollup.js (guessing 'View')
src/index.js
import View from 'components/main/view`;
View();
src/components/main/view.js
const View = () => console.log('foo');
export default View;
See https://rollupjs.org/guide/en#es-module-syntax
You have to import local dependencies with a leading period as otherwise it will be interpreted as an external dependency:
import View from './components/main/view';

Resources