Gathering detailed insights and metrics for work-with-net
Gathering detailed insights and metrics for work-with-net
Gathering detailed insights and metrics for work-with-net
Gathering detailed insights and metrics for work-with-net
aeza-net-sdk
A library that allows you to work with the AEZA.NET hosting API
auth-net-cap
Work with the AuthNetCap in a common way for iOS, Android, and web
rinvoke
RPC library based on net sockets, can work both with tcp sockets and ipc
literable
A library for work with iterators inspired in .Net LINQ
npm install work-with-net
Typescript
Module System
Node Version
NPM Version
76.2
Supply Chain
98.7
Quality
76.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
931
Last Day
4
Last Week
6
Last Month
20
Last Year
291
MIT License
4 Stars
19 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Feb 04, 2025
Minified
Minified + Gzipped
Latest Version
0.3.2
Package Id
work-with-net@0.3.2
Unpacked Size
193.94 kB
Size
43.63 kB
File Count
24
NPM Version
6.14.17
Node Version
14.20.0
Published on
Feb 04, 2025
Cumulative downloads
Total Downloads
Last Day
300%
4
Compared to previous day
Last Week
100%
6
Compared to previous week
Last Month
33.3%
20
Compared to previous month
Last Year
34.1%
291
Compared to previous year
English | Русский
Library for working with data received from the network. Very often, when working with AJAX requests, we receive data in base64 format, or data in binary format. You won't be able to display them just like that. This library contains modules that convert file extensions to mime types, mime types to regular file extensions. Modules that allow you to download files received by an AJAX request, open this data in a new tab, work with base64.
In order to install this library, you need to type in the console:
npm i work-with-net
After installation, you can include both the library itself and its specific modules.
By default, my library contains about 800 mime types, thanks for that Robert Kieffer. That's a lot, but it will work for everything. The size, however, will be about 40kb. If you need standard extensions, then connect the most common types:
With this connection, the size will be approx 3kb. There are only the most typical extensions. Initially, my task was to make a chat for working with a manager, it was assumed that the user through this chat would correspond with the manager, upload or download documents from him. The list of extensions was provided to me, I did not add much to it. Let me attach it:
As you can see, these are the most common extensions for working with documents, archives, pictures. The chat was businesslike, it was impossible to put music there, in the future I will probably fix it.
If you need support for IE 11, then include the library as follows:
I want to say right away that I did not check for 11 IE, connect at your own risk.
To get the mime type from a file extension use the getMimeType ('file extensions') function. This will probably not be useful to you, in most cases you will get file extensions from the mime type. There is a function getFileExtension ('mime type') for this. If you have included the entire library then:
If you get a file from an AJAX request (it is in binary in the database, I use blob to transform it). Then to download it, use the downloadFile function ('file in binary', 'mime type', 'filename'). Look, you definitely need the file itself, and its mime type. Mime type usually lies in the response header (Content-Type). If the file name is not specified, then when downloading the file name will contain the date in milliseconds since 1970. If you downloaded something through the state portal. services, then there the files are downloaded as well. If you need to generate a name somehow specifically, then set 3 parameters, so it is not required.
If you need to open a file in a new tab, then use the openFile function ('file in binary'). As a rule, the task can be such that we open pdf-files in a new tab, and all other files need to be downloaded. Accordingly, from the "Content-Type" we get the mime type of the file, transform it via 'getFileExtension' and, depending on its extension, call either 'getFileExtension' or 'getMimeType'. There is one thing, but not all files can be opened in a browser. The pdf document will open, but the ISO image is not, it will be downloaded from you. There is nothing you can do about it.
There are times when you don't need to know its mime type to download a file. For example, you know in advance that jpeg images will come to you by AJAX request. Or another option, you need to generate a torrent file. To do this, there is a function downloadFileByExt('file in binary form, 'its extension', 'file name'). Look, you need the file itself, the default extension is jpeg (if you need to generate jpeg, then you can not set the extension). The filename is also optional. If you don't specify a filename, the downloaded filename will contain the date in milliseconds since 1970. This function will be faster than downloadFile because the file extension will not be calculated under the hood.
If you have included a library, and not individual modules, then:
To work with base64, the following functions are used: base64Code, base64Encode, base64FileEncode, convertBase64ToBinary;
If you have included a library, and not individual modules, then:
At first glance, this is a simple problem. What could be easier than generating a CSV in javascript, but when I started solving it, I had a lot of problems.
The first problem was with the encoding. All examples on the net were from English-language forums. They all worked well. In my case, the text contained Cyrillic, as a result, it was not displayed as it should be in excel. After half an hour of searching, I found a solution, I had to substitute 3 characters for the BOM encoding.
The second problem was that the text was in one column. The guys here helped me. It was necessary to use ";" as a separator.
In general, it became clear that this is the case for my library. In order to generate a CSV file in my library there is a downloadCSV function. It takes 2 parameters, an array of arrays from which I will build the CSV file, and a file name. The filename is optional. If it is not set, the time in milliseconds since 1970 will be substituted. Let me give you a better example to illustrate.
import { downloadCSV } from 'work-with-net';
const csvArr = [
[1, 2, 3],
['какой-то текст 1', '"' + 'какой-то ; \\n текст 2' + '"', 'какой-то текст 3'],
[1, 2, 3],
];
downloadCSV(csvArr, 'example');
As you can see from the example, each array in csvArr is a line in the resulting CSV file. Naturally, all control characters must be escaped, if your string contains ";", then you will need to follow the example of the second array.
If you included the library, and not individual modules, then the final code will look like this:
import workWithNet from 'work-with-net';
const csvArr = [
[1, 2, 3],
['какой-то текст 1', '"' + 'какой-то ; \\n текст 2' + '"', 'какой-то текст 3'],
[1, 2, 3],
];
workWithNet.downloadCSV(csvArr, 'example');
No vulnerabilities found.
No security vulnerabilities found.