Skip to main content

module getting started

neo-jquery using as node frontend module CJS and ESM import mode.

this module is the main one to use the concepts of DOM, ES6+ and to know the basics of ajax.

using neo-jquery

it has a size of almost 2KB which is much smaller than jQuery and beneficial for the correct functioning it is compatible with webpack and cjs electron and indepent script for browser.

browser

<!--main file-->
<script src="https://cdn.jsdelivr.net/npm/neo-jquery/browser/index.js"></script>
// id
const hello = $id('hello-world')

hello.textContent = 'hello world'

module

/* CJS */
const neoJquery = require('neo-jquery/core') // full module
const { $id } = require('neo-jquery/core') // destructuring module

/* ESM */
import neoJquery from 'neo-jquery/core' // full module
import { $id } from 'neo-jquery/core' // destructuring module

/* dynamic import promise */
import('neo-jquery/core')
.then(({ $id }) => {
.....
})

/* async/await and top level await*/
const { $id } = await import('neo-jquery/core')

dynamic import is compatible with CJS

functions

$id function

$id('hello-world');
desctype
param: elstring
returnHTMLElement

$selector function

$selector('hello-world');
desctype
param: elstring
returnElement | null

$selectorAll function

$selectorAll('hello-world');
desctype
param: elstring
returnNodeListOf<Element>

$createElement function

$createElement('h2');
desctype
param: elkeyof HTMLElementTagNameMap | string
returnHTMLElement

$root element

$root.classList.add('example')
type
HTMLElement

$body function

$body.textContent = 'hello world'
type
HTMLElement

$date function

$date() // param null
$data('2021-12-03') // with param
desctype
param: elnull | any
returnDate

$audio function

$audio() // without audio path
$audio('https://example.com/audio.mp3') // without audio path
desctype
param: path? (optional)string
returnHTMLAudioElement

using web audio api

$canvas function

<canvas id="draw" height="600" width="800"></canvas>
$canvas('#draw') // opt 1
const canvas = $canvas('#draw') // opt 2
desctype
param: idstring
returnHTMLCanvasElement
warning

only if know canvas api.

$getJSON function

$getJSON('http://jsonplaceholder.typicode.com/users', (data) => {
console.info(data)
})
desctype
param: urlstring
param: callback(param: any) => void
returnPromise<void>

$ajax function

$ajax({
url: 'http://jsonplaceholder.typicode.com/users',
type: 'get', // http method
data: JSON.stringify({
names: names,
typedoc: typedoc,
numdoc: Number(numdoc),
numtitulada: Number(numtitulada),
numcomplementarias: Number(numcomplementarias),
estado: estado,
certificado: Boolean(certificado)
}), // from data only in http post | put method
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
}, // except http get method
success(data) {
console.log(data)
},
failed(err) {
console.error(err)
}
})
desctype
params: { url, type, data, headers, dataType, success, failed }ajax
returnPromise<void>

ajax type params

propietytype
url (required)string
type (optional)string
data (optional)any
headers (optional)any
dataType (required)'text' | 'json' | 'blob'
success (required)(param: any) => void
failed (required)(param: any) => void

fadeIn function

const main = $selector('h1')

fadeIn(main);
desctype
param: elHTMLElement | Element
returnvoid

fadeOut function

const main = $selector('h1')

fadeOut(main);
desctype
param: elHTMLElement | Element
returnvoid

hide function

const main = $selector('h1')

hide(main);
desctype
param: elany
returnstring

show function

const main = $selector('h1')

show(main);
desctype
param: elany
returnstring

$toast method

new function add version 1.0.5 extract from stack-analyze desktop 5.0.0 higher

$toast('hello user', 'alert', 5000)
desctype
param: msgstring
param: classAlertstring
param: timenumber
returnvoid

$url

$url('https://example.com')
desctype
param: urlstring
returnURL