Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use natively as import in JS/TS NodeJS? #12

Open
dj-nuo opened this issue Mar 21, 2024 · 0 comments
Open

How to use natively as import in JS/TS NodeJS? #12

dj-nuo opened this issue Mar 21, 2024 · 0 comments

Comments

@dj-nuo
Copy link

dj-nuo commented Mar 21, 2024

Hi! Can somebody please provide guidance on how to use main parse function from app.cljc in order to get result as regular JS object?

Something like this (expected result):

{
 "id3v2-offset": 0,
 "mpeg": {
  "version": 1,
  "has-padding?": false,
  "sample-rate": 48000,
  "num-channels": 2,
  "bit-rate": 320000,
  "frame-length": 960,
  "num-samples": 1152,
  "header": [
   -1,
   -5,
   -28,
   68
  ],
  "layer": 3
 },
 "mpeg-valid?": true,
 "xing-tag?": false
}

So far I used this code in order to build for NodeJS, but then I cannot really import & use the parse function within my codebase:
clj -M -m cljs.main --target node --output-to main.js -c mp3-parser.app

Or, to be specific, I did manage to import the function, but then it provides very convoluted result.
How I imported:

var path = require('path');
try {
	require('source-map-support').install();
} catch (err) {}
require('../goog/bootstrap/nodejs');
require('../cljs_deps');
goog.global.CLOSURE_UNCOMPILED_DEFINES = { 'cljs.core._STAR_target_STAR_': 'nodejs' };
goog.require('cljs.nodejscli');
goog.require('cljs.core');
goog.require('mp3_parser.app');

How I used the import:
const result = mp3_parser.app.parse(mp3FilePath);

Result that I got:

{
	tree: {
		key: {
			ns: null,
			name: 'mpeg',
			fqn: 'mpeg',
			_hash: -1021588107,
			cljs$lang$protocol_mask$partition0$: 2153775105,
			cljs$lang$protocol_mask$partition1$: 4096,
		},
		val: {
			meta: null,
			cnt: 9,
			root: {
				edit: null,
				bitmap: 436559874,
				arr: [
					{
						ns: 'mp3-parser.mpeg',
						name: 'version',
						fqn: 'mp3-parser.mpeg/version',
						_hash: 81018049,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					1,
					null,
					{
						edit: {},
						bitmap: 1048704,
						arr: [
							{
								ns: 'mp3-parser.mpeg',
								name: 'has-padding?',
								fqn: 'mp3-parser.mpeg/has-padding?',
								_hash: -367653651,
								cljs$lang$protocol_mask$partition0$: 2153775105,
								cljs$lang$protocol_mask$partition1$: 4096,
							},
							false,
							{
								ns: 'mp3-parser.mpeg',
								name: 'sample-rate',
								fqn: 'mp3-parser.mpeg/sample-rate',
								_hash: -978390387,
								cljs$lang$protocol_mask$partition0$: 2153775105,
								cljs$lang$protocol_mask$partition1$: 4096,
							},
							48000,
							null,
							null,
							null,
							null,
						],
						cljs$lang$protocol_mask$partition1$: 131072,
						cljs$lang$protocol_mask$partition0$: 0,
					},
					{
						ns: 'mp3-parser.mpeg',
						name: 'num-channels',
						fqn: 'mp3-parser.mpeg/num-channels',
						_hash: -1961528722,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					2,
					{
						ns: 'mp3-parser.mpeg',
						name: 'bit-rate',
						fqn: 'mp3-parser.mpeg/bit-rate',
						_hash: 561072816,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					320000,
					{
						ns: 'mp3-parser.mpeg',
						name: 'frame-length',
						fqn: 'mp3-parser.mpeg/frame-length',
						_hash: 407983954,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					960,
					{
						ns: 'mp3-parser.mpeg',
						name: 'num-samples',
						fqn: 'mp3-parser.mpeg/num-samples',
						_hash: -345617735,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					1152,
					{
						ns: 'mp3-parser.mpeg',
						name: 'header',
						fqn: 'mp3-parser.mpeg/header',
						_hash: 214035803,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					{
						meta: null,
						cnt: 4,
						shift: 5,
						root: {
							edit: null,
							arr: [
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
							],
						},
						tail: [-1, -5, -28, 68],
						__hash: null,
						cljs$lang$protocol_mask$partition0$: 167666463,
						cljs$lang$protocol_mask$partition1$: 139268,
					},
					{
						ns: 'mp3-parser.mpeg',
						name: 'layer',
						fqn: 'mp3-parser.mpeg/layer',
						_hash: -1558617700,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					3,
				],
				cljs$lang$protocol_mask$partition1$: 131072,
				cljs$lang$protocol_mask$partition0$: 0,
			},
			has_nil_QMARK_: false,
			nil_val: null,
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 16123663,
			cljs$lang$protocol_mask$partition1$: 139268,
		},
		left: {
			key: {
				ns: null,
				name: 'id3v2-offset',
				fqn: 'id3v2-offset',
				_hash: -44725623,
				cljs$lang$protocol_mask$partition0$: 2153775105,
				cljs$lang$protocol_mask$partition1$: 4096,
			},
			val: 0,
			left: null,
			right: null,
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 166619935,
			cljs$lang$protocol_mask$partition1$: 0,
		},
		right: {
			key: {
				ns: null,
				name: 'mpeg-valid?',
				fqn: 'mpeg-valid?',
				_hash: -328426969,
				cljs$lang$protocol_mask$partition0$: 2153775105,
				cljs$lang$protocol_mask$partition1$: 4096,
			},
			val: true,
			left: null,
			right: {
				key: {
					ns: null,
					name: 'xing-tag?',
					fqn: 'xing-tag?',
					_hash: -1695319398,
					cljs$lang$protocol_mask$partition0$: 2153775105,
					cljs$lang$protocol_mask$partition1$: 4096,
				},
				val: false,
				left: null,
				right: null,
				__hash: null,
				cljs$lang$protocol_mask$partition0$: 166619935,
				cljs$lang$protocol_mask$partition1$: 0,
			},
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 166619935,
			cljs$lang$protocol_mask$partition1$: 0,
		},
		__hash: null,
		cljs$lang$protocol_mask$partition0$: 166619935,
		cljs$lang$protocol_mask$partition1$: 0,
	},
	cnt: 4,
	meta: null,
	__hash: null,
	cljs$lang$protocol_mask$partition0$: 418776847,
	cljs$lang$protocol_mask$partition1$: 8192,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant