Skip to content

JavaScripts (mostly moved from my `scripts` repository)

License

Notifications You must be signed in to change notification settings

kekse1/javascripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Every JavaScript is made by myself, arose out of necessity.. or because I found it interesting.

Note

For the future I'm planning to sort all the scripts in here by their line counts. JFYI..

Note

I think most scripts should run 'as is', due to the nature of vanilla JavaScript. As interpreter I'm mostly using the nice Node.js.

Tip

You could also take a look at my make-nodejs.sh script within my own Scripts repository. This makes it easier and more elegant to manage even multiple versions of Node.js.

Note

JFYI: I really dislike npm.js and the inclusion of so many modules I could write by myself as well. Don't expect me to use 'em.

Index

  1. News
  2. Scripts
  3. Contact
  4. Copyright and License

News

JavaScripts

My favorite language.. absolutely. ^_^

Many, many years ago I just laughed about JavaScript, because it was just some 'browser scripting language'.. TODAY, in the times of Node.js, it's a great language, even for the server side! ;-)

Every script is made by myself, arose out of necessity.. or because I found it interesting.

Got it's own repository dump.js

With this script, you can calculate and convert between offsets and lines with columns, or count them, etc. Without any parameter it'll show you the whole countings, and with another parameter combination you can even get to know how many columns a specific line has.

Tip

Start with the argv parameter --help or -?. ;-)

My Reflect.clone() extension (because JavaScript doesn't include it natively)..

.. and it works great, really! :-) Also checks Reflect.isExtensible(), so even functions with extensions are being fully cloned. And even the functions themselves (if _function === true; see also DEFAULT_CLONE_FUNCTION).. and - utilizing a Map - every instance will only get cloned once, so no circular dependencies occure! ;-)

[!INFO] Since v0.5.0 the function also supports any type of TypedArray.

Using a regular .json file/structure. But with improved handling.

Important

It ain't runnable in a regular JavaScript environment, since it's using extensions I've only got in my own code. But the algorithms and structures should be correct and clear when you are looking in the code for yourself.

Example given: { server: { host: 'localhost', { http: { port: 8080 } } } }; You can .get('server.http.host'); and nevertheless get the host above it.

It's possible to receive an array with all upper definitions, and via _index argument to select one (-1 for the last, deepest one, e.g.). You can also FORCE a concrete item without parents, see '.force()'.

The .with() function is meant for e.g. { enabled: (bool) }. It checks all upper occurencies, if there's at least one (false/true) value. So you can 'globally' disable/enable smth., even if deeper occurencies enable smth. I needed/wanted this; .. usable by .enabled() and .disabled() (chooses the test with one of true/false).

You can, btw., init with config object using {,static} wrap(_object, ..); or just argue with such a base object in any constructor argument. AND now you can also .extend() with kinda 'chroot' sub paths (so your query paths can start in a sub object).. and now, since v0.6.0 I also support the 'step-wise' traversing up the paths. So not only any chroot path, but every path item (see Configuration.delim)!

This class extracts all links from .html files. It should work better than regular expressions, since it covers many possible codes. And this class should be instanciated, so it also works with file chunks (this way, the input data does not have to be complete, which is great for streams; also to save memory, etc.).

And see the DEFAULT_ATTRIBS = [ 'href', 'src' ];; or maybe define a filter, like the DEFAULT_SCHEME = [ 'http:', 'https:' ], so only these links will remain in the result array; you can also instanciate with a source param or attrib: from which URL this HTML document comes from, so the links are adapted to it (relative links could be a problem otherwise).

Since v0.4.0 also with DEFAULT_UNIQUE = true; extra .extract() function (original .onData() was meant for stream events); plus some improvements and bugs fixed. And more big changes since v0.5.0.

PLUS: since v0.8.0 it can extract ALL links, not only those from HTML codes; e.g. text/plain; BUT you need (beneath .all or DEFAULT_ALL) also at least one .scheme[] item..

