• Stars
    star
    136
  • Rank 266,732 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple and fast git helper functions.

@napi-rs/simple-git

https://github.com/Brooooooklyn/simple-git/actions Install size

Repository

Usage

import { Repository } from '@napi-rs/simple-git'

Repository.init('/path/to/repo') // init a git repository

const repo = new Repository('/path/to/repo') // Open an existed repo

const timestamp = new Date(repo.getFileLatestModifiedDate('build.rs')) // get the latest modified timestamp of a `build.rs`
console.log(timestamp) // 2022-03-13T12:47:47.920Z

const timestampFromAsync = new Date(await repo.getFileLatestModifiedDateAsync('build.rs')) // Async version of `getFileLatestModifiedDate`

console.log(timestamp) // 2022-03-13T12:47:47.920Z

API

export class Repository {
  static init(p: string): Repository
  constructor(gitDir: string)
  /** Retrieve and resolve the reference pointed at by HEAD. */
  head(): Reference
  getFileLatestModifiedDate(filepath: string): number
  getFileLatestModifiedDateAsync(filepath: string, signal?: AbortSignal | undefined | null): Promise<unknown>
}

Reference

Usage

import { Repository } from '@napi-rs/simple-git'

const repo = new Repository('/path/to/repo') // Open an existed repo

const headReference = repo.head()

headReference.shorthand() // 'main'
headReference.name() // 'refs/heads/main'
headReference.target() // 7a1256e2f847f395219980bc06c6dadf0148f18d

API

/** An enumeration of all possible kinds of references. */
export const enum ReferenceType {
  /** A reference which points at an object id. */
  Direct = 0,
  /** A reference which points at another reference. */
  Symbolic = 1,
  Unknown = 2
}
export class Reference {
  /**
   * Ensure the reference name is well-formed.
   *
   * Validation is performed as if [`ReferenceFormat::ALLOW_ONELEVEL`]
   * was given to [`Reference.normalize_name`]. No normalization is
   * performed, however.
   *
   * ```ts
   * import { Reference } from '@napi-rs/simple-git'
   *
   * console.assert(Reference.is_valid_name("HEAD"));
   * console.assert(Reference.is_valid_name("refs/heads/main"));
   *
   * // But:
   * console.assert(!Reference.is_valid_name("main"));
   * console.assert(!Reference.is_valid_name("refs/heads/*"));
   * console.assert(!Reference.is_valid_name("foo//bar"));
   * ```
   */
  static isValidName(name: string): boolean
  /** Check if a reference is a local branch. */
  isBranch(): boolean
  /** Check if a reference is a note. */
  isNote(): boolean
  /** Check if a reference is a remote tracking branch */
  isRemote(): boolean
  /** Check if a reference is a tag */
  isTag(): boolean
  kind(): ReferenceType
  /**
   * Get the full name of a reference.
   *
   * Returns `None` if the name is not valid utf-8.
   */
  name(): string | undefined | null
  /**
   * Get the full shorthand of a reference.
   *
   * This will transform the reference name into a name "human-readable"
   * version. If no shortname is appropriate, it will return the full name.
   *
   * Returns `None` if the shorthand is not valid utf-8.
   */
  shorthand(): string | undefined | null
  /**
   * Get the OID pointed to by a direct reference.
   *
   * Only available if the reference is direct (i.e. an object id reference,
   * not a symbolic one).
   */
  target(): string | undefined | null
  /**
   * Return the peeled OID target of this reference.
   *
   * This peeled OID only applies to direct references that point to a hard
   * Tag object: it is the result of peeling such Tag.
   */
  targetPeel(): string | undefined | null
  /**
   * Get full name to the reference pointed to by a symbolic reference.
   *
   * May return `None` if the reference is either not symbolic or not a
   * valid utf-8 string.
   */
  symbolicTarget(): string | undefined | null
}

Performance

Compared with the exec function, which gets the file's latest modified date by spawning a child process. Getting the latest modified date from the file 1000 times:

Child process took 1.9s
@napi-rs/simple-git took 65ms

More Repositories

1

canvas

High performance skia binding to Node.js. Zero system dependencies and pure npm packages without any postinstall scripts nor node-gyp.
Rust
1,635
star
2

ts-import-plugin

babel-import-plugin TypeScript Implement
TypeScript
567
star
3

learning-rxjs

Learning RxJS step by step
TypeScript
449
star
4

Image

Image processing library.
Rust
251
star
5

snappy

Fastest Snappy compression library in Node.js
Rust
119
star
6

uuid

Fastest RFC4122 UUIDs generator for Node.js
JavaScript
91
star
7

Clipboard

