Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

load-ini

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-ini - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

55

dist/index.cjs.js

@@ -242,2 +242,29 @@ 'use strict';

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
function arrayFromNested(data) {
const keys = Object.keys(data);
for (const key of keys) {
if (!/^\d+$/.test(key))
return data;
}
return Array.from(__spreadValues({
length: keys.length
}, data));
}
var __async = (__this, __arguments, generator) => {

@@ -271,23 +298,11 @@ return new Promise((resolve, reject) => {

function parseIni(data) {
try {
return ini.parse(stripBom(data));
} catch (err) {
console.error(err);
return null;
}
return arrayFromNested(ini.parse(stripBom(data)));
}
function stringifyIni(data, options) {
try {
return ini.stringify(data, options);
} catch (err) {
console.error(err);
return null;
}
return ini.stringify(data, options);
}
function loadIni(path) {
return __async(this, null, function* () {
if (!fs.existsSync(path)) {
console.error(`${path} is not exists`);
return null;
}
if (!fs.existsSync(path))
throw new Error(`${path} is not exists`);
return parseIni(yield fs.promises.readFile(path, "utf8"));

@@ -297,9 +312,7 @@ });

function loadIniSync(path) {
if (!fs.existsSync(path)) {
console.error(`${path} is not exists`);
return null;
}
if (!fs.existsSync(path))
throw new Error(`${path} is not exists`);
return parseIni(fs.readFileSync(path, "utf8"));
}
const version = "1.0.0";
const version = "1.1.0";

@@ -306,0 +319,0 @@ exports.loadIni = loadIni;

@@ -1,2 +0,31 @@

import { EncodeOptions } from 'ini';
export declare interface EncodeIniOptions {
/**
* to specify whether to align the = characters for each section. This option will automatically enable whitespace. Defaults to false.
*/
align?: boolean;
/**
* which will be the first section in the encoded ini data. Defaults to none.
*/
section?: string;
/**
* to specify if all keys in each section, as well as all sections, will be alphabetically sorted. Defaults to false.
*/
sort?: boolean;
/**
* to specify whether to put whitespace around the = character. By default, whitespace is omitted, to be friendly to some persnickety old parsers that don't tolerate it well. But some find that it's more human-readable and pretty with the whitespace. Defaults to false.
*/
whitespace?: boolean;
/**
* to specify whether to put an additional newline after a section header. Some INI file parsers (for example the TOSHIBA FlashAir one) need this to parse the file successfully. By default, the additional newline is omitted.
*/
newline?: boolean;
/**
* to define which platform this INI file is expected to be used with: when platform is win32, line terminations are CR+LF, for other platforms line termination is LF. By default, the current platform name is used.
*/
platform?: string;
/**
* to specify whether array values are appended with []. By default this is true but there are some ini parsers that instead treat duplicate names as arrays.
*/
bracketedArrays?: boolean;
}

@@ -14,3 +43,3 @@ /**

*/
export declare function loadIni(path: string): Promise<Record<string, unknown> | null>;
export declare function loadIni(path: string): Promise<Record<string, unknown> | unknown[]>;

@@ -28,3 +57,3 @@ /**

*/
export declare function loadIniSync(path: string): Record<string, unknown> | null;
export declare function loadIniSync(path: string): Record<string, unknown> | unknown[];

@@ -37,3 +66,3 @@ /**

*/
export declare function parseIni(data: string): Record<string, unknown> | null;
export declare function parseIni(data: string): Record<string, unknown> | unknown[];

@@ -44,6 +73,6 @@ /**

* @param data - file path
* @param options - stringify options: EncodeOptions
* @param options - stringify options: EncodeIniOptions
* @returns - result
*/
export declare function stringifyIni<T>(data: T, options?: EncodeOptions): string | null;
export declare function stringifyIni<T>(data: T, options?: EncodeIniOptions | string): string;

@@ -50,0 +79,0 @@ export declare const version: string;

@@ -240,2 +240,29 @@ import { existsSync, readFileSync, promises } from 'fs';

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
function arrayFromNested(data) {
const keys = Object.keys(data);
for (const key of keys) {
if (!/^\d+$/.test(key))
return data;
}
return Array.from(__spreadValues({
length: keys.length
}, data));
}
var __async = (__this, __arguments, generator) => {

@@ -269,23 +296,11 @@ return new Promise((resolve, reject) => {

function parseIni(data) {
try {
return ini.parse(stripBom(data));
} catch (err) {
console.error(err);
return null;
}
return arrayFromNested(ini.parse(stripBom(data)));
}
function stringifyIni(data, options) {
try {
return ini.stringify(data, options);
} catch (err) {
console.error(err);
return null;
}
return ini.stringify(data, options);
}
function loadIni(path) {
return __async(this, null, function* () {
if (!existsSync(path)) {
console.error(`${path} is not exists`);
return null;
}
if (!existsSync(path))
throw new Error(`${path} is not exists`);
return parseIni(yield promises.readFile(path, "utf8"));

@@ -295,10 +310,8 @@ });

function loadIniSync(path) {
if (!existsSync(path)) {
console.error(`${path} is not exists`);
return null;
}
if (!existsSync(path))
throw new Error(`${path} is not exists`);
return parseIni(readFileSync(path, "utf8"));
}
const version = "1.0.0";
const version = "1.1.0";
export { loadIni, loadIniSync, parseIni, stringifyIni, version };
{
"name": "load-ini",
"description": "Read and parse a .ini file",
"version": "1.0.0",
"version": "1.1.0",
"packageManager": "pnpm@8.6.12",

@@ -47,3 +47,2 @@ "main": "./dist/index.cjs.js",

"dependencies": {
"@types/ini": "^1.3.31",
"ini": "^4.1.1",

@@ -65,2 +64,3 @@ "tslib": "^2.6.1"

"@rollup/plugin-typescript": "^11.1.2",
"@types/ini": "^1.3.31",
"@types/jest": "^29.5.3",

@@ -67,0 +67,0 @@ "@types/node": "^20.5.0",

@@ -77,3 +77,3 @@ <div style="text-align: center;" align="center">

- Returns: `object | null`
- Returns: `object | array`

@@ -92,3 +92,3 @@ - Example:

```ts
declare function loadIni(path: string): Promise<Record<string, unknown> | null>
declare function loadIni(path: string): Promise<Record<string, unknown> | unknown[]>
```

@@ -108,3 +108,3 @@

- Returns: `object | null`
- Returns: `object | array`

@@ -121,3 +121,3 @@ - Example:

```ts
declare function loadIniSync(path: string): Record<string, unknown> | null
declare function loadIniSync(path: string): Record<string, unknown> | unknown[]
```

@@ -137,3 +137,3 @@

- Returns: `object | null`
- Returns: `object | array`

@@ -154,3 +154,3 @@ - Example:

```ts
declare function parseIni(data: string): Record<string, unknown> | null
declare function parseIni(data: string): Record<string, unknown> | unknown[]
```

@@ -166,7 +166,7 @@

| Parameters | Description | Type | Optional | Required | Default |
| ---------- | ----------- | -------- | -------- | -------- | ------- |
| data | object data | `object` | - | true | - |
| Parameters | Description | Type | Optional | Required | Default |
| ---------- | ----------- | ---------------- | -------- | -------- | ------- |
| data | object data | `object` `array` | - | true | - |
- Returns: `string | null`
- Returns: `string`

@@ -185,3 +185,3 @@ - Example:

```ts
declare function stringifyIni<T>(data: T, options?: EncodeOptions): string | null
declare function stringifyIni<T>(data: T, options?: EncodeOptions): string
```

@@ -188,0 +188,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc