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

calendarize

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calendarize - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

dist/index.js

15

index.d.ts

@@ -1,13 +0,2 @@

export type Bit = number;
export type Byte8 = [Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit];
export type Byte16 = [Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit];
export type Byte32 = [Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit,Bit];
export function convert(size: number, value: number): Bit[];
export function u8(value: number): Byte8;
export function u16(value: number): Byte16;
export function u32(value: number): Byte32;
export function from(text: string): Byte8[];
export function toString(values: Bit[] | Bit[][], glue = ''): string;
export type Week = [number,number,number,number,number,number,number];
export default function (target?: Date | string | number): Week[];
{
"version": "0.0.0",
"version": "1.0.0",
"name": "calendarize",
"repository": "lukeed/calendarize",
"description": "WIP",
"description": "A tiny (196B) utility to generate calendar views",
"module": "dist/index.mjs",

@@ -24,2 +24,5 @@ "unpkg": "dist/index.min.js",

"keywords": [
"calendar",
"utils",
"date"
],

@@ -26,0 +29,0 @@ "scripts": {

@@ -1,66 +0,52 @@

# totalist [![build status](https://badgen.now.sh/github/status/lukeed/totalist)](https://github.com/lukeed/totalist/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/totalist)](https://codecov.io/gh/lukeed/totalist)
# calendarize [![build status](https://badgen.net/github/status/lukeed/calendarize)](https://github.com/lukeed/calendarize/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/calendarize)](https://codecov.io/gh/lukeed/calendarize)
> A tiny (195B to 224B) utility to recursively list all (total) files in a directory
> A tiny (196B) utility to generate calendar views.
Traverse a directory recursively, running a function for **every file** found.
This function (optionally) accepts a date in exchange for a calendar view of that date's month.
With this module, you easily apply custom logic to decide which file(s) to process without worrying about accidentally accessing a directory or making repeat `fs.Stats` requests.
Additionally, this module is delivered as:
* **ES Module**: [`dist/calendarize.mjs`](https://unpkg.com/calendarize/dist/index.mjs)
* **CommonJS**: [`dist/calendarize.js`](https://unpkg.com/calendarize/dist/index.js)
* **UMD**: [`dist/calendarize.min.js`](https://unpkg.com/calendarize)
## Install
```
$ npm install --save totalist
$ npm install --save calendarize
```
## Modes
There are two "versions" of `totalist` available:
#### "async"
> **Node.js:** >= 8.x<br>
> **Size (gzip):** 224 bytes<br>
> **Availability:** [CommonJS](https://unpkg.com/totalist/dist/index.js), [ES Module](https://unpkg.com/totalist/dist/index.mjs)
This is the primary/default mode. It makes use of `async`/`await` and [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original).
#### "sync"
> **Node.js:** >= 6.x<br>
> **Size (gzip):** 195 bytes<br>
> **Availability:** [CommonJS](https://unpkg.com/totalist/sync/index.js), [ES Module](https://unpkg.com/totalist/sync/index.mjs)
This is the opt-in mode, ideal for scenarios where `async` usage cannot be supported.
## Usage
***Selecting a Mode***
***via Date Instance***
```js
// import via npm module
import totalist from 'totalist';
import totalist from 'totalist/sync';
import calendarize from 'calendarize';
const date = new Date('2019-12-20');
const view = calendarize(date);
//=> [
//=> [ 1, 2, 3, 4, 5, 6, 7],
//=> [ 8, 9, 10, 11, 12, 13, 14],
//=> [15, 16, 17, 18, 19, 20, 21],
//=> [22, 23, 24, 25, 26, 27, 28],
//=> [29, 30, 31, 0, 0, 0, 0],
//=> ]
```
***Example Usage***
***via Date String***
```js
import totalist from 'totalist/sync';
import calendarize from 'calendarize';
const styles = new Set();
const scripts = new Set();
totalist('src', (name, abs, stats) => {
if (/\.js$/.test(name)) {
scripts.add(abs);
if (stats.size >= 100e3) {
console.warn(`[WARN] "${name}" might cause performance issues (${stats.size})`);
}
} else if (/\.css$/.test(name)) {
styles.add(abs);
}
});
console.log([...scripts]);
//=> [..., '/Users/lukeed/.../src/path/to/example.css', ...]
const view = calendarize('Nov 01, 2019');
//=> [
//=> [ 0, 0, 0, 0, 0, 1, 2],
//=> [ 3, 4, 5, 6, 7, 8, 9],
//=> [10, 11, 12, 13, 14, 15, 16],
//=> [17, 18, 19, 20, 21, 22, 23],
//=> [24, 25, 26, 27, 28, 29, 30],
//=> ]
```

@@ -71,40 +57,20 @@

### totalist(dir, callback)
Returns: `void`
### calendarize(date?)
Returns: `Array<Week>`
> **Important:** The "async" usage must be `await`ed or included within a Promise chain.
An Array of `Week` Arrays is returned.<br>Each `Week` is an Array of 7 numbers, each representing a numerical date.
#### dir
Type: `string`<br>
Required: `true`
> **Important:** A zero (`0`) value represents a date that exists beyond the current month view.
The directory to traverse.
#### date
Type: `string` | `number` | `Date`<br>
Default: `new Date()` – aka, today
This may be a relative _or_ an absolute path.
The date you want to process.
> **Note**: Node.js will assume a relative path is meant to be resolved from the current location (`process.cwd()`).
> **Important**: Your `string|number` value will be cast to a `Date` object, which means Node.js may apply incorrect timezone!
#### callback
Type: `Function`<br>
Required: `true`
The callback function to run for _every_ file.
The function receives three parameters:
##### relPath
Type: `String`<br>
The path _relative to_ the initial `dir` value you provided.
##### absPath
Type: `String`<br>
The absolute path of the file.
##### stats
Type: `fs.Stats`<br>
The [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object for the file.
## License
MIT © [Luke Edwards](https://lukeed.com)
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