Manipulate Clipboard in Node.js via native API.
Rust
73
star
8

jsc-rs

JavaScript core Rust safe binding
Rust
67
star
9

redux-epics-decorator

Dumb decorators for redux & redux-observable & react-redux & redux-actions
TypeScript
59
star
10

blake-hash

Rust Blake hash bindings for Node.js.
Rust
36
star
11

sourcemap-decoder

https://github.com/getsentry/rust-sourcemap node bindings
Rust
33
star
12

woff-build

TTF to WOFF2
Rust
30
star
13

rust-to-nodejs-overhead-benchmark

Benchmark over Node.js binding frameworks in Rust
Rust
25
star
14

vercel-canvas

Sample Canvas App running on Vercel
HTML
23
star
15

ssh

https://github.com/warp-tech/russh Node.js binding
Rust
20
star
16

hns

Node.js http server framework powered by Hyper native binding.
TypeScript
19
star
17

sysinfo

System information
Rust
19
star
18

svg-to-pdf

Convert SVG to PDF
Rust
17
star
19

notify

https://github.com/notify-rs/notify Node.js binding via https://napi.rs
Rust
16
star
20

keyring-node

https://github.com/hwchen/keyring-rs Node.js binding via https://napi.rs. Including 100% compatible node-keytar alternative.
Rust
15
star
21

rxjs-webpack-treeshaking-example

Example for treeshaking
JavaScript
13
star
22

typescript-monorepo

Template project for typescript monorepo
JavaScript
12
star
23

lzma

https://docs.rs/lzma-rs binding to Node.js via https://napi.rs
Rust
10
star
24

wechat-api

JavaScript
9
star
25

ada-url

https://github.com/ada-url/ada Rust and Node.js binding
C++
9
star
26

Learning-Rx

在实践中学习 Rx
9
star
27

rxjs-in-react-demo

RxJS 在 React 中的应用示例项目
TypeScript
8
star
28

html-parser

Parse html string to AST.
JavaScript
8
star
29

crypto-wasm

rust-crypto wasm build
JavaScript
8
star
30

dog

Watch dog for Node.js development
Rust
8
star
31

vuex-rx

RxJS Plugins for vuex
TypeScript
7
star
32

wx-fetch

微信小应用的 fetch polyfill
JavaScript
7
star
33

datafusion-node

Apache DataFusion Node.js binding
Rust
6
star
34

WechatBot

TypeScript
5
star
35

summer-page

JavaScript
5
star
36

node-ed25519

JavaScript
5
star
37

pnpm-duplicate-packages

Reproduction for duplicate packages bundled in pnpm project
JavaScript
5
star
38

node-threadsafe-function-loom

Play the Loom
Rust
4
star
39

Build-Promise

Build your own Promise
TypeScript
4
star
40

puppeteer-screencast-to-video

Puppeteer screencast frames to video
Rust
4
star
41

resume

Resume
TypeScript
4
star
42

Rust-OSS

Aliyun OSS utils
3
star
43

xcx-fucker

3
star
44

dart-rs

Dart rust binding library
Rust
3
star
45

blog

blog
TypeScript
3
star
46

css-minify-comparation

JavaScript
3
star
47

napi-rs-cli-testing

Testing package for @napi-rs/cli
JavaScript
2
star
48

zig-linker-issue

JavaScript
2
star
49

wechat-dingding-cryptor

Wechat/ Dingding cryptor
JavaScript
1
star
50

TypeScript-Webworker-Plugin

Generate webworker codes
1
star
51

next.js-remix-benchmark

TypeScript
1
star
52

ts-import-plugin-example

ts-import-plugin example project with create-react-app
JavaScript
1
star
53

node-crypto

rust-crypto bindings to nodejs
Rust
1
star
54

Cassanova

Teambition & Gitlab & Jenkins Webhook Bridge
TypeScript
1
star
55

Appelsin-Scroll

A cross browers custom scroll bar
JavaScript
1
star
56

frontend-mesh

Connect, control, and observe frontend services. Inspired by Istio.
1
star
57

Learning-FSharp

1
star
58

yarn-bug

1
star
59

node-ref-object-leak

JavaScript
1
star
60

angular_with_typescript

JavaScript
1
star
61

nestjs-vercel

1
star
62

traceurs

Fetch your data, eagerly.
TypeScript
1
star
63

vue-worker-rendering

Rendering HTML in service worker
JavaScript
1
star
64

nodejs-worker-thread-constructor-attribute-issue

C++
1
star
65

typescript-example-projects

JavaScript
1
star
66

nft-pnpm

@vercel/nft with pnpm
JavaScript
1
star
67

intelligent-link

Generate universal link or urlschema or App download url
1
star