Nice one; have phun.

This is radix/base conversion, but only for bytecode (so radix/base 256). Here's only the BigInt part, for regular Integers you could change it a bit, or you use the 'power' of Typed Arrays (which I don't like that much..).

You could use it for more efficient encoding of numbers, on disk or via network transmission, etc.

My solution for JavaScript's instanceof problem, so when in multiple environments the classes are initialized/declared not once. In this case, comparing two environments, it's like Array !== Array, e.g.. and I don't mean only the instances, the base classes are being created multiple times in multiple environments..

So I'm using [Reflect.]is() and [Reflect.]was() (for a long time, so it's well tested, and works great). You'll find more description in this reflection.js, in the starting comment on top of the file.

Important

Since v2.1.0 the additional was() parameters (varargs) mean AND, not OR any longer.. but the is() stayed the same (OR);

Tip

In v3.1.0 improved/fixed Object.{has,get,set,remove}()** (traversing functions)!

Intersection for Arrays. Works with any data type (so no optimization like binary search possible here), and respects multiple occurences (if no (true) is in your arguments).

Depends on my multiset.js!!

My MultiSet class: extends Map, but works like a Set, with the difference that it also counts the amount of items in this set.

String extensions to support C {un,}escaping. Example given \n is the newline character.

Supports both escaping and unescaping. The latter will produce strings with the encoded values, so \n will become a real newline byte, and the first one will encode the string \n out of the \10 byte code.

Tip

Count and/or convert your text files with this little tool (instead of the old dos2unix etc.)!

Counts any occurence of various (UNIX, DOS, MAC) newlines if called without additional parameters; as follows:

  • -d / --dos
  • -u / --unix
  • -m / --mac
  • [ -c / --count ]

They define the optional target format to which the input will be converted to. Optional, and only one of them per call (last occurence rules).

If stdin is being filled, no additional file path parameter will be used. Or define any amount of file paths - they get used in order. The - file is also allowed (also stdin).

Files that don't exist or files with open/read errors will always throw an exception.

stdout is the place where either the count result will be, or with enabled conversion stdout is the place for the new data - stderr in this case for the count summary at the end.

Two functions to measure the throughput of your data, in bytes per second (just remove the multiplication with 1000 für milliseconds); and the ETA ('Estimated Time Of Arrival') w/ .remaining(), in milliseconds (multiply *1000 for seconds).

This is just a link to the only animation.js of my v4 project.

Some extensions to the Web Animations API; very necessary for my special needs.. it's also the one with the most lines.

Maybe useful for you? But you've to read the source for yourself; and some functions may be missing; then look at my v4 source code!

Extends the Date object with moon phase calculation functions.

[!WARN] MAYBE old version?? For more, partially very useful Date extensions take a look (for docs and concrete code):

I'm a bit embarrassed about this script - it's just so really tiny and nothing..

But I really needed it one time. Read the description in the comment on top of this file.

Little 'toy'! "Maps" some counted values in a coordinate system, so it draws kinda chess board .. in your console/terminal! ;-)

example()

DEPENDS on my own library, so you've to adapt this script for your own!

It's merely kinda proof of concept that state parsers can be as good as regular expressions, or even better! ;-D See also this discussion;

'Folds' CSS style code. Earlier I used the fold (Linux) command, but that didn't work that well for what I needed the resulting code: had to filter out CSS classes in .html code and grep for them in many .css files - since grep is for lines, and cut is too stupid, .. I couldn't find the CSS styles in stylesheets without newlines, etc. ..

The reason for this script was: I wanted to 'import' GitHub's markdown .css code, since my website provides all my GitHub repositories, and I needed only some parts out of there.. but the code is/was a mess!

Important

Early version, so only the real basics are covered.

Contact

Copyright and License

The Copyright is (c) Sebastian Kucharczyk, and it's licensed under the MIT (also known as 'X' or 'X11' license).

Favicon

About

JavaScripts (mostly moved from my `scripts` repository)